function preloadImages(images) {
	var $div = $(document.createElement("div"));
	$div.css({
		height:'1px',
		overflow:'hidden'
	});
	var src;
	var $img;
	for(var i = 0; i < images.length; i++) {
		src = images[i];
		$img = $(document.createElement("img"));
		$img.attr("src", src);
		$img.appendTo($div);
	}
	$("#header").after($div);
}
function carouselTrabajosPortfolio(selector) {
	$(function() {
		$(selector).jcarousel({
			vertical: true,
			wrap: "last",
			scroll: 1,
			auto: 10
		});
	});
} 
function accordionServicios(selector) {
	$(selector).accordion();
	$(".ui-accordion-header").each(function(i) {
		if('#'+(i+1) == document.location.hash) {
			$(".ui-accordion").accordion("activate",i);
		}
	});
}
function lightBox() {
	$('.thumb a').colorbox();
	$('.ver_fotos').click(function(){
  		$(this).parent().parent().prev().find('a:first').click();
  		return false;
	});
}
function showAccesoClientes() {
	if(!$("#acceso_clientes").hasClass("open")) {
		$("#acceso_clientes").stop();
		var callback = function() {
			var callback2 = function(){
				//$("#header").css("overflow","visible");
				$("#acceso_clientes p.sinmargen").css("visibility","visible");
				$("#acceso_clientes").addClass("open");
			}
			$("#acceso_clientes").animate({	height:"135px",
											bottom:"-25px"
										},"normal","linear",callback2);
		}
		$("#acceso_clientes").animate({	height:"110px"},"normal","swing",callback);
	}
}
function hideAccesoClientes() {
	$("#acceso_clientes").stop();
	$("#acceso_clientes").removeClass("open");
	$("#acceso_clientes p.sinmargen").css("visibility","hidden");
	//$("#header").css("overflow","hidden");
	var callback = function() {
		$("#acceso_clientes").animate({	height:"64px"});
		$("#acceso_clientes").addClass("closed");
	}
	$("#acceso_clientes").animate({	height:"110px",
										bottom:"0px"
								  },
									"normal",
									"linear",
									callback);
}
function animateAccesoClientes() {
	$(function() {
	   var funcOver = showAccesoClientes;
	   var funcOut = hideAccesoClientes;
	   $("#acceso_clientes").hover(funcOver,funcOut);
	});
}
function carouselNoticias(selector) {
	$(function() {
		$(selector).jcarousel({
			vertical: true,
			wrap: "last",
			scroll: 1,
			auto: 10,
			buttonNextHTML: null,
			buttonPrevHTML: null 
		});
	});
}
function bindMostrarVentana(selectorTrigger, selectorVentana, width, height) {
	$(selectorTrigger).click(function(){
		 mostrarVentana(selectorVentana, width, height);
		 return false;
	});
}
function mostrarVentana(selector, width, height) {
	if(width == null) {
		width = 650;
	}
	if(height == null) {
		height = 430;
	}
	$.fn.colorbox({
		width:width+"px", 
		height:height+"px",
		display:"block",
		href:selector,
		opacity:0.8,
		open:true,
		inline:true
	});
}
function formularioSetFocuses(selectorForm) {
	setFocusBlur($(selectorForm+" input"));
	setFocusBlur($(selectorForm+" textarea"));
	setFocusBlur($(selectorForm+" select"));
}
function setFocusBlur($obj) {
	setElementOnFocus($obj);
	setElementOnBlur($obj);
}
function setElementOnFocus($obj) {
	$obj.focus(function() {
		$(this).addClass("focus");
		$(this).parents("div:first").prevAll("label:first").eq(0).addClass("focus");
	});
}
function setElementOnBlur($obj) {
	$obj.blur(function() {
		$(this).removeClass("focus");
		$(this).parents("div:first").prevAll("label:first").eq(0).removeClass("focus");
	});
}
function setOnsubmit($form, onsubmit) {
	if(typeOf(onsubmit) == "function") {
		$form.submit(onsubmit);
	}
}
function attachSubmitToForm($elem, $form, callback) {
	$elem.click(function(){ 
		$form.submit();
		if(typeOf(callback) == "function") {
			return callback();
		}
	});
}
function scrollToSelector(selector, callback, duration, over) {
	if(typeOf(callback) != "function") {
		callback = function(){};
	}
	if(duration == null) {
		duration = 600;
	}
	if(over == null) {
		over = 0;
	}
	$.scrollTo($(selector), {
		duration: duration,
		axis: "y",
		onAfter: callback,
		over: over
	});
}
function attachGoToAcceso($elem, callback) {
	$elem.click(function(){
		var over = ($("#acceso_clientes").hasClass("open")) ? 0 : -0.7;
		scrollToSelector("#acceso_clientes", showAccesoClientes, 600, over);
		if(typeOf(callback) == "function") {
			return callback();
		}
	});
}
function bindSolicitarLlamada(selector) {
	$(selector).click(function(){			   
		asuntoFormularioContacto(msgstr[10]);
		scrollToSelector("#contenidos");
		return false;
	});
}
function asuntoFormularioContacto(asunto) {
	$("#id_asunto").val(asunto);
}
