function lightsOut(waiting){
	if (waiting==null) waiting=true;
	if ($('#transp').size()==0){     
		$('body').append('<div id="transp"></div>');
	}    
	if ($(document).height()>$(window).height()){
		$('#transp').css('height',$(document).height()+"px");
	}else{
		$('#transp').css('height',$(window).height()+"px");
	}
	$('#transp').css('width',$(document).width()+"px");

	
	if (waiting){
		$('body').append('<div id="waiting"><img src="/design/royal_canin/img/dots_w_bg.gif" width="36" height="36" /> a processar</div>');
		$('#waiting').ready(function(){
			
			var deltaX=($(window).width()-$('#waiting').width())/2;
			var deltaY=($(window).height()-$('#waiting').height())/2;
			$('#waiting').css('marginLeft',($(document).scrollLeft()+deltaX)+"px");
			$('#waiting').css('marginTop' ,($(document).scrollTop()+deltaY)+"px");
			
		});
	}
	
 }
 
 function lightsIn(){
	$('#transp').remove();
	$('#waiting').remove();
 }


function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function isValidBarCode(code) {
	var pattern = new RegExp(/^\d{13}$/);
	return pattern.test(code);
}


function shareFB(path){
	var theUrl=escape(path);	
	window.open("http://www.facebook.com/sharer.php?u="+theUrl,"facebookshare",'scrollbars=auto,menubar=no,width=500,height=500,resizable=yes,toolbar=no,location=no,status=no');
}

function openPFDog(){
	var colorboxOptions={href:'/swf/pfcao',iframe:true,open:true,width:690,height:820};
	$.fn.colorbox(colorboxOptions);
	
}

function openPFCat(){
	var colorboxOptions={href:'/swf/pfgato',iframe:true,open:true,width:690,height:820};
	$.fn.colorbox(colorboxOptions);	
}

function openPF(){
	var colorboxOptions={href:'/swf/product_finder.html',iframe:true,open:true,width:690,height:820};
	$.fn.colorbox(colorboxOptions);	
}

function openAC3D(){
	var colorboxOptions={href:'/swf/ageingcat3d/English/ageing_cat_3d.html',iframe:true,open:true,width:860,height:550};
	$.fn.colorbox(colorboxOptions);	
}



$(document).ready(function(){
	$('div.racasListItem').bind('mouseenter',function(e){
		$(this).find('img').each(function(i){
			var pattern = new RegExp(/leg_cinza_[a-zA-Z_]+\.gif$/);
			if (pattern.test(this.src)){
				this.src=this.src.replace(/cinza/i,"verm");
			}			
		});
		$(this).find(".legendaBtArrow").addClass('legendaBtArrowHover');
		$(this).find(".legendaBtArrowBottom").addClass('legendaBtArrowBottomHover');
		$(this).find(".legendaBtTopCorner").addClass('legendaBtTopCornerHover');
		$(this).find(".legendaBtBottomCorner").addClass('legendaBtBottomCornerHover');
		$(this).find(".legendaBtText").addClass('legendaBtTextHover');
	});
	
	$('div.racasListItem').bind('mouseleave',function(e){
		$(this).find('img').each(function(i){
			var pattern = new RegExp(/leg_verm_[a-zA-Z_]+\.gif$/);
			if (pattern.test(this.src)){
				this.src=this.src.replace(/verm/i,"cinza");
			}			
		});
		$(this).find(".legendaBtArrow").removeClass('legendaBtArrowHover');
		$(this).find(".legendaBtArrowBottom").removeClass('legendaBtArrowBottomHover');
		$(this).find(".legendaBtTopCorner").removeClass('legendaBtTopCornerHover');
		$(this).find(".legendaBtBottomCorner").removeClass('legendaBtBottomCornerHover');
		$(this).find(".legendaBtText").removeClass('legendaBtTextHover');
	});
/*	
	$('div.legendaBt').bind('mouseenter',function(e){
		$(this).children(".legendaBtTopCorner").html('<img src="img/leg_verm_top_right.gif" class="right" />');
		$(this).children(".legendaBtBottomCorner").html('<img src="img/leg_verm_bottom_right.gif" class="right" />');
		$(this).children(".legendaBtArrow").addClass('legendaBtArrowHover');
		$(this).children(".legendaBtArrowBottom").addClass('legendaBtArrowBottomHover');
		$(this).children(".legendaBtTopCorner").addClass('legendaBtTopCornerHover');
		$(this).children(".legendaBtBottomCorner").addClass('legendaBtBottomCornerHover');
		$(this).children(".legendaBtText").addClass('legendaBtTextHover');
		if($(this).parent().hasClass('productListItem')){
			$(this).parent().parent().find('div.productListFooter').show();
		}
	});

	$('div.legendaBt').bind('mouseleave',function(e){
		$(this).children(".legendaBtArrow").removeClass('legendaBtArrowHover');
		$(this).children(".legendaBtArrowBottom").removeClass('legendaBtArrowBottomHover');
		$(this).children(".legendaBtTopCorner").removeClass('legendaBtTopCornerHover');
		$(this).children(".legendaBtBottomCorner").removeClass('legendaBtBottomCornerHover');
		$(this).children(".legendaBtText").removeClass('legendaBtTextHover');
		
		if($(this).parent().hasClass('productListItem')){
			$(this).children(".legendaBtTopCorner").html('<img src="img/leg_cinza_strong_top_right.gif" class="right" />');
			$(this).children(".legendaBtBottomCorner").html('<img src="img/leg_cinza_strong_bottom_right.gif" class="right" />');	
		}else if($(this).parent().hasClass('racasListName')){
			$(this).children(".legendaBtTopCorner").html('<img src="img/leg_cinza_top_right.gif" class="right" />');
			$(this).children(".legendaBtBottomCorner").html('<img src="img/leg_cinza_bottom_right.gif" class="right" />');
		}
		$('div.productListFooter').hide();
	});
*/	
	$('div.sizeListItem').bind('mouseenter',function(e){
		$(this).parent().parent().find('div.productListFooter').show();
	});
	$('div.sizeListItem').bind('mouseleave',function(e){
		$('div.productListFooter').hide();
	});
	//input Enter
	$('.btEnter').bind('mouseenter',function(e){
		$(this).addClass('btEnterOver');
	});
	$('.btEnter').bind('mouseleave',function(e){
		$(this).removeClass('btEnterOver');
	})
	//CheckBox
	$('#checkLoja, #checkVet, #local1, #local2, #local3').bind('click',function(e){
		$(this).toggleClass('vendaCheckOn');
		if ($(this).hasClass('vendaCheckOn')){
			$(this).children('input').attr('value','1');
		}else{
			$(this).children('input').attr('value','0');
		}
	});
	//Radio Button
	/*
	$('#radioGato').bind('click',function(e){
		$(this).toggleClass('vendaRadioOn');
		$(this).children('input').attr('value','1');
		$('#radioCao').removeClass('vendaRadioOn');
		$('#radioCao').children('input').attr('value','0');
		$('#escolheCao').hide();
		$('#escolheGato').show();
		
	});
	$('#radioCao').bind('click',function(e){
		$(this).toggleClass('vendaRadioOn');
		$(this).children('input').attr('value','1');
		$('#radioGato').removeClass('vendaRadioOn');
		$('#radioGato').children('input').attr('value','0');
		$('#escolheGato').hide();
		$('#escolheCao').show();
	});
	
	$('#radioMacho').bind('click',function(e){
		$(this).toggleClass('vendaRadioOn');
		$(this).children('input').attr('value','1');
		$('#radioFemea').removeClass('vendaRadioOn');
		$('#radioFemea').children('input').attr('value','0');
		
	});
	$('#radioFemea').bind('click',function(e){
		$(this).toggleClass('vendaRadioOn');
		$(this).children('input').attr('value','1');
		$('#radioMacho').removeClass('vendaRadioOn');
		$('#radioMacho').children('input').attr('value','0');
	});
	$('#radioSim').bind('click',function(e){
		$(this).toggleClass('vendaRadioOn');
		$(this).children('input').attr('value','1');
		$('#radioNao').removeClass('vendaRadioOn');
		$('#radioNao').children('input').attr('value','0');
		
	});
	$('#radioNao').bind('click',function(e){
		$(this).toggleClass('vendaRadioOn');
		$(this).children('input').attr('value','1');
		$('#radioSim').removeClass('vendaRadioOn');
		$('#radioSim').children('input').attr('value','0');
		
	});
	*/
	//Botoes de submit
	$('.standartBt').bind('mouseenter',function(e){
		$(this).addClass('standartBtOver');
	});
	$('.standartBt').bind('mouseleave',function(e){
		$(this).removeClass('standartBtOver');
	});
	//Listagens de resultados dos forms
	/*
	$('.formResultItem').bind('mouseenter',function(e){
		$(this).addClass('formResultItemOver');
	});
	$('.formResultItem').bind('mouseleave',function(e){
		$(this).removeClass('formResultItemOver');
	});
	$('.formResultItem').bind('click',function(e){
		var clickDiv = $(this).find('div.formResultInside');
		if((!clickDiv.is(':visible'))) {
			$('div.formResultInside').slideUp();
			clickDiv.slideDown(500);
			return false;
		}
	})
	*/;
});

/*TABELAS*/
$(document).ready(function(){
	$('div.mainText table.productDataTable tr, div.mainTextLarger table.productDataTable tr').bind('mouseenter',function(e){
		$(this).addClass('over');
	});
	$('div.mainText table.productDataTable tr, div.mainTextLarger table.productDataTable tr').bind('mouseleave',function(e){
		$(this).removeClass('over');
	});
});



/*Imagens de Roll Over*/

function olAutoRolloverDoRollover(event){		
	var imgName=$(this).attr('src');
	imgName=imgName.substr(0,imgName.length-7)+"over.gif";
	$(this).attr('src',imgName);
}

function olAutoRolloverRemoveRollover(event){
	var imgName=$(this).attr('src');
	imgName=imgName.substr(0,imgName.length-8)+"off.gif";
	$(this).attr('src',imgName);
}

$(document).ready(function(){
	$('a').each(function(i){
		if ($(this).children('*').size()==1 && $(this).children('img').size()==1){
			var targetImg=$(this).children('img');
			var imgName=targetImg.attr('src').toUpperCase();
			if(imgName.substr(imgName.length-8)=='_OFF.GIF'){				
				targetImg.bind('mouseenter',olAutoRolloverDoRollover);
				targetImg.bind('mouseleave',olAutoRolloverRemoveRollover);
			}			
		}
	});
	
	$('.printBtn').click(function(event){
		window.print();
		return false;
	});
	
	
	
});



