// JavaScript Document

(function($){$.dimensions={version:'1.2'};$.each(['Height','Width'],function(i,name){$.fn['inner'+name]=function(){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';return this.is(':visible')?this[0]['client'+name]:num(this,name.toLowerCase())+num(this,'padding'+torl)+num(this,'padding'+borr);};$.fn['outer'+name]=function(options){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';options=$.extend({margin:false},options||{});var val=this.is(':visible')?this[0]['offset'+name]:num(this,name.toLowerCase())+num(this,'border'+torl+'Width')+num(this,'border'+borr+'Width')+num(this,'padding'+torl)+num(this,'padding'+borr);return val+(options.margin?(num(this,'margin'+torl)+num(this,'margin'+borr)):0);};});$.each(['Left','Top'],function(i,name){$.fn['scroll'+name]=function(val){if(!this[0])return;return val!=undefined?this.each(function(){this==window||this==document?window.scrollTo(name=='Left'?val:$(window)['scrollLeft'](),name=='Top'?val:$(window)['scrollTop']()):this['scroll'+name]=val;}):this[0]==window||this[0]==document?self[(name=='Left'?'pageXOffset':'pageYOffset')]||$.boxModel&&document.documentElement['scroll'+name]||document.body['scroll'+name]:this[0]['scroll'+name];};});$.fn.extend({position:function(){var left=0,top=0,elem=this[0],offset,parentOffset,offsetParent,results;if(elem){offsetParent=this.offsetParent();offset=this.offset();parentOffset=offsetParent.offset();offset.top-=num(elem,'marginTop');offset.left-=num(elem,'marginLeft');parentOffset.top+=num(offsetParent,'borderTopWidth');parentOffset.left+=num(offsetParent,'borderLeftWidth');results={top:offset.top-parentOffset.top,left:offset.left-parentOffset.left};}return results;},offsetParent:function(){var offsetParent=this[0].offsetParent;while(offsetParent&&(!/^body|html$/i.test(offsetParent.tagName)&&$.css(offsetParent,'position')=='static'))offsetParent=offsetParent.offsetParent;return $(offsetParent);}});function num(el,prop){return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;};})(jQuery);

$(function() {
	$('#lista_noticias a').each(function() {
		$(this).bind('mouseover',function() { 
			$(this).parents('li').find('img,.titulo_noticia,.mais_info').addClass('hover');
		}).bind('mouseout',function() { 
			$(this).parents('li').find('img,.titulo_noticia,.mais_info').removeClass('hover');
		});
	});
	
	$('.noticias_listagem_interna a').each(function() {
		$(this).bind('mouseover',function() { 
			$(this).parents('li').addClass('hover');
		}).bind('mouseout',function() { 
			$(this).parents('li').removeClass('hover');
		});
	});
});


function Banners() {
	
	this.BannerAtual = false;
	this.Paused = false;
	this.Fading = false;
	this.Go = 'next';
	this.i = 0;
	this.Total = 0;
	this.Location = 'http://localhost/UNIPAC/public_html/imagens/';
	this.Interval = 10000; 
	
	
	this.Init = function(Banners,Links) {
		this.Banners = Banners;
		this.Links = Links;
		this.Total = Banners.length - 1;
		
		this.next = (this.i+1)>=0 ? this.i + 1 : this.Total;
		this.prev = (this.i-1)>=0 ? this.i - 1 : this.Total;
		this.Locked = false;
		
		
		if(this.Total != 0) myBanners.AutoChange('prev');
		else { this.Change('prev'); this.Locked = true; this.Pause(); }
	}
	
	this.AutoChange = function() {
		
		if(!this.Paused)
			this.Change('next');
	}
	
	this.Change = function(Go) {
		if(!this.Locked) {
			clearTimeout(this.wInterval);
			if(!this.Fading) {
				this.Paused = false;
				this.Animate(Go);
			}
		}	
	}
	
	this.Animate = function(Go) {
		this.Fading = true;
		
		eval('this.i = this.'+Go+';');
		
		this.next = (this.i+1)<=this.Total ? this.i + 1 : 0;
		this.prev = (this.i-1)>=0 ? this.i - 1 : this.Total;
		
		$('#banner_load').show();
		var img = new Image();
		
		var Src = this.Banners[this.i]; 
		
		//alert(Src);
		
		$(img).load(function () {
			$(this).hide();
			$('#img_banner').remove();
			$('#link_banners_rotativos').prepend(this);
			
			var Link = myBanners.Links[myBanners.i];
			
			if(Link != undefined) {
				$('#link_banners_rotativos').attr({href:Link}).removeClass('disabled').addClass('enabled');
			}
			else {
				$('#link_banners_rotativos').attr({'href':'#'}).removeClass('enabled').addClass('disabled');
			}
			$(this).fadeIn();
			$('#banner_load').fadeOut();
		})		
		.error(function () {
			
		})
		.attr({'src': myBanners.Location+Src,id:'img_banner'});
		
		this.BannerAtual = this.i;
		this.Fading = false;
		this.wInterval = window.setTimeout("myBanners.AutoChange('next')",this.Interval);
	
	}
	
	this.Pause = function() {
		this.Paused = true;
	}
}




// 		MENU
function Menus() {
	
	this.innerWidth = undefined;
	this.Submenu = undefined;
	this.Margin = 290;
	
	this.Init = function Init() {
		$('#menu_topo li:has(.submenus)').each(function() {
			Submenu = $(this).children('.submenus');
			innerWidth = Submenu.innerWidth();
			TotalWidth = 0;
			$(Submenu).children('a').each(function() {
				TotalWidth = TotalWidth + $(this).innerWidth() + 1;
			});
			innerWidth = TotalWidth;
			if(innerWidth != undefined) {
				Submenu.css({width:innerWidth+'px',left:'auto'});
				if((myMenu.Margin + innerWidth) > 901) {
					Submenu.css({marginLeft:'-'+((myMenu.Margin + innerWidth) - 901)+'px'});
				}				
				myMenu.Margin = myMenu.Margin + $(this).innerWidth();
			}
		});
	}
}

var myMenu = new Menus();
//myMenu.Init();
