/**************************************************************/
//						HIGHSLIDE
/**************************************************************/
// override Highslide settings here
// instead of editing the highslide.js file
hs.graphicsDir = '/js/highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.wrapperClassName = 'dark borderless floating-caption';

hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.dimmingOpacity = .75;
hs.showCredits = false; 

var galleryOptions = {
	slideshowGroup: 'gallery',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: .6,
		position: 'bottom center',
		hideOnMouseOut: true
	}
};

// Add the controlbar
if (hs.addSlideshow) hs.addSlideshow({
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: .6,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});
    function fixElement(el) {
       var stl = el.style;
       stl.position = 'fixed';
       stl.top = (parseInt(stl.top) - hs.page.scrollTop) +'px';
       stl.left = (parseInt(stl.left) - hs.page.scrollLeft) +'px';
   }
   function unfixElement(el) {
      var stl = el.style;
      stl.position = 'absolute';
      stl.top = (parseInt(stl.top) + hs.page.scrollTop) +'px';
      stl.left = (parseInt(stl.left) + hs.page.scrollLeft) +'px';
   }

   if (!hs.ie || hs.ieVersion() > 6) {
       hs.Expander.prototype.onAfterExpand = function() {
          fixElement (this.wrapper);
         if (this.outline) fixElement(this.outline.table);
      };

       hs.Expander.prototype.onBeforeClose = function() {
          unfixElement (this.wrapper);
         if (this.outline) unfixElement(this.outline.table);
      };
   }
hs.lang = {
   loadingText :     'Cargando...',
   loadingTitle :    'Click para cancelar',
   focusTitle :      'Click para traer al frente',
   fullExpandTitle : 'Expandir al tama�o actual',
   fullExpandText :  'Tama�o real',
   creditsText :     'Potenciado por <i>Highslide JS</i>',
   creditsTitle :    'Ir al home de Highslide JS',
   previousText :    'Anterior',
   previousTitle :   'Anterior (flecha izquierda)',
   nextText :        'Siguiente',
   nextTitle :       'Siguiente (flecha derecha)',
   moveTitle :       'Mover',
   moveText :        'Mover',
   closeText :       'Cerrar',
   closeTitle :      'Cerrar (esc)',
   resizeTitle :     'Redimensionar',
   playText :        'Iniciar',
   playTitle :       'Iniciar slideshow (barra espacio)',
   pauseText :       'Pausar',
   pauseTitle :      'Pausar slideshow (barra espacio)',
   restoreTitle :    'Click para cerrar la imagen, click y arrastrar para mover. Usa las flechas del teclado para avanzar o retroceder.'
};

//scrips de inicio
jQuery(function() {
	//lavalamp
	jQuery('#menuNav').lavaLamp({
		fx: "backout",
		speed: 600
	});
	
	//Formulario de contacto
	jQuery("#formContact").validate({
		errorLabelContainer: $("#formContact div.error"),
		submitHandler: function(form) {
			data = jQuery(form).serializeArray();
			if( jQuery('input[name=quoteQuestion]:checked').val() == 1){
				alert('cotizacion');
			} else {
				jQuery('#formSent').fadeIn(2000).load('/ajax/contacts/send', data);
			}
		}
	});
	
	jQuery('#formContact').submit(function(){
		
		return false;
	});
});

function cleanAllImages(){
	var imglst = document.images; 
    for(var i = 0; i < imglst.length; i++){ 
      imglst[i].onerror = function() { 
        this.src = "/img/espacio.gif"; 
      }
      imglst[i].src = imglst[i].src; 
    }
}
jQuery(document).ready(function() {
	setTimeout("cleanAllImages()",3000);

	
	
	/**************************************************************/
	//						Scroll en links
	/**************************************************************/
	function filterPath(string) {
		return string
		.replace(/^\//,'')
		.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
		.replace(/\/$/,'');
	}
	var locationPath = filterPath(location.pathname);
	$('a[href*=#]').each(function() {
		var thisPath = filterPath(this.pathname) || locationPath;
		if (  locationPath == thisPath
		&& (location.hostname == this.hostname || !this.hostname)
		&& this.hash.replace(/#/,'') ) {
		  var $target = $(this.hash), target = this.hash;
		  if (target) {
			var targetOffset = $target.offset().top;
			$(this).click(function(event) {
			  event.preventDefault();
			  $('html, body').animate({scrollTop: targetOffset}, 1000, function() {
				location.hash = target;
			  });
			});
		  }
		}
	});
	
	//CHAT FLOTANTE

	jQuery('#chatFloat').scrollFollow({relativeTo: 'bottom', offset: 10, easing: 'backout', 
		killSwitch: 'chatFloatClose', onText: '<img src="/img/icons/fail.gif">', offText: '<img src="/img/icons/arrow-downright.gif">'});
	jQuery("#chatFloat").fadeTo("slow", 0.6).hover(function(){
		jQuery("#chatFloat").fadeTo("slow", 1.0); 
	},function(){
		jQuery("#chatFloat").fadeTo("slow", 0.6); 
	});

});
//LLAMAMOS AL OBJETO AJAX
function crearXMLHttpRequest() 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}



