
/***************     PARALLAX SCROLLING         ******************/
/*slide*/

var theWidth;
var theHeight;
var currentContent = 0;




jQuery(window).resize(function () {
    sizeContent();
	
});


jQuery(window).ready(function () {
							   
   /* jQuery(document).snowfall();
			
			jQuery("#clear").click(function(){
				jQuery(document).snowfall('clear'); // How you clear
			});
			
			jQuery("#round").click(function(){
				jQuery('body').css({'backgroundColor' : '#666'});
				jQuery(document).snowfall('clear');
				jQuery(document).snowfall({round : true, minSize: 5, maxSize:8}); // add rounded
			});
			
			jQuery("#shadows").click(function(){
				jQuery('body').css({'backgroundColor' : '#ccc'});
				jQuery(document).snowfall('clear');
				
				
				jQuery(document).snowfall({shadow : true, flakeCount:200}); // add shadows
			});

			jQuery("#roundshadows").click(function(){
				jQuery('body').css({'backgroundColor' : '#ccc'});
				jQuery(document).snowfall('clear');
				jQuery(document).snowfall({shadow : true, round : true,  minSize: 5, maxSize:8}); // add shadows
			});
			
			jQuery("#collection").click(function(){
				jQuery('body').css({'backgroundColor' : '#666'});
				jQuery(document).snowfall('clear');
				
				
				jQuery(document).snowfall({collection : '.collectonme', flakeCount : 250});
			});*/
	/********************/
	(function() {
	jQuery.fn.bgscroll = jQuery.fn.bgScroll = function( options ) {
		
		if( !this.length ) return this;
		if( !options ) options = {};
		if( !window.scrollElements ) window.scrollElements = {};
		
		for( var i = 0; i < this.length; i++ ) {
			
			var allowedChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
			var randomId = '';
			for( var l = 0; l < 5; l++ ) randomId += allowedChars.charAt( Math.floor( Math.random() * allowedChars.length ) );
			
				this[ i ].current = 0;
				this[ i ].scrollSpeed = options.scrollSpeed ? options.scrollSpeed : 70;
				this[ i ].direction = options.direction ? options.direction : 'h';
				window.scrollElements[ randomId ] = this[ i ];
				
				eval( 'window[randomId]=function(){var axis=0;var e=window.scrollElements.' + randomId + ';e.current -= 1;if (e.direction == "h") axis = e.current + "px 0";else if (e.direction == "v") axis = "0 " + e.current + "px";else if (e.direction == "d") axis = e.current + "px " + e.current + "px";$( e ).css("background-position", axis);}' );
														 
				setInterval( 'window.' + randomId + '()', options.scrollSpeed ? options.scrollSpeed : 70 );
			}
			
			return this;
		}
})(jQuery);
	/********************/
	/********************/
	(function() {
	jQuery.fn.bgscroll2 = jQuery.fn.bgScroll2 = function( options ) {
		
		if( !this.length ) return this;
		if( !options ) options = {};
		if( !window.scrollElements ) window.scrollElements = {};
		
		for( var i = 0; i < this.length; i++ ) {
			
			var allowedChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
			var randomId = '';
			for( var l = 0; l < 5; l++ ) randomId += allowedChars.charAt( Math.floor( Math.random() * allowedChars.length ) );
			
				this[ i ].current2 = 0;
				this[ i ].scrollSpeed = options.scrollSpeed ? options.scrollSpeed : 70;
				this[ i ].direction = options.direction ? options.direction : 'h';
				window.scrollElements[ randomId ] = this[ i ];
				
				eval( 'window[randomId]=function(){var axis=0;var e=window.scrollElements.' + randomId + ';e.current2 -= 1;if (e.direction == "h") axis = e.current2 + "px 0";else if (e.direction == "v") axis = "0 " + e.current2 + "px";else if (e.direction == "d") axis = e.current2 + "px " + e.current2 + "px";$( e ).css("background-position", axis);}' );
														 
				setInterval( 'window.' + randomId + '()', options.scrollSpeed ? options.scrollSpeed : 70 );
			}
			
			return this;
		}
})(jQuery);
	/********************/
	
	
	
	
    /*jQuery('#base_edificios').delay(5000).slideDown('slow');*/

	sizeContent();
	/*jQuery("#base_edificios").fadein("fast");*/
	/*jQuery("#base_edificios").animate({height:425},"slow");*/
	jQuery("#base_edificios").delay(3000).animate({"left": "-=2500px"}, "slow");
	
	
	/*******************************************/
	var totWidth=0;
	var positions = new Array();
	
	jQuery("#slides .slide").each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		positions[i]= totWidth;
		totWidth += jQuery(this).width();
		
		/* The positions array contains each slide's commulutative offset from the left part of the container */
		
		if(!jQuery(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
		
	});
	
	jQuery("#slides").width(totWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	jQuery("#nav ul li a").click(function(e,keepScroll){

			/* On a thumbnail click */

			jQuery("li.menuItem").removeClass("act").addClass("inact");
			jQuery(this).parent().addClass("act");
			
			var pos = jQuery(this).parent().prevAll(".menuItem").length;
			jQuery("#slides").stop().animate({marginLeft:-positions[pos]+"px"},450);
			/* Start the sliding animation */
			
			e.preventDefault();
			/* Prevent the default action of the link */
			
			
			// Stopping the auto-advance if an icon has been clicked:
			if(!keepScroll) clearInterval(itvl);
	});
	
	jQuery("#nav ul li.menuItem:first").addClass("act").siblings().addClass("inact");
	/* On page load, mark the first thumbnail as active */
	
	
	
	/*****
	 *
	 *	Enabling auto-advance.
	 *
	 ****/
	 
	var current=1;
	function autoAdvance()
	{
		if(current==-1) return false;
		
		jQuery("#nav ul li a").eq(current%jQuery("#nav ul li a").length).trigger("click",[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		current++;
	}

	// The number of seconds that the slider will auto-advance in:
	
	var changeEvery = 6;

	var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);

	/* End of customizations */

	
	/*******************************************/

	
});

function prev() {
	
	scrollContent(i-1);
	
	}

function sig() {
	
	scrollContent(i-1);
	
	}

function sizeContent() {
    theWidth = jQuery(window).width();
    /*theHeight = jQuery(window).height();*/
	theHeight = 550;
    sizeContentItems();
    setLeftOnContentItems();
    sizeContentWrapper(theWidth, theHeight);
    moveContent(currentContent, theWidth);
    changeSelected(currentContent);
}

function sizeContentItems() {
    jQuery(".contentItem").css('width', theWidth);
    jQuery(".contentItem").css('height', theHeight);

}

function setLeftOnContentItems() {
    var contentCount = 0;
    jQuery(".contentItem").each(function (i) {
        contentCount += i;
        jQuery(this).css('left', i * theWidth);
    });
}

function sizeContentWrapper(width, height) {
    jQuery("#contentWrapper").css('width', width);
    jQuery("#contentWrapper").css('height', height);
}

function moveContent(i, width) {
    jQuery("#contentWrapper").scrollLeft(i * width);
}

function changeSelected(i) {
    jQuery(".selected").removeClass("selected");
    jQuery("li:eq(" + i + ") a").addClass("selected");
}
function scrollContentNext() {
    scrollContent(currentContent + 1);
	
}

function scrollContent(i) {

    i = checkMax(i);
    scrollLogo(i);
	scrollSol();
    scrollNubes_1();
	scrollNubes_2();
	scrollNubes_3();
	Tren();
	setTimeout("Tren2()",15000);
    changeSelected(i)
	if( i == 1 ) {lucesPaso2();}
    currentContent = i;
    jQuery("#contentWrapper").animate({ scrollLeft: i * theWidth }, 1000);
	
	
}

function scrollLogo(i) {
    var left = (i * -200) + 20;
    jQuery("#logo").animate({ left: left }, 1000);
}

function scrollSol() {
	jQuery("#sol").animate({"left": "-=2px"}, "slow");
}



function lucesPaso2() {
    jQuery("#luces_1").show(1);
	jQuery("#luces_2").show(1);
    jQuery("#luces_3").show(1);
	}

function Tren() {
	
	jQuery("#tren").animate({"left": "-=850px"}, "slow");


	}
	

function Tren2() {
	
	jQuery("#tren2").animate({"left": "+=350px"}, "slow");


	}

function scrollNubes_1( ) {

   	jQuery("#nubes_1").animate({"left": "-=15px"}, "slow");
		

	if( parseInt(jQuery("#nubes_1").css("left")) == -475) {
		jQuery("#nubes_1").css("margin-left","2800px");
		}
	
	/*alert(nubes1_left);*/
}

function scrollNubes_2() {
   /* var left = (i * -50);
    jQuery("#nubes_2").animate({ left: left  }, 1000);*/
	jQuery("#nubes_2").animate({"left": "-=10px"}, "slow");
	
	if( parseInt(jQuery("#nubes_2").css("left")) == -2100) {
		jQuery("#nubes_2").css("margin-left","3100px");
		}
	
	
}

function scrollNubes_3() {
   /* var left = (i * -50);
    jQuery("#nubes_2").animate({ left: left  }, 1000);*/
	jQuery("#nubes_3").animate({"left": "-=15px"}, "slow");
	
	if( parseInt(jQuery("#nubes_3").css("left")) == -1100) {
		jQuery("#nubes_3").css("margin-left","3500px");
		}
}


function checkMax(i) {
    var maxItems = jQuery("li").length;
    if (i >= maxItems) {
        return 0;
    }
    return i;
}




/***************     PARALLAX SCROLLING         ******************/

 konami = new Konami()
	konami.code = function() {
		alert("You have entered the KONAMI CODE!  You now have 30 lives.  Kinda.")
		}

	konami.load()
	 

/**************     grande ***********/





