(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
// Para utilizar el script y cargar tus imágenes:
jQuery.preLoadImages("img/bg/1.jpg", "img/bg/2.jpg", "img/bg/3.jpg");

$(document).ready(function(){

	var Cookies = new CookieHandler();
	var bg = Cookies.getCookie('bg');
	if (typeof(bg) == 'undefined' || typeof(bg) == null || bg == null) bg = 1;
	
	$('html').css('backgroundImage','url("img/bg/'+bg+'.jpg")');
	$('body').css('backgroundImage','url("img/bg/'+bg+'.jpg")');	

	$('.bgc-1r').click(function () {
		$('body').fadeTo('fast', 0.5, function(){
			$('html').css('backgroundImage','url("img/bg/1.jpg")');
			$('body').css('backgroundImage','url("img/bg/1.jpg")');
			$('body').fadeTo('fast',1);
			$('#bgc-3l-1r').hide();
			$('#bgc-2l-1r').hide();
			$('#bgc-2l-3r').show();
		});
		Cookies.setCookie('bg', 1, 365*60*60);
		return false;
	 });
	$('.bgc-2l').click(function () { 
		$('body').fadeTo('fast', 0.5, function(){
			$('html').css('backgroundImage','url("img/bg/2.jpg")');
			$('body').css('backgroundImage','url("img/bg/2.jpg")');
			$('body').fadeTo('fast',1);
			$('#bgc-2l-3r').hide();
			$('#bgc-2l-1r').hide();
			$('#bgc-3l-1r').show();
		});
		Cookies.setCookie('bg', 2, 365*60*60);
		return false;
	 });
	$('.bgc-3r').click(function () { 
		$('body').fadeTo('fast', 0.5, function(){
			$('html').css('backgroundImage','url("img/bg/3.jpg")');
			$('body').css('backgroundImage','url("img/bg/3.jpg")');
			$('body').fadeTo('fast',1);
			$('#bgc-2l-3r').hide();
			$('#bgc-3l-1r').hide();
			$('#bgc-2l-1r').show();
		});
		Cookies.setCookie('bg', 3, 365*60*60);
		return false;
	 });
	$('.bgc-3l').click(function () { 
		$('body').fadeTo('fast', 0.5, function(){
			$('html').css('backgroundImage','url("img/bg/3.jpg")');
			$('body').css('backgroundImage','url("img/bg/3.jpg")');
			$('body').fadeTo('fast',1);
			$('#bgc-3l-1r').hide();
			$('#bgc-2l-3r').hide();
			$('#bgc-2l-1r').show();			
		});
		Cookies.setCookie('bg', 3, 365*60*60);		
		return false;
	 });

});



$(document).ready(function() {	
	$('.arrow-down').mousedown(function () { 
		$('.scroll-text').bind('marquee', function() {
			var ob = $(this);
			var th = ob.height();
			var ph = ob.parent().height();
			var hh = (th-(ph));
			ob.animate({ top: -hh }, ((th/ph)*1500) );
		}).trigger('marquee');
	});
	$('.arrow-down').mouseup(function(){
		$('.scroll-text').stop(true);
	});
	$('.arrow-up').mousedown(function () { 
		$('.scroll-text').bind('marquee-up', function() {
			var ob = $(this);
			var th = ob.height();			
			var ph = ob.parent().height();
			ob.animate({ top:0 }, ((th/ph)*1500) );
		}).trigger('marquee-up');
	});
	$('.arrow-up').mouseup(function(){
		$('.scroll-text').stop(true);
	});	
});

$(document).ready(function() {
	$('.img-holder').mouseover(function(){
		$(this).fadeTo('fast',0.7);
	 });	
	$('.img-holder').mouseout(function(){
		$(this).fadeTo('fast',1);
	 });		
	$('.img-holder img').click(function(){
		var src = $(this).attr('src');
		src = src.substr(0, src.lastIndexOf(".")) + ".jpg";
		$('.primary-holder img').attr('src',src);
		$('.primary-holder img').fadeTo('fast',0.6);		
		$('.img-holder img').fadeTo('fast',1);
		$(this).fadeTo('fast',0.6);
		$('.primary-holder img').fadeTo('slow',1);		
	});
});

$(document).ready(function() {
	$('.img-holder').click(function(){
		$('#gallery .title-img').fadeOut('fast');
	 });
	$('.img-arrow.first img').click(function(){
		$('.img-arrow.first').fadeOut('fast');
		$('.img-arrow.second').fadeIn('fast');		
		$('.img-holder.one').fadeOut('fast');
		$('.img-holder.two').fadeOut('fast');
		$('.img-holder.three').fadeOut('fast');
		$('.img-holder.four').fadeIn('slow');
		$('.img-holder.five').fadeIn('slow');
		$('.img-holder.six').fadeIn('slow');
	});
	$('.img-arrow.second img').click(function(){
		$('.img-arrow.first').fadeIn('slow');
		$('.img-arrow.second').fadeOut('fast');
		$('.img-holder.one').fadeIn('slow');
		$('.img-holder.two').fadeIn('slow');
		$('.img-holder.three').fadeIn('slow');
		$('.img-holder.four').fadeOut('fast');
		$('.img-holder.five').fadeOut('fast');
		$('.img-holder.six').fadeOut('fast');
	});
	$('.img-arrow.third img').click(function(){
		$('.img-arrow.fourth').fadeIn('slow');
		$('.img-arrow.third').fadeOut('fast');
		$('.img-arrow.second').fadeOut('fast');
		$('.img-holder.seven').fadeIn('slow');
		$('.img-holder.eight').fadeIn('slow');
		$('.img-holder.nine').fadeIn('slow');
		$('.img-holder.six').fadeOut('fast');
		$('.img-holder.five').fadeOut('fast');
		$('.img-holder.four').fadeOut('fast');
	});
	$('.img-arrow.fourth img').click(function(){
		$('.img-arrow.third').fadeIn('slow');
		$('.img-arrow.second').fadeIn('slow');
		$('.img-arrow.fourth').fadeOut('fast');
		$('.img-arrow.fifth').fadeOut('fast');
		$('.img-holder.six').fadeIn('slow');
		$('.img-holder.four').fadeIn('slow');
		$('.img-holder.five').fadeIn('slow');
		$('.img-holder.seven').fadeOut('fast');
		$('.img-holder.eight').fadeOut('fast');
		$('.img-holder.nine').fadeOut('fast');
		
	});	
	$('.img-arrow.fifth img').click(function(){
		$('.img-arrow.sixth').fadeIn('slow');
		$('.img-arrow.fifth').fadeOut('fast');
		$('.img-arrow.fourth').fadeOut('fast');
		
		$('.img-holder.ten').fadeIn('slow');
		$('.img-holder.eleven').fadeIn('slow');
		$('.img-holder.twelve').fadeIn('slow');
		
		$('.img-holder.seven').fadeOut('fast');
		$('.img-holder.eight').fadeOut('fast');
		$('.img-holder.nine').fadeOut('fast');
	});
	$('.img-arrow.sixth img').click(function(){
		$('.img-arrow.fifth').fadeIn('slow');
		$('.img-arrow.fourth').fadeIn('slow');
		$('.img-arrow.sixth').fadeOut('fast');
		$('.img-holder.nine').fadeIn('slow');
		$('.img-holder.eight').fadeIn('slow');
		$('.img-holder.seven').fadeIn('slow');
		$('.img-holder.ten').fadeOut('fast');
		$('.img-holder.eleven').fadeOut('fast');
		$('.img-holder.twelve').fadeOut('fast');
	});		
});

$(document).ready(function() {
	$('.inv img').click(function(){
		$('.inv img').fadeTo('fast',0.5);
		$(this).fadeTo('fast',1);
	});
});

function roll(img_name, img_src){
   document[img_name].src = img_src;
}

