$(document).ready(function() {
    $('#barra-superior li, #social-pie li').hover(function(){
        $(this).find('span').stop(true, true).fadeIn("slow");
    }, function(){
        $(this).find('span').stop(true, true).fadeOut("slow");
    });
    $('#menu li').hover(function(){
		if(checkIEVersion())
			$(this).find('ul').stop(true, true).show();
		else
			$(this).find('ul').stop(true, true).fadeIn("slow");

    }, function(){
        $(this).find('ul').stop(true, true).hide();
    });
    $(".botones-secciones-5 li a img").hover(function(){
        $(".botones-secciones-5 li a img").stop(true, true).animate({
            opacity: 1
          }, 300);
        $(".botones-secciones-5 li a img").not(this).stop(true, true).animate({
            opacity: 0.3
          },300);
        });
    $(".botones-secciones-5 li a img").mouseleave(function(){
        $(".botones-secciones-5 li a img").stop(true, true).animate({
            opacity: 1
          },300);
    });
	
	$('.pack_repuestos li').hover(function(){
        $(this).find('span').stop(true, true).fadeIn("fast");
    }, function(){
        $(this).find('span').stop(true, true).fadeOut("fast");
    });


	var alertTimerId;
	$("#flash-pie").mouseout(function() {
		clearTimeout(alertTimerId);
		alertTimerId= setTimeout('ocultaIconosFooter()', 2000);
	});


});

function ocultaIconosFooter()
{
	$(".sn-c-vehiculos").stop().hide(0);
	$(".sn-c-maq").stop().hide(0);
	$(".sn-c-parts").stop().hide(0);
	$("#tercer-nivel.tn-c-vehiculos").stop().hide(0);
	$(".sn-c-autoplanet").stop().hide(0);
}


$(window).load(function() {
    $('#slider-bienvenida').nivoSlider({
        effect:'fade',
        slices:3,
        animSpeed:700, 
        pauseTime:3000,
        startSlide:0, 
        directionNav:false, 
        directionNavHide:true, 
        controlNav:false, 
        keyboardNav:false,
        pauseOnHover:true, 
        manualAdvance:false

    });
});

function getInternetExplorerVersion()
// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
{
   var rv = -1; // Return value assumes failure.
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}
function checkIEVersion()
{
   var ver = getInternetExplorerVersion();
   if ( ver> -1 )
   {
      if ( ver>= 8.0 )
         return true;
      else if ( ver == 7.0 )
    	  return true;
      else if ( ver == 6.0 )
    	  return true;
      else
    	  return true;
    }else{
	   return false;
	}
}


function footerSegundoNivel(cat)
{
	if(checkIEVersion())
	{
		$(".sn-c-vehiculos").stop().hide();
		$(".sn-c-maq").stop().hide();
		$(".sn-c-parts").stop().hide();
		$(".sn-c-vehiculos").stop().hide();
		$(".sn-c-autoplanet").stop().hide();
		$(".tn-c-vehiculos").stop().hide();
		
		$(".sn-" + cat).show();
	}else{
		$(".sn-c-vehiculos").stop().hide(0);
		$(".sn-c-maq").stop().hide(0);
		$(".sn-c-parts").stop().hide(0);
		$("#tercer-nivel.tn-c-vehiculos").stop().hide(0);
		$(".sn-c-autoplanet").stop().hide(0, function(){
			$(".sn-" + cat).stop().show(0);
		});
	}
}

function footerTercerNivel(cat)
{
	if(checkIEVersion())
	{
		$(".tn-c-vehiculos").stop().hide();
		$(".tn-" + cat).stop().show();
	}else{
		$("#tercer-nivel.tn-c-vehiculos").stop().hide(0, function(){
			$("#tercer-nivel.tn-" + cat).stop().show(0);
		});
	}
}


//ACORDION

$(document).ready(function(){
		$(".acordeon dd:not(:first)").hide();
		
	});


var acc1= true;
var acc2= false;
var acc3= false;
var acc4= false;
var acc5= false;
var acc6= false;
var acc7= false;
var acc8= false;
var acc9= false;
var acc10= false;	
	function acordion(num)
	{
	
		if(num == 1)
		{				
			if(acc1){
				$("#masmenos_1").css({backgroundPosition: "0 0"});
				$("#opcion1").slideUp("fast");
				acc1= false;
			}else{
				$("#masmenos_1").css({backgroundPosition: "0 -13px"});
				$("#opcion1").slideDown("fast");
				acc1= true;
			}
		}else if(num == 2){
			if(acc2){
				$("#masmenos_2").css({backgroundPosition: "0 0"});
				$("#opcion2").slideUp("fast");
				acc2= false;
			}else{
				$("#masmenos_2").css({backgroundPosition: "0 -13px"});
				$("#opcion2").slideDown("fast");
				acc2= true;
			}
		}else if(num == 3){
			if(acc3){
				$("#masmenos_3").css({backgroundPosition: "0 0"});
				$("#opcion3").slideUp("fast");
				acc3= false;
			}else{
				$("#masmenos_3").css({backgroundPosition: "0 -13px"});
				$("#opcion3").slideDown("fast");
				acc3= true;
			}
		}else if(num == 4){
			if(acc4){
				$("#masmenos_4").css({backgroundPosition: "0 0"});
				$("#opcion4").slideUp("fast");
				acc4= false;
			}else{
				$("#masmenos_4").css({backgroundPosition: "0 -13px"});
				$("#opcion4").slideDown("fast");
				acc4= true;
			}
		}else if(num == 5){
			if(acc5){
				$("#masmenos_5").css({backgroundPosition: "0 0"});
				$("#opcion5").slideUp("fast");
				acc5= false;
			}else{
				$("#masmenos_5").css({backgroundPosition: "0 -13px"});
				$("#opcion5").slideDown("fast");
				acc5= true;
			}
		}else if(num == 6){
			if(acc6){
				$("#masmenos_6").css({backgroundPosition: "0 0"});
				$("#opcion6").slideUp("fast");
				acc6= false;
			}else{
				$("#masmenos_6").css({backgroundPosition: "0 -13px"});
				$("#opcion6").slideDown("fast");
				acc6= true;
			}
		}else if(num == 7){
			if(acc7){
				$("#masmenos_7").css({backgroundPosition: "0 0"});
				$("#opcion7").slideUp("fast");
				acc7= false;
			}else{
				$("#masmenos_7").css({backgroundPosition: "0 -13px"});
				$("#opcion7").slideDown("fast");
				acc7= true;
			}
		}else if(num == 8){
			if(acc8){
				$("#masmenos_8").css({backgroundPosition: "0 0"});
				$("#opcion8").slideUp("fast");
				acc8= false;
			}else{
				$("#masmenos_8").css({backgroundPosition: "0 -13px"});
				$("#opcion8").slideDown("fast");
				acc8= true;
			}
		}else if(num == 9){
			if(acc9){
				$("#masmenos_9").css({backgroundPosition: "0 0"});
				$("#opcion9").slideUp("fast");
				acc9= false;
			}else{
				$("#masmenos_9").css({backgroundPosition: "0 -13px"});
				$("#opcion9").slideDown("fast");
				acc9= true;
			}
		}
}

//ACORDEON FAQ

$(document).ready(function(){
		$(".acordeon_faq dd:not(:first)").hide();
		
	});


var acc1= true;
var acc2= false;
var acc3= false;
var acc4= false;
var acc5= false;

	function acordion_faq(num)
	{
	
		if(num == 1)
		{				
			if(acc1){
				$("#mas_1").css({backgroundPosition: "0 0"});
				$("#opcion1").slideUp("fast");
				acc1= false;
			}else{
				$("#mas_1").css({backgroundPosition: "0 -13px"});
				$("#opcion1").slideDown("fast");
				acc1= true;
			}
		}else if(num == 2){
			if(acc2){
				$("#mas_2").css({backgroundPosition: "0 0"});
				$("#opcion2").slideUp("fast");
				acc2= false;
			}else{
				$("#mas_2").css({backgroundPosition: "0 -13px"});
				$("#opcion2").slideDown("fast");
				acc2= true;
			}
		}else if(num == 3){
			if(acc3){
				$("#mas_3").css({backgroundPosition: "0 0"});
				$("#opcion3").slideUp("fast");
				acc3= false;
			}else{
				$("#mas_3").css({backgroundPosition: "0 -13px"});
				$("#opcion3").slideDown("fast");
				acc3= true;
			}
		}else if(num == 4){
			if(acc4){
				$("#mas_4").css({backgroundPosition: "0 0"});
				$("#opcion4").slideUp("fast");
				acc4= false;
			}else{
				$("#mas_4").css({backgroundPosition: "0 -13px"});
				$("#opcion4").slideDown("fast");
				acc4= true;
			}
		}else if(num == 5){
			if(acc5){
				$("#mas_5").css({backgroundPosition: "0 0"});
				$("#opcion5").slideUp("fast");
				acc5= false;
			}else{
				$("#mas_5").css({backgroundPosition: "0 -13px"});
				$("#opcion5").slideDown("fast");
				acc5= true;
			
			}
		}else if(num == 6){
			if(acc6){
				$("#mas_6").css({backgroundPosition: "0 0"});
				$("#opcion6").slideUp("fast");
				acc6= false;
			}else{
				$("#mas_6").css({backgroundPosition: "0 -13px"});
				$("#opcion6").slideDown("fast");
				acc6= true;
			
			}
		}
}
//

function trackEvent(cat,act,lbl) {
	try {
	_gaq.push(['_trackEvent', cat,act,lbl]);
	} catch(err) {}
}

//ocultar menu contextual en imagenes

$(document).ready(function()
    {
       $('img').bind("contextmenu",function(e){
              return false;
       });
    }); 
	
//popup redes
$(document).ready(function() {
	//Code goes here

//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="img/close_pop.png" class="btn_close" title="Cerrar" alt="Cerrar" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
});

//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
    return false;
});	
});


