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 accordionConHash(selector) {
	$(selector).accordion();
	$(".ui-accordion-header").each(function(i) {
		if('#'+(i+1) == document.location.hash) {
			$(".ui-accordion").accordion("activate",i);
		}
	});
}
function lightBox(selector, selectorHandle) {
	$(selector).colorbox();
	$(selectorHandle).click(function(){
		/* editar esto */
  		$(this).parent().parent().prev().find('a:first').click();
  		return false;
	});
}
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 efectoFoco(selector1, selector2, tiempo) {
	var over = function() { 
				var $img = $(this).find(selector2);
				$img.dequeue();
				$img.animate({opacity:"1"},tiempo); 
			};
	var out = function() {
				var $img = $(this).find(selector2);
				$img.dequeue();
				$img.animate({opacity:"0.5"},tiempo); 
			};
	$(selector1).hover(over, out);
}
function defaultFormValues(styles) {
	if(empty(styles)) {
		styles = {
			"color": "#999999",
			"font-style": "italic"
		};
	}
	function getStyles($objs) {
		var styles = [];
		$objs.each(function(index, obj){
			var $obj = $(obj);
			styles[index] = {
				"color": $obj.css("color"),
				"font-style": $obj.css("font-style")
			}
		});
		return styles;
	}
	function setStyle($obj, style) {
		return $obj.css(style);
	}
	function setStyles($objs, styles) {
		$objs.each(function(index, obj){
			setStyle($(obj), styles[index]);
		});
		return $objs;
	}
	var $inputs = $.merge($("form input[type='text']"), $("form textarea")).filter(function(){ return !empty($(this).val()); });
	var defaultStyles = getStyles($inputs);
	$inputs = setStyle($inputs, styles);
	$inputs.each(function(index, obj){
		var $obj = $(this);
		$obj.addClass("default_value");
		var value = $obj.val();
		$obj.focus(function(){
			var $this = $(this);
			if(($this.hasClass("default_value") && ($obj.val() == value)) || empty($this.val())) {
				$this.val("");
				setStyle($this, defaultStyles[index]);
				$this.removeClass("default_value");
			}
		});
		$obj.blur(function(){
			var $this = $(this);
			if(empty($this.val())) {
				$this.val(value);
				setStyle($this, styles);
				$this.addClass("default_value");
			}
		});
		$obj.parents("form").eq(0).submit(function(){ 
			if($obj.hasClass("default_value") && ($obj.val() == value)){
				$obj.val("");
			} 
		});
	}) ;
}

function fixPng() {
	$(function() {
		if($.browser.msie && ($.browser.version.substr(0,1) < 7)){
			$("*").ifixpng();
		}
	});
}
function isSwf(filename) {
	var isValid = false;
	extnRx = new RegExp('\.swf'.toUpperCase()+'$');
	if (extnRx.exec(filename.toUpperCase())) {
		isValid = true;
	}
	return isValid;
}
function embedBannerGrupo(banners, width, height, vinculo) {
	/* De la forma:
	<div class="banner">
		<div id="banner-{$idBanner}">
		</div>
	</div>
	*/
	var i, banner;
	for(i in banners) {
		banner = banners[i];
		if(isSwf(banner.archivo) && ($("#banner-"+banner.id).length == 1)) {
			swfobject.embedSWF('images/banners/'+banner.archivo, 'banner-'+banner.id, width, height, '6', null, "href="+vinculo);
		}
	}
}
