// JavaScript Document
$(document).ready(function() {
	
	document.originalTitle = document.title;
	setInterval( function(){
	document.title = document.originalTitle;
	},1000)

	$("#cidadesSinalDigital .listasSinalDigital ul li:nth-child(odd)").addClass("itemListaOdd");

	$('.lista_produtos').each(function(x){
		  $(this).css("visibility","visible");
	      $(this).css("margin-left",((1002/2)-($(this).width()/2)));
	});

	// toshibaFAQ - ACCORDION
	$("#toshibaFAQ").accordion({ 
		header: "h3",
		autoHeight: false,
		active: false
	});
	
	
	$('.div_produtos p span a').hover(function(){
		$('img',this).animate({ 
			width: "130px",
			height: "89px",
			top:'0px',
			left:'0px'
		  }, 500 );
	},
	function(){
		$('img',this).animate({ 
			width: "91px",
			height: "62px",
			top:'13px',
			left:'20px'
		  }, 500 );
	})
	
	$('.btn_limpar').click(function(){
		pageTracker._trackEvent('Botão', 'Clique_trabalhe_conosco', '', 'limpar');
	});
	
	$('btn_enviar2').click(function(){
		pageTracker._trackEvent('Botão', 'Clique_trabalhe_conosco', '', 'enviar');
	});
	
	// Lightbox Eventos
	$('.eventos .descricao .fotos ul li a').lightBox();
	
	$('.glossario ul').equalHeights();
	
});

/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: 
		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
  		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------*/

$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height() + 1; }
		});
		//if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

function trocarConteudo(id,total){
	var objLi = $("#item_" + id);
	var objcont = $("#cont_" + id); 
	
	for(var i =1; i <= total; i++){
		$("#item_" + i).removeClass("li_active");
		$("#cont_" + i).css("display", "none");
	}
	
	objLi.addClass("li_active");
	objcont.css("display", "inline");
	if(id != 1){
		$("#menusessao").css("display", "none");
	}
	else{
		$("#menusessao").css("display", "inline");	
	}
}

function mostraSubConteudo(id,total){
	var objLi = $("#link_" + id);
	var objcont = $("#box_" + id); 
	
	for(var i =1; i <= total; i++){
		$("#link_" + i).removeClass("ativo");
		$("#box_" + i).css("display", "none");
	}
	
	objLi.addClass("ativo");
	objcont.css("display", "inline");
}


//LightBox
$(document).ready(function(){

	/* EVENTO DE ABRIR O LIGHTBOX */
	$('.lista_produtos a, .div_box_tipoCeltvSti a, .div_box_tipoDestaque a').click(function(){
		
		var urlItem = $(this).attr("href");		
		var urlTarget = $(this).attr("target");
		
		if((urlTarget == "LightBox") || (urlTarget == "")) {
			startLightBox(urlItem);
		}
		
		else if (urlTarget == "MesmaJanela") {
			window.open(urlItem, '_self'); 			
		}
		
		else {
			window.open(urlItem, '_blank');
		}
		

		return false;
	});

	$('.lightbox').click(function(){
		fecharLightBox();
	});
});
var lastlightboxopenhrl;
var bodyheight = 0;
function startLightBox(urlProduto)
{
	lastlightboxopenhrl = urlProduto;
	$('.lightbox').animate({height:$(document).height()},0);
	$('.alinhamento').fadeOut(1000);
	bodyheight = $(document).height();
	abrirCarregando();

	
	/*$.ajax({
	   type: "POST",
	   url: urlProduto,
	   success: function(msg){
		 
		 $('.alinhamento').html(msg);
		 abrirLightBox();
	   }
	 });
*/
//alert(urlProduto);
	/* CARREGA NA DIV .alinhamento, O CONTEUDO */
	$('.alinhamento').load(urlProduto + " #detalheProduto", abrirLightBox);
	/*  UTILIZADO PARA SUBIR O SCROLL DA PÁGINA PARA O TOPO */
	window.scroll(0,0);
}

function abrirCarregando()
{
	/* APLICA A OPACIDADE NA DIV, PARA VALIDAR NO W3C */
	$('.lightbox').animate({opacity:'0.5'},0);

	/* APLICA A ALTURA NO LIGHTBOX */
	$('.lightbox').fadeIn(1000,function() {
		$("body, .lightbox").height($(document).height());	
		var alturaContainer = $('body').height();
		$('.lightbox').animate({height:alturaContainer},0);
	});
	
	/* MOSTRA A DIV CARREGANDO */
	$('.carregando').css('display', 'block').fadeIn(1000);

	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	b_version = b_version.substring(22,23);

	if(browser.indexOf("Microsoft Internet Explorer") !== -1 && b_version == 6) {
		$("select").css("visibility","hidden");
	}
}
function abrirLightBox()
{
	
	/* ESCONDE A DIV CARREGANDO */
	$('.carregando').fadeOut(1000);

	/* APLICA A OPACIDADE NA DIV, PARA VALIDAR NO W3C */
	$('.lightbox').animate({opacity:'0.5'},0);

	/* APLICA A ALTURA NO LIGHTBOX */
	$('.lightbox').fadeIn(1000,function() {
		$("body, .lightbox").height($(document).height());	
		var alturaContainer = $(document).height();
		$('.lightbox').animate({height:alturaContainer},0);
		addListenerInTollTips();
	});
	
	$('.alinhamento').fadeIn(1000,function(){
		$("body, .lightbox").height($(document).height());	
		var alturaContainer = $(document).height();
		if(bodyheight+40 < alturaContainer){
			$('.lightbox').animate({height:alturaContainer+40},0);
		}else{
			$('.lightbox').animate({height:alturaContainer},0);
		}
		
		
	});

	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	b_version = b_version.substring(22,23);

	if(browser.indexOf("Microsoft Internet Explorer") !== -1 && b_version == 6) {
		$("select").css("visibility","hidden");
	}
	
	
	
}


/* EVENTO DE FECHAR O LIGHTBOX */
function fecharLightBox()
{
	$('#autentico').hide();
	$('.alinhamento').fadeOut('slow');										
	$('.lightbox').fadeOut('slow');

	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	if(browser.indexOf("Microsoft Internet Explorer") !== -1 && b_version == 6) {
		$("select").css("visibility","visible");
	}
	$("body").height("");
	return false;
}



function imprimirLightBox(){
	winPrint = window.open(lastlightboxopenhrl, "Print", "width=20,height=20,scrollbars=no");
	if (winPrint.focus) {window.focus()}
	if(winPrint.attachEvent) {
		setTimeout("winPrint.print()", 3000);
		setTimeout("winPrint.close()",6000);
		/*
		winPrint.attachEvent('onload',function(){
			winPrint.print();
			if (winPrint.focus) {winPrint.opener.focus()}
			winPrint.close();
		});
		*/
	}
	else {
		winPrint.onload = function(){
			winPrint.print();
			if (winPrint.focus) {winPrint.opener.focus()}
			winPrint.close();
		}
	}
}

document.tooltipAutentico = false;
function addListenerInTollTips(){
	$('.lista_modelos dl dt').prev().prev().css('border','none');
	$('.lista_modelos dl dd:last').css('border','none');

	$('.recomendados ul li:last').css('border','none');


	$('#autentico').prependTo($('body'),'top');
	$('#image_display').prependTo($('body'),'top');

	$('.especificacoes ul li:contains("Windows")').each(function(){
		var b = this.innerHTML.replace(/ Aut(.*)ntico /gi,' <a href="#autentico">Aut&ecirc;ntico</a> ');
		b = b.replace(/ Aut(.*)ntico /gi,' <a href="#autentico">Aut&ecirc;ntico</a> ');
		b = b.replace(/ Aut(.*)ntico/gi,' <a href="#autentico">Aut&ecirc;ntico</a>');
		b = b.replace(/ Aut(.*)ntico/gi,' <a href="#autentico">Aut&ecirc;ntico</a>');
		b = b.replace(/Aut(.*)ntico /gi,'<a href="#autentico">Aut&ecirc;ntico</a> ');
		b = b.replace(/Aut(.*)ntico /gi,'<a href="#autentico">Aut&ecirc;ntico</a> ');
		b = b.replace(/<span>Aut(.*)ntico/gi,'<span><a href="#autentico">Aut&ecirc;ntico</a>');
		b = b.replace(/<span>Aut(.*)ntico/gi,'<span><a href="#autentico">Aut&ecirc;ntico</a>');
		b = b.replace(/<span> Aut(.*)ntico/gi,' <span><a href="#autentico">Aut&ecirc;ntico</a>');
		b = b.replace(/<span> Aut(.*)ntico/gi,' <span><a href="#autentico">Aut&ecirc;ntico</a>');
	    this.innerHTML = b;
	});

	setTimeout(function(){
		$('a[href$=autentico]').click(function(e){
	
			ttop  = ( (e.clientY + $(window).scrollTop()) - $('#autentico').height() ) + 15;
				lleft = (e.clientX+25);
			
			if((lleft+$('#autentico').width()) >= $(document.body).width()){
				lleft = ($(document.body).width() - $('#autentico').width()) - 10;
			}
			
			$('#autentico').css('top',ttop+'px');
			$('#autentico').css('left',lleft+'px');
			
			
			$('#autentico').css('display','block');
			$('.close','#autentico').click(function(){
				$('#autentico').css('display','none');
			});
			return false;
		}).hover(
			function(e){
				ttop  = ( (e.clientY + $(window).scrollTop()) - $('#autentico').height() ) + 15;
				lleft = (e.clientX+25);
				
				if((lleft+$('#autentico').width()) >= $(document.body).width()){
					lleft = ($(document.body).width() - $('#autentico').width()) - 10;
				}
				
				$('#autentico').css('top',ttop+'px');
				$('#autentico').css('left',lleft+'px');
				
				
				$('#autentico').css('display','block');
				
				$('#autentico').click(
					function(){
						$('#autentico').css('display','none');
					}
				).hover(
					function(){
						//clearTimeout(document.tooltipAutentico);
					},
					function(){
						$('#autentico').css('display','none');
					}
				);
				return false;
			},
			function(){
				//document.tooltipAutentico = setTimeout(function(){
				//	$('#autentico').css('display','none');
				//},6000);
			}
		);
	},200);

	var tooltip_image_time = false;
	$('.recomendados ul li a').click(function(){return false;});
	$('.recomendados ul li a').hover(
		function(e){
			clearTimeout(tooltip_image_time);
			$(this).addClass('hover');
			
			$('img','#image_display').attr('src',$(this).attr('rel'));
			
			pos = $(this).offset();
			ttop  = ( pos.top - $('#image_display').height() );
			lleft = (pos.left-34);
			
			if((lleft+$('#image_display').width()) >= $(document.body).width()){
				lleft = ($(document.body).width() - $('#image_display').width()) - 10;
			}
			
			$('#image_display').css('top',ttop+'px');
			$('#image_display').css('left',lleft+'px');
			
			
			$('#image_display').css('display','block');
		},
		function(){
			$(this).removeClass('hover');
			tooltip_image_time = setTimeout(function(){
				$('#image_display').css('display','none');
			},500);
		}
	);
}