//cambia idioma
    function cambiaIdioma(lang){
        if(lang=='EN'){
            $.get("sitio/secciones/idioma.php", {lang: lang}, function(data){
                var pos= window.location.toString();
                window.location.replace(pos);
            })
        }else if(lang=='PO'){
            $.get("sitio/secciones/idioma.php", {lang: lang}, function(data){
                var pos= window.location.toString();
                window.location.replace(pos);
            })
        }else if(lang=='CA'){
            $.get("sitio/secciones/idioma.php", {lang: lang}, function(data){
                var pos= window.location.toString();
                window.location.replace(pos);
            })
        }else{
            $.get("sitio/secciones/idioma.php", {lang: lang}, function(data){
                var pos= window.location.toString();
                window.location.replace(pos);
            })
        }
    }

$(document).ready(function(){
    if($('#ampliar_txt').height()<187){
        $('div.descargas a#vermas').remove();
    }
//direccion base
		var base= $('base').attr('href');


//HOVER PARA NAVEGACION
	$('#nav li a.bgpos')
	.css( {backgroundPosition: "0px -60px"} )
	.mouseover(function(){
		$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:500})
	})
	.mouseout(function(){
		$(this).stop().animate({backgroundPosition:"(0px -60px)"}, {duration:500, complete:function(){
			$(this).css({backgroundPosition: "0px -60px"})
		}})
	})


//Current
    $('#nav li a').each( function(idx, el) {
        if (el.href === window.location.toString()) {
            $(el).css({"color": "#fff", "background-color": "#8BB2DD"});
            $(el).parent().parent().prev("a.bgpos").css({backgroundPosition: "0px 0px","backgroundImage":"url(sitio/img/current.png)",color: "#fff"});
        }
    });

     $('#nav li a.bgpos').each( function(idx, el) {
        if (el.href === window.location.toString() || el.href+'/' === window.location.toString() ) {
            $(el).css({backgroundPosition: "0px 0px","backgroundImage":"url(sitio/img/current.png)",color: "#fff"})
        }
    });

//Current inicio
    $('.taco_azul a#inicio').each( function(idx, el) {
        if (el.href === window.location.toString()) {            
            $(el).css("color", "#fff");
            $(el).parent().parent().parent().find('a').toggleClass('current_menu');
        }
    });

//Submenu
    $("#nav ul").css({display: "none"}); // Opera Fix
    $("#nav ul").parent().append("<span></span>");
    $("#nav li").hover(function(){
        $(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
        },function(){
        $(this).find('ul:first').css({visibility: "hidden"});
    });

//Acordeon
    $(".acordeon ul li ul").hide();   
    $(".acordeon ul li a").click(function(){
        if($(this).children('span').hasClass('abierto')){
            $(this).children('span').removeClass('abierto').addClass('cerrado');
        }else{
            $(this).children('span').removeClass('cerrado').addClass('abierto');
        }        
            $(this).next("ul").slideToggle("300").parent("li").siblings("li").find("ul:visible").slideUp("300");            
            $(this).toggleClass("open");
            $(this).parent("li").siblings("li").find("a").removeClass("open");
            $(".acordeon ul li a[class!='open']").children('span').removeClass('abierto').addClass('cerrado');
    });
	
	$(".acordeon ul li a").each(function(){
		if($(this).attr('class')=='toto') {
			$(this).toggleClass("open").removeClass("toto");
			$(this).parents("li").parents("ul").css({display:"block"});
            $(this).next("ul").slideToggle("300");
		}
    });


//Flash
    var cab= /(inicio)/;
	var jslan= $('a#jslan').attr('href');
    if ( window.location.toString() === base || cab.test(window.location.toString())) {
        flashembed("flash", {src: "sitio/img/swf/cab_home"+jslan+".swf", wmode: 'transparent', width: '970px', height: '219px'});
        $('div.cont_flash').css('height', '219px');
        $('div.cont_flash').css('backgroundImage', 'url(sitio/img/bg_flash.gif)');
        $('div.cont_flash').css('backgroundRepeat', 'repeat-x');
    }else{
         flashembed("flash", {src: "sitio/img/swf/cab_interna"+jslan+".swf", wmode: 'transparent', width: '970px', height: '90px'});
         $('div.cont_flash').css('height', '90px');
         $('div.cont_flash').css('backgroundImage', 'url(sitio/img/bg_flash2.gif)');
         $('div.cont_flash').css('backgroundRepeat', 'repeat-x');
    }

//Banner Home
    if ( $("#banner").length > 0 ) {
        flashembed("banner", {src: "sitio/img/swf/banner.swf", wmode: 'transparent', width: '230px', height: '150px', flashvars: 'url=http://www.google.com'});
    }

//Ver mas
    $('#descripcion').css('height', '215px');
    $('a#vermenos').hide();
    var alturamentira=15+$('#ampliar_txt').height();
    $("a#vermas").click(function() {
        $('#descripcion').animate({
            height:alturamentira+'px'
        }, function(){
            $('#ampliar_txt').slideDown();
            $('a#vermenos').show();
            $("a#vermas").hide();
        })
    })

    $("a#vermenos").click(function() {
        $('#descripcion').animate({
            height:'215px'
        }, function(){
            $('a#vermenos').hide();
            $("a#vermas").show();
        })
    })


//Ver mas DETALLE
    $('#descripcion_detalle').css('height', '390px');
    $('a#vermenos').hide();
    var alturamentira2=20+$('#ampliar_txt').height();
    $("a#vermas").click(function() {
        $('#descripcion_detalle').animate({
            height:alturamentira2+'px'
        }, function(){
            $('#ampliar_txt').slideDown();
            $('a#vermenos').show();
            $("a#vermas").hide();
        })
    })

    $("a#vermenos").click(function() {
        $('#descripcion_detalle').animate({
            height:'390px'
        }, function(){
            $('a#vermenos').hide();
            $("a#vermas").show();
        })
    })


    $("a.zoom").fancybox({
        'onComplete' : function() {$("#fancybox-wrap").unbind('mousewheel.fb');} ,
        'transitionIn'  :   'elastic',
        'transitionOut' :   'elastic',
        'zoomSpeedIn'   :   500,
        'zoomSpeedOut'  :   500,
        'overlayShow'   :   false,
        'width'         :   1000,
        'height'        :   600
    });

    $('a.mapa').fancybox({
            'transitionIn'	:	'elastic',
            'transitionOut'	:	'elastic',
            'speedIn'		:	500,
            'speedOut'		:	500,
            'overlayShow'	:	false,
            'type'          :       'iframe',
            'width'         :       600,
            'height'        :       360
    });

//validate newsletter inicio
    $('#suscripcion').validate({
        rules: {
            nombre: {
                required: true
            },
            email: {
                required: true
            }
        }
    });

//validate newsletter
    $('#newsletter').validate({
        rules: {
            nombre: {
                required: true
            },
            email: {
                required: true
            }
        }
    });
    
//validate contacto
    $('#contacto').validate({
        rules: {
            nombre: {
                required: true
            },
            telefono: {
                required: true
            },
            pais: {
                required: true
            },
            empresa: {
                required: true
            },
            ciudad: {
                required: true
            },
            comentarios: {
                required: true
            },
            mail: {
                required: true
            }
        }
    });


//SLIDE CATEGORIAS DE PRODUCTOS
    $("div.cont").hover(
        function(){$("div.slide_productos",this).stop().animate({'top':'0px'},700,'easeOutExpo');},
        function(){$("div.slide_productos",this).stop().animate({'top':'-200px'},400,'easeOutExpo');}
    );

//SUBMIT BUSCADOR TOP Y HOME
    $("a#lupita").click(function(){
			$("form#buscatop").submit();
			return false;
    });
	
	$("a#lupitahome").click(function(){
			$("form#buscahome").submit();
			return false;
    });
	
//CONTACTO
	$('p.oficedata').hide();
	$('p.oficedata').first().show();
	$('#oficina_central').css({'backgroundPosition':'0 -8px'});
	
	$('a.ofice').click(function(){
		$('a.ofice').css({'backgroundPosition':'0 0'});
		$(this).css({'backgroundPosition':'0 -8px'});
		$('p.oficedata').hide();
		var oficina = $(this).attr('rel');
		$(oficina).show();
	});
	
});// Cierro document ready
