var avisolegal = 0;

$(document).ready(function(){

	$("#votacion-comen").stars({

		inputType:"radio",

		split:2,

		captionEl: $("#votacion-comen-cap")

	});

	$("#numPa li:first").addClass("first");

    $("#menu-3 li:last,.titulo-right ul li:last,#links-footer li:last,#menu-footer ul li:last,#numPa li:last,#icoPa li:last,.capaVolver ul li:last,#lisOrdenar li a:last").addClass("last");

	$("#lista-des-home li h2 a").mouseout(function() {    

		$(".imgDes").remove();

		$("#capaHomeA").show();

    });

	var contador = 1;

	$( ".bloque-resultado" ).each(

		function(){

			if(contador == 2){

				$(this).addClass("last");					

				contador = 1;

			}else{ 

				contador++;

			}

		}

	);

	$(".faq-toogle .faq-contenedor p").hide();

	$(".faq-toogle .faq-contenedor .faq-toogle").hide();

	$(".faq-toogle .faq-contenedor h3").click(function(){

		$(this).parent().parent().find(".faq-contenedor p:visible").slideUp("slow");

		$(this).parent().parent().find(".faq-contenedor .faq-toogle").hide();

		$(this).next("p").slideDown("slow");

		

		if($(this).parent().children(".faq-toogle") != null){

			$(this).parent().find(".faq-toogle").show();

			$(this).parent().find(".faq-toogle .faq-contenedor .faq-toogle").hide();

		}

	});

	imagen_on_1 = new Image()

	imagen_on_1.src = SKIN+"imagenes/icons/help_hover.gif"

	imagen_off_1 = new Image()

	imagen_off_1.src = SKIN+"imagenes/icons/help.gif"

	imagen_on_2 = new Image()

	imagen_on_2.src = SKIN+"imagenes/icons/help_hover2.gif"

	imagen_off_2 = new Image()

	imagen_off_2.src = SKIN+"imagenes/icons/help2.gif"

	loadJsAjax();

	$('#licapa1').click(function(){

		viewCapa(1);

		$('#licapa2-active').hide();

		$('#licapa2').show();

	});

	$('#licapa2').click(function(){

		viewCapa(2);

		$('#licapa2').hide();

		$('#licapa2-active').show();

	});

	$('#licapa3').click(function(){

		viewCapa(3);

		$('#licapa2-active').hide();

		$('#licapa2').show();

	});

	$('#licapa4').click(function(){

		viewCapa(4);

		$('#licapa2-active').hide();

		$('#licapa2').show();

	});

	$('#licapa6').click(function(){

		$('#licapa2-active').hide();

		$('#licapa2').show();

	});

	$(".tarjForm label:first,.labelvisacard:first").addClass("tarjeta");

});

function cambiaIMG (ruta) {

	$("#capaHomeA").hide();

	$("#capaHomeA").after("<img class=\"imgDes\" src=\""+ruta+"\" />");

}

function loadJsAjax(){

	submitCSS();

	var contador = 1;

	$("#list-galeria li").each(

		function(){

			if(contador == 5){

				$(this).addClass("last");					

				contador = 1;

			}else{ 

				contador++;

			}

		}

	);

	$(".btnSubmitCSS").mouseover(function() {    

		$(this).addClass("btnSubmitCSS-active");

	}).mouseout(function() {    

		$(this).removeClass("btnSubmitCSS-active");

	});

	$('#loadAjxIMG').click(function(){

		$('#cargandoIMG').show();

	});

	$('#theme-cerrar,.labelDif').click(function() {$.validationEngine.closePrompt('.formError',true);});

	$("form").validationEngine();

	$("input[type=text],input[type=password]").each(function(){

		for(i=1;i<=3;i++){

			if($(this).hasClass(".input-"+i)){

				var str = $(this).attr("class");

				var strExpl = str.split(" ");

				for(j = 0;j<strExpl.length;j++){

					if(strExpl[j].indexOf("input-") != -1){

						var strPart = strExpl[j].split("-");

						$(this).focus(function() {

							$(this).addClass("inputText"+strPart[1]+"_hover");

						}).blur(function(){

							$(this).removeClass("inputText"+strPart[1]+"_hover");

						});

					}

				}

				

				

			}	

		}

	});

	$("input[type=file]").filestyle({ 

		image:SKIN+"imagenes/icons/examinar.gif",

 		imageheight:20,

	 	imagewidth:83,

	 	width:154

	});

	var count;

	for(count=0;count<=150;count++){

		if(document.getElementById("tooltip-"+count)){

			$("#tooltip-"+count).ezpz_tooltip({

				contentId:'tooltip-content-'+count

			});

		}

	}

	Cufon.replace('#lista-des-home li h2 a,#lista-des-home-faq li h2', {fontFamily:'Helvetica-CondensedBlack',hover: true});

	Cufon.replace('.tituloCufon,.des,.des2,#capaHomeA h3', {fontFamily:'Helvetica-UltraCompressed',hover: true});

	Cufon.replace('#menu-1 li a,.tituloCufon2,#menu-2 li a,.titulo-right h3,.banners-bloques li a,#capaHomeA h4,.formLila h3,.formAmarillo h3,#accesLogin li,.hideAll h2', {fontFamily:'Helvetica67-CondensedMedium',hover: true});

	$(".lanzarPopUp").colorbox({

		'overlayClose':false,

		'title':true,

		'scrolling':false

	});

	$(".lanzarIMG").colorbox({title:false});

	$("#aviso-legal-imgpr").click(function(){

		avisolegal = 1;

		$(".titlePopUp").toggle();

		$(".titleAviso").show();

		resizeate();

	});

	$("#aviso-legal-volver").click(function(){

		avisolegal = 0;

		$(".titleAviso").toggle();

		$(".titlePopUp").toggle();
		
		resizeate();

	});

	$("#link-opinar").click(function(){

		$(this).toggleClass("gris");

		$("#formOpinar").slideToggle();

	});

	$(".linkValor,#hideComments").click(function(){

		$("#list-opiniones").slideToggle();

	});

	$(".linklostpassw").click(function(){

		$("#losPassw").toggle();

		$("#commentForm").toggle();

		$.fn.colorbox.resize();

	});

	/*jQuery.each(jQuery.browser, function(i, val) {*/
		if($.browser.safari){
			$(".select-1").height(24).css("padding-top", "4px");
		}
		if($.browser.chrome){
			$(".select-1").height(23).css("padding-top", "5px");
		}
	  /* if(i=="mozilla" && jQuery.browser.version>="1.9.2.3"){

		   	$(".input-1,.input-2,.input-3,.input-4").css({'padding-top':'0px','height':'28px'});

		   }
*/
	 /* }); */

	/*
	if($.browser.msie && $.browser.version.substr(0,3)<="7.0") {

		$(".input-1").each(function() {

			if($(this).parent("div").attr("class") != "capaInput-1"){

				$(this).wrap("<div class='capaInput-1'></div>");

				$(this).focus(function() {

					$(this).parent("div").addClass("capaInput-1_hover");

				}).blur(function(){

					$(this).parent("div").removeClass("capaInput-1_hover");

				});

				$.fn.colorbox.resize();

			}

		})

		$(".input-2").each(function() {

			if($(this).parent("div").attr("class") != "capaInput-2"){

				$(this).wrap("<div class='capaInput-2'></div>");

				$(this).focus(function() {

					$(this).parent("div").addClass("capaInput-2_hover");

				}).blur(function(){

					$(this).parent("div").removeClass("capaInput-2_hover");

				});

				$.fn.colorbox.resize();

			}

		})

		$(".input-3").each(function() {

			if($(this).parent("div").attr("class") != "capaInput-3"){

				$(this).wrap("<div class='capaInput-3'></div>");

				$(this).focus(function() {

					$(this).parent("div").addClass("capaInput-3_hover");

				}).blur(function(){

					$(this).parent("div").removeClass("capaInput-3_hover");

				});

				$.fn.colorbox.resize();

			}

		})

		$(".input-4").each(function() {

			if($(this).parent("div").attr("class") != "capaInput-4"){

				$(this).wrap("<div class='capaInput-4'></div>");

				$(this).focus(function() {

					$(this).parent("div").addClass("capaInput-4_hover");

				}).blur(function(){

					$(this).parent("div").removeClass("capaInput-4_hover");

				});

				$.fn.colorbox.resize();

			}

		})

	}
*/
	setTimeout ('equalHeight($(".bloque-content"))', 1800);

}

function refreshLocation(){

	window.top.location.href=window.top.location.href;

}

function comerceSaved(){

	if(document.getElementById('comerceSaved')){

		$('#comerceAlert').hide();

		$('#comerceSaved').fadeIn(1000);

		setTimeout('$(\'#comerceSaved\').fadeOut(1000)',5000);

		setTimeout('$(\'#comerceAlert\').fadeIn(1000);',6000);

	}

}

function equalHeight(group) {

    tallest = 0;

    group.each(function() {

        thisHeight = $(this).height();

        if(thisHeight > tallest) {

            tallest = thisHeight;

        }

    });

    group.height(tallest);

}
/*
var userAgent = navigator.userAgent.toLowerCase();
jQuery.browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1],
	chrome: /chrome/.test( userAgent ),
	safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};*/