// NAV

$(document).ready(function(){
	// We can use this object to reference the panels container
	var panelContainer = $('div#panels');
	// Create a DIV for the tabs and insert it before the panel container
	$('<div id="tabs"></div>').insertBefore(panelContainer);
	
	// Find panel names and create nav
	// -- Loop through each panel
	panelContainer.find('div.panel').each(function(n){
		// For each panel, create a tab
		$('div#tabs').append('<a class="tab" href="#' + (n+1) + '">' + $(this).attr('title') + '</a>');
	});
	
	// Determine which tab should show first based on the URL hash
	var panelLocation = location.hash.slice(1);
	if(panelLocation){
		var panelNum = panelLocation;
	}else{
		var panelNum = '1';
	}
	// Hide all panels
	panelContainer.find('div.panel').hide();
	// Display the initial panel
	panelContainer.find('div.panel:nth-child(' + panelNum + ')').fadeIn('slow');
	// Change the class of the current tab
	$('div#tabs').find('a.tab:nth-child(' + panelNum + ')').removeClass().addClass('tab-active');
	
	// What happens when a tab is clicked
	// -- Loop through each tab
	$('div#tabs').find('a').each(function(n){
		// For each tab, add a 'click' action
		$(this).click(function(){
			// Hide all panels
			panelContainer.find('div.panel').hide();
			// Find the required panel and display it
			panelContainer.find('div.panel:nth-child(' + (n+1) + ')').fadeIn('slow');
			// Give all tabs the 'tab' class
			$(this).parent().find('a').removeClass().addClass('tab');
			// Give the clicked tab the 'tab-active' class
			$(this).removeClass().addClass('tab-active');
		});
	});
});


// Toggle
//$(document).ready(function() {
//	$('#nav > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle'  } });
// $('#tabvanilla div').hide();
//});


// Slideshow
//$(function(){
//	$('.fadein img:gt(0)').hide();
//	setInterval(function(){$('.fadein :first-child').fadeOut().next('img').fadeIn().end().appendTo('.fadein');}, 6000);
//});

$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500, //Slide transition speed
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
      controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
});




function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}


// Taurus

function ir_a (cod_producto){
	location = "taurus-detalle-producto.php?cod_producto="+cod_producto;
}
function ir_a_pagina (seccion, campo1){
	if (seccion == "ar"){
		location = "taurus-articulos.php?seccion="+seccion;	
	}
	if (seccion == "se"){
		location = "taurus-servicios.php?seccion="+seccion;	
	}
	if (seccion == "qs"){
		location = "taurus-historia.php?seccion="+seccion;	
	}
	sectionid = "" + campo1;
	var thediv=getObjectFromID(sectionid);
	if (thediv.style.display=="none"){ // MUESTRA
		thediv.style.display="block";
	}
	else { // OCULTA
		thediv.style.display="none";
	}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p);
		  max=test.substring(p+1);

          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';

    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function setHomePage(homepage,la_url_es) {
    var agt=navigator.userAgent.toLowerCase();
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
   var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) && (agt.indexOf("msie 6")==-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
   var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
if (is_win && is_ie5up) {
		oHomePage.style.behavior='url(#default#homepage)';
		oHomePage.setHomePage(homepage);
	}
}

//Returns an object given an id
function getObjectFromID(id){
	var theObject;
	if(document.getElementById)
		theObject=document.getElementById(id);
	else
		theObject=document.all[id];
	return theObject;
}
function hideSection(campo1){
	sectionid = "" + campo1;
	var thediv=getObjectFromID(sectionid);
	if (thediv.style.display=="none"){ // MUESTRA
		thediv.style.display="block";
	}
	else { // OCULTA
		thediv.style.display="none";
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function formHandler()
{
	if (document.form.cod_estado.value == "0"){
		alert("Por favor, elija un estado");		
	}else {
		var URL = document.form.cod_estado.options[document.form.cod_estado.selectedIndex].value;
		window.parent.location.href = URL+"#3";
	}
}

function aceptar()
{
			if (blanco(document.myForm.nombre.value))
			{
					alert("Por favor ingrese el Nombre.");
					document.myForm.nombre.focus();
					return false;
			}

			if (blanco(document.myForm.apellido.value))
			{             
					alert ("Por favor ingrese el apellido.");
					document.myForm.apellido.focus();
					return false;
			}		

			if (blanco(document.myForm.email.value))
			{             
					alert ("Por favor ingrese el E-mail.");
					document.myForm.email.focus();
					return false;
			}		

			if (blanco(document.myForm.telefono.value))
			{             
					alert ("Por favor ingrese el teléfono.");
					document.myForm.telefono.focus();
					return false;
			}			
			if (blanco(document.myForm.defecto.value))
			{             
					alert ("Por favor señale el defecto .");
					document.myForm.defecto.focus();
					return false;
			}			

	document.myForm.submit();
      return true;
}
/* ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''*/
/* '''''''''''''''Verifica que los campos no esten en blanco'''''''''''''''''' */
/* ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''*/
function blanco(s)
   {    
    for (var i = 0; i < s.length; i++) 
        {
         var c = s.charAt(i);
          if ((escape(c)!='%0D')&&(escape(c)!='%0A')&&(c !=" "))
             	return false;
        }        
   return true
  }
  
 
 // Calendar
 var cal = new CalendarPopup(); 
	cal.showNavigationDropdowns();
	cal.setYearSelectStartOffset(10);
	
	
// Fancybox
$(document).ready(function() {
			
			$("a.iframe").fancybox({
				'titleShow'		: false
			});
			
			$("a#example1").fancybox({
				'titleShow'		: false
			});
			
			$("a[rel=grupo]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'overlayOpacity'	: '0.4',
				'overlayColor'		: '#000',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Imagen ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			
		});
		

