/* Dart para publicidade uol */
var DEt=new Date(); DEt=DEt.getTime(); DErand=Math.floor(DEt*1000*Math.random());
var scw=0,sch=0; if(screen.height){scw=screen.width;sch=screen.height;}

// DEshow personalized. This function support iframe and script
function DEshow ( ad , pos ) {
	
	try {
		
		if ( typeof isAlbum == "undefined" ) {
			isAlbum = false ;
		}
		
	} catch ( error ) {
		
		isAlbum = false ;
		
	}

	var DEconn = document.body ;
	DEconn.style.behavior = 'url(#default#clientCaps)' ;
	DEconn = ( DEconn.connectionType == 'lan' ) ? 1 : 0 ;

	if ( isAlbum === false || ad === "1x1" ) {
		
		document.write ( '<scr' + 'ipt language="JavaScript1.1" src="http://bn.uol.com.br/js.ng/site=par&chan=' + DEchan + '&subchan=' + DEsubc + '&affiliate=' + DEaff + '&size=' + ad + '&page=' + pos + '&conntype=' + DEconn + '&expble=' + Expble + '&reso=' + scw + 'x' + sch + '&cmpng=' + DEcmpng + '&group=' + DEGroup + '&tile=' + DErand + '?"></scr' + 'ipt>' ) ;
	
	} else {

		var parseAd = ad.split ( "x" ) ;
		var iframe_w = parseInt ( parseAd[0] ) ;
		var iframe_h = parseInt ( parseAd[1] ) ;

		document.write ( '<ifr' + 'ame class="ads_iframe" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" allowtransparency="true" width="' + iframe_w + '" height="' + iframe_h + '" src="/furniture/html/publicidade-iframe.html?DEaff=' + DEaff + '&DEchan=' + DEchan + '&DEsubc=' + DEsubc + '&DEcmpng=' + DEcmpng + '&DEGroup=' + DEGroup + '&ads=' + ad + '&pos=' + pos + '"></ifr' + 'ame>' ) ;
	}
}
/* /Dart para publicidade uol */

/* Nova Janela */

function novaJanela (url, title, extras){
	window.open(url, title, extras);
}


(function($) {
 
	$.fn.MediaBox = function ( settings ) {

		// Array com as configurações do MediaBox
		$.fn.MediaBox.Options = {
			SwitchIn: 5000,
			effectVelocity: "fast",
			imageSizeSmall: [78,63],
			imageSizeLarge: [551,303]
		};
		
		
		// Herda as configurações extras
		$.extend ( $.fn.MediaBox.Options, settings, {nextLi: null, stopSwitch: false} );
		
		// Pre-load de imagens
		$.fn.MediaBox.PreLoadImages ();
				
		this.each(function() {
			
			// Atalho para as opcoes do Plugin
			var Options = $.fn.MediaBox.Options;

			// Liga o Auto-switch
			window.setTimeout($.fn.MediaBox.Switch, Options.SwitchIn);
			
			// Se o usuário estiver com o mouse em cima da área de destaque
			// Desabilita o Auto-Switch

			$('#mediaboxShow').mouseenter(function(){
				Options.stopSwitch = true;
			}).mouseleave(function(){
				Options.stopSwitch = false;
			});
			
			// Varre todos os lis do mediabox para definir os eventos da interface
			
			$('#mediaboxMenu ul li').each(function() {
				
				var current_li = $(this);
						
				// Aplica os eventos de mouseover nos links do mediabox
				current_li.find('a').mouseover(function(){
					
					// Desabilita o Auto-Switch
					Options.stopSwitch = true;

					$(this).MediaBox.ChangeImage ( current_li );

					// Seta o próximo item do Switch
					Options.nextLi = $('#mediaboxMenu ul li.active').next();
					
				}).mouseout(function(){
					// Habilita o Auto-Switch 
					Options.stopSwitch = false;

					$(this).MediaBox.ChangeImage ( current_li );
				});
	
			});
		}); 
	};
	
	/**
	 * Método responsável por trocar de tempo em tempo o destaque
	 */
	$.fn.MediaBox.Switch = function ( ) {
		// Atalho para as opcoes do Plugin
		var Options = $.fn.MediaBox.Options;
		
		if(Options.stopSwitch == false)	{
			
			// Esconde a imagem de destaque
			$('#Mediabox #mediaboxShow .mediaboxDestaque img').fadeOut('slow');
			
			// Esconde a div com o titulo do destaque
			$('#Mediabox .mediaboxSubtitle, ').animate({'top': "+=100px"}, "slow");
			$('#Mediabox .mediaboxOpacity').animate({'top': "+=100px"}, "slow", function(){
				// Carrega o próximo destaque
				$.fn.MediaBox.ChangeImage();
			});
			
			// Recolhe a div com o titulo do destaque
			$('#Mediabox .mediaboxSubtitle, #Mediabox .mediaboxOpacity').animate({'top': "-=100px"}, "slow");
			
			// Aparece a imagem de destaque
			$('#Mediabox #mediaboxShow .mediaboxDestaque img').fadeIn('slow');
			
		}
		
		window.setTimeout($.fn.MediaBox.Switch, Options.SwitchIn);
	};
	
	/**
	 * Método responsável por trocar a imagem da area de detaque
	 */
	$.fn.MediaBox.ChangeImage = function ( current_li ) {
				
		// Atalho para as opcoes do Plugin
		var Options = $.fn.MediaBox.Options;
					
	 	current_li = (!current_li) ? $('#mediaboxMenu ul li.active').next() : current_li;
	
		// Se a fila chegar ao fim, reinicia desde o início
		if( current_li.length == 0 ){
			 current_li = $('#mediaboxMenu ul li:first');			
		}
		
		$('#mediaboxMenu ul li').removeClass ( 'active' );
		current_li.addClass ( 'active' );	
		
		// Recebe as propriedades dos elementos do li que passei o mouse em cima
		var link 		= $( current_li ).find ( '.categorie a' ).attr ( 'href');
		var link_target	= $( current_li ).find ( '.categorie a' ).attr ( 'target');
		var categoria 	= $( current_li ).find ( '.categorie a' ).text ( );
		var titulo 		= $( current_li ).find ( '.title a' ).text ( );
		var imagem 		= $( current_li ).find ( '.image a img' ).attr ( 'src' );
		var imagem_title = $( current_li ).find ( '.image a img' ).attr ( 'title' );
		
		// Troca a imagem atual pela nova.
		var smallSize = Options.imageSizeSmall[0] + 'x' + Options.imageSizeSmall[1];
		var largeSize = Options.imageSizeLarge[0] + 'x' + Options.imageSizeLarge[1];
		var src_imagem_grande =	$.fn.MediaBox.getLargeImage ( imagem );

		$('#mediaboxShow .mediaboxDestaque img').attr ( 'src', src_imagem_grande )
												.attr ( 'alt', imagem_title )
												.attr ( 'title', imagem_title );
								
		// Muda o endereço de todos os links dentro do MediaboxShow
		$('#mediaboxShow a').attr ( 'href', link );	
			
		if(link_target == '_blank') {
			$('#mediaboxShow a').attr ( 'target', '_blank' );
		} else {
			$('#mediaboxShow a').attr ( 'target', '' );
		}		
			
		// Troca a categoria pelo item que passei o mouse em cima
		$('#mediaboxShow .mediaboxSubtitle .categorie a').text ( categoria );
			
		// Troca o titulo pelo item que passei o mouse em cima
		$('#mediaboxShow .mediaboxSubtitle .title a').text ( titulo );			
			
	};
	
	/**
	 * Faz o pre-load das imagens grandes assim que o MediaBox é invocado 
	 */
	$.fn.MediaBox.PreLoadImages = function ( ) {
		
		$('#mediaboxMenu span.image img').each(function(){
			
			var img_src = $(this).attr('src');
			var img_src_large = $.fn.MediaBox.getLargeImage ( img_src );
			
			// Carrega a imagem
			var new_image = new Image ();
				new_image.src = img_src_large;
				
		});
		
	}
	
	/**
	 * Retorna a url da imagem grande passando a url da imagem pequena 
	 */
	$.fn.MediaBox.getLargeImage = function ( img_src ) {
		
		// Atalho para as opcoes do Plugin
		var Options = $.fn.MediaBox.Options;
		
		// Tamanho pequeno
		var smallSize = Options.imageSizeSmall[0] + 'x' + Options.imageSizeSmall[1];
		
		// Tamanho grande
		var largeSize = Options.imageSizeLarge[0] + 'x' + Options.imageSizeLarge[1];
		
		return img_src.replace(smallSize, largeSize);
		
	}
	
	
})(jQuery);
