$(document).ready(function(){
	$.preloadImages('images/m1-act.gif','images/m2-act.gif','images/m3-act.gif','images/m4-act.gif','images/m5-act.gif');
	$.rollOver('.rollover');
	if ($('form#Contacto').length) {
		var c = $.parseURI(window.location.href);
		try {
			var m = '&iexcl;Error! Disculpe las molestias. Intentelo de nuevo m&aacute;s tarde. <br /> '; 
			var s = 'e';
			if (c.params['m']) { m = '&iexcl;Gracias por confiar en nosotros! Pronto nos pondremos en contacto. <br />'; s = 'v'; }
			$('#CC').prepend( $('<p>').attr('class', s).html(m) );
		} catch (a) { console.log(a) }
		$('form#Contacto').validate();
	}
	if ($('#gallery a').length) { 
		$('#gallery a').lightBox({txtImage:'Imagen', txtOf:'de'});
	}
	var COOKIE = 'Carga';
	bCarga = (!$.cookie(COOKIE));
	$.cookie(COOKIE, 0, { path: '/', expires: 10 }); 
	if (bCarga) { 
		$('div#swf').flash({src:'swf/cabecera.swf', width:943, height:188, menu:'false'}); 
	}
});

jQuery.rollOver = function() {
	$(arguments[0]).hover(function() {
		var currentImg = $(this).attr('src');
		$(this).attr('src', $(this).attr('hover'));
		$(this).attr('hover', currentImg);
	}, function() {
		var currentImg = $(this).attr('src');
		$(this).attr('src', $(this).attr('hover'));
		$(this).attr('hover', currentImg);
	});	
}

jQuery.preloadImages = function() {
	for(var i = 0; i < arguments.length; i++) {
    	jQuery('<img>').attr('src', arguments[i]);
	}
}

jQuery.parseURI = function(uri, options) {
	var m = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/.exec(uri);
    var u = {};
    var options = jQuery.extend(jQuery.extend({}, arguments.callee.defaults), options);
    //var options = jQuery.extend({}, arguments.callee.defaults, options);
    
	if (options.generic) {
		// Generic components (as specified in RFC3986)
		u.scheme = m[2];
		u.authority = m[4];
		u.path = m[5];
		u.query = m[7];
		u.fragment = m[9];
	}
	
	if (options.location) {
		// window.location compatible properties
		u.hash = m[8];
		u.host = m[4];
		u.hostname = m[4].split(':')[0];
		u.href = uri;
		u.pathname = m[5];
		u.port = m[4].split(':')[1] || '';
		u.protocol = m[1];
		u.search = m[6];
	}
	
	if (options.params) {
		// Parse the query string
		try {
			var q = m[7].split(options.paramDelim);
			u.params = {};
			while (q.length > 0) {
				var x = q.shift().split('=');
				u.params[x[0]] = options.paramCallback(x[1]);
			}
		} catch (a) { console.log(a) }
	}
	
	return u;
};

jQuery.parseURI.defaults = {
	generic: true,
	location: false,
	params: true,
	paramDelim: '&',
	paramCallback: function(v) {
		if (v && !isNaN(v)) return Number(v);
		var l = v.toLowerCase();
		if (l == 'true') return true;
		if (l == 'false') return false;
		return v;
	}
};
