$(document).ready(function(){
	/* PLUGIN DE WATERMARK */
	watermark.init();
	/* PLUGIN DE PNG FIX */
	if($.browser.msie&&($.browser.version=="6.0")){$(document).pngFix();}
	/* HABILITA OS SELECTS CUSTOM */
	$('#sl1,#sl2,#sl3,#sl5').sSelect();
	$('.navigation .sel select,.navigation .sel1 select').sSelect();
	/* HABILITA OS SELECTS CUSTOM */
	/* CORNERS */
	$('.content').corner("18px");
	/* CORNERS */
	/* AJUSTA O HOVER DO MENU */
	$(".menu li").hover(
		function(){
			if($(this).hasClass('li1')){$(this).addClass('on-hover');}
			else{$(this).addClass('on-hover1');}
		},
		function(){
			if($(this).hasClass('li1')){$(this).removeClass('on-hover');}
			else{$(this).removeClass('on-hover1');}
		}
	);
	/* AJUSTA O HOVER DO MENU */
	/* ABAS */
	$("div.contaba").hide();
	$("div.contaba:first").show();
	$("#abas a:first").addClass("selected");
	$("#abas a").click(function(){
		$("div.contaba").hide();
		$("#abas a").removeClass("selected");
		$(this).addClass("selected");
		$($(this).attr("href")).show();
		return false;
	});
	/* ABAS */
	/* CAROUSEL */
	if($('.content-where-buy #result-data').size()){jQuery('.content-where-buy #result-data').jcarousel({vertical:true,scroll:5});}
	if($('.products #other-products').size()){jQuery('.products #other-products').jcarousel();}
	/* CAROUSEL */
	//seta idioma
	var swf=$('body').attr('id');
	if(swf=='home'||swf=='home_es'||swf=='home_en'){altura='367';}
	else{altura='200';}
	//randomiza o banner
	//var rand=Math.floor(Math.random()*2);
	//var rand=aleatorio(1,3);
	var rand=4;
	/* AJUSTES DOS FLASH */
	if($('#banner-top').size()){
		$('#banner-top').flash({
		  /*src:base_url+'assets/site/swf/banner/'+rand+'.swf',		BANNERS RANDÔMICOS*/
			src:base_url+'assets/site/swf/banner/fpower.swf',
			width:"100%",
			height:'300',
			wmode:'transparent',
			flashvars:{link:base_url}
		},{update:false});
	}
	if(!jQuery.browser.flash){$('#banner-top').html('<a href="http://www.famastilfpower.com.br" target="_blank"><img src="'+base_url+'assets/site/img/pics/fpower_top.jpg" /></a>');}
	else{
		$("#banner-top").hover(
			function(){$(this).css('height','300px')},
			function(){$(this).css('height','68px')}
		);
	}
	if($('#conceptual_'+swf).size()){
		$('#conceptual_'+swf).flash({
			src:base_url+'assets/site/swf/'+swf+'.swf',
			width:"100%",
			height:altura,
			wmode:'transparent',
			flashvars:{link:base_url}
		},{update:false});
		var pseudo_flash=swf;
	}
	if($('#mapac').size()){
		$('#mapac').flash({
			src:base_url+'assets/site/swf/mapa.swf',
			width:'308',
			height:'295',
			wmode:'transparent',
			flashvars:{link:base_url}
		},{update:false});
	}
	if(!jQuery.browser.flash){$('#conceptual_'+pseudo_flash).html('<img src="'+base_url+'assets/site/swf/pics/'+pseudo_flash+'.png" />');}
	/* AJUSTES DOS FLASH */
	/* SCRIPTS NON OBSTRUCTIVE  */
	$('.btn-request-magazine').click(function(){
		$('.box-request-magazine').slideDown();
		$(this).remove();
	});
	$('.btn-search').click(function(){
		var query=$('#q').val();
		var url="";
		if(query!='O que procura?'&&query!='')url='|q='+query;
		if(url!=''||$('#sl2').val()!='')window.location=$('#sl2').val()+url;
	});
	$('.languages a').each(function(){
		$(this).click(function(){
			var lang=$(this).attr('rel');
			$.ajax({
				type:"POST",
				url:base_url+"index.php?on=home&in=setLang",
				data:'lang='+lang,
				success:function(msg){location.reload();}
			});
		});
	});
	/* SCRIPTS NON OBSTRUCTIVE  */
	/* ALIGNS */
	$('.img-detail2 img').each(function(i){
		var parent_height=320;
		var image_height=$(this).height();
		var top_margin =(parent_height - image_height)/2;
		$(this).css( 'margin-top' ,top_margin);
	});
	/* ALIGNS */
	/* SCROLL ANIMATE */
	$('.scrollPage').click(function(){
		var elementClicked=$(this).attr("href");
		var destination=$(elementClicked).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({scrollTop:destination-20},500);
		return false;
	});
	/* SCROLL ANIMATE */
	/*DROP DOWN */
	$('#espaco_intranet').mouseenter(function(){$('#drop_intranet').toggle();});
	$('#drop_intranet').mouseleave(function(){$(this).hide();});
	/*DROP DOWN */
	
});
function gotoRegion(){
	var id=$('#representatives_group').val();
	if(id!='')gotoAnchor('group_'+id);
}
function gotoCity(state){
	$.ajax({
		type:"POST",
		url:base_url+"index.php?on=home&in=getCity",
		data:'state='+state,
		success:function(msg){
			var elemento  = '<select id="representatives_city" name="representatives_city" onchange="getRepre(this.value);">';
				elemento += '<option value="0">Selecione</option>';
				elemento += msg;
				elemento += '</select>';
		
			$('#teste').html(elemento);
			$('.selCity select').sSelect();
			//$('#representatives_city').html(msg);
			//$('#representatives_city').reset();
		}
	});
}

function getRepre(city){
	$.ajax({
		type:"POST",
		url:base_url+"index.php?on=home&in=getRepre",
		data:'city='+city,
		success:function(msg){
			$('.content-sales').html(msg);
		}
	});
}

function getLojista(host,state){
	$('#representatives_state').val(state);
	$('.selstate .selectedTxt').text(state);
	gotoCity(state);
}
function printProduct(id,pg){
    var oPrint,oJan;
    oPrint=window.document.getElementById(id).innerHTML;
    oJan=window.open(pg);
    oJan.document.write("<style>table{font-size:11px;width:620px;}table tr.header{padding:3px;background:\#D9D9D9;color:\#333;}body{font:normal 12px Arial}h2{font-size:22px;}</style>"+oPrint+'<br /><br /><img src="'+base_url+'assets/site/img/pics/legenda.gif" />');
    oJan.history.go();
    oJan.window.print();
    oJan.close();
}
function disabledFormButton(ct){$(ct).attr('disabled','disabled').css('cursor','default').css('filter','alpha(opacity=40)').css('-moz-opacity','0.4').css('opacity','0.4');}
function enabledFormButton(ct){$(ct).attr('disabled','').css('cursor','pointer').css('filter','alpha(opacity=100)').css('-moz-opacity','1').css('opacity','1');}
function hideError(){
	$("#retorno_erro").animate({
		left:'+=50',
		height:'toggle'
	},500,function(){
		$("#retorno_erro").html('');
		$("#retorno_erro").css('display','block');
	});
	window.clearTimeout(timeoutID);
}
function aleatorio(inferior,superior){ 
   	numPossibilidades=superior-inferior 
   	aleat=Math.random()*numPossibilidades 
   	aleat=Math.floor(aleat) 
   	return parseInt(inferior)+aleat 
}
function topo(){window.location=document.URL+'#';}
function gotoAnchor(value){
	var elementClicked='#'+value;
	var destination=$(elementClicked).offset().top;
	$("html:not(:animated),body:not(:animated)").animate({scrollTop:destination-20},500);
}
var valEmail=/^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
function str_replace(haystack,needle,replacement){var temp=haystack.split(needle);return temp.join(replacement);}
