 /* -----------------------------HOMEPAGE SLIDER FUNCTIONALITY------------------------ */
 
 $(document).ready(function(){
	
	var totWidth=0;
	var positions = new Array();
	
	$('#slides .slide').each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		positions[i]= totWidth;
		totWidth += $(this).width();
		
		/* The positions array contains each slide's commulutative offset from the left part of the container */
		
		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
		
	});
	
	$('#slides').width(totWidth);

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

	$('#menu ul li a').click(function(e,keepScroll){

			/* On a thumbnail click */

			$('li.menuItem').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');
			
			var pos = $(this).parent().prevAll('.menuItem').length;
			
			$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},850);
			/* 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);
	});
	
	$('#menu 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;
		
		$('#menu ul li a').eq(current%$('#menu 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 = 7;

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

	/* End of customizations */
});


/* -----------------------------CRYSTALS MOVEMENT/CIRCULATE------------------------ */

$(window).load(function() {

    function startBallOne() {
        $("#sparkle1").circulate({
            speed: 1000,
            height: 10,
            width: 10,
            sizeAdjustment: 80,
            loop: true,
            zIndexValues: [1, 1, 3, 3]
        });
    }
    
    function startBallTwo() {
        $("#sparkle2").circulate({
            speed: 1500,
            height: 20,
            width: 30,
            sizeAdjustment: 65,
            loop: true,
            zIndexValues: [2, 2, 2, 2]
        })
    }
    
    function startBallThree() {
        $("#sparkle3").circulate({
            speed: 2000,
            height: 15,
            width: 0,
            sizeAdjustment: 80,
            loop: true,
            zIndexValues: [3, 3, 1, 1]
        }).fadeIn();
    }
	
	function startBallFour() {
        $("#sparkle4").circulate({
            speed: 1000,
            height: 10,
            width: 0,
            sizeAdjustment: 70,
            loop: true,
            zIndexValues: [3, 3, 1, 1]
        }).fadeIn();
    }
            
    startBallOne();
    setTimeout(startBallTwo, 00);
    setTimeout(startBallThree, 500);
	setTimeout(startBallFour, 00);
	});
	
/* -----------------------------ZOUT BOUNCE------------------------ */
	$(window).load(function() {
	$.fn.cycle.defaults.timeout = 3500;
$(function() {
    // run the code in the markup!
    $('#zout').each(function() {
        eval($(this).text());
    });
});
   $('#s1').cycle({
    fx:      'zoom',
    speedIn:  1500,
    speedOut: 300,
    easeIn:  'bounceout',
    easeOut: 'easein',
    sync:     1,    
    delay:   -1000, 
	cleartypeNoBg: true
});
});

/* -----------------------------HE FUSION BOUNCE------------------------ */
	$(window).load(function() {
	$.fn.cycle.defaults.timeout = 3500;
$(function() {
    // run the code in the markup!
    $('#fusion').each(function() {
        eval($(this).text());
    });
});
   $('#s2').cycle({
    fx:      'zoom',
    speedIn:  1500,
    speedOut: 300,
    easeIn:  'bounceout',
    easeOut: 'easein',
    sync:     1,    
    delay:   -1000, 
	cleartypeNoBg: true
});
});

/* -----------------------------Earthday BOUNCE------------------------ */
	$(window).load(function() {
	$.fn.cycle.defaults.timeout = 3500;
$(function() {
    // run the code in the markup!
    $('#fusion').each(function() {
        eval($(this).text());
    });
});
   $('#s3').cycle({
    fx:      'zoom',
    speedIn:  1500,
    speedOut: 300,
    easeIn:  'bounceout',
    easeOut: 'easein',
    sync:     1,    
    delay:   -1000, 
	cleartypeNoBg: true
});
});


/* -----------------------------3-IN-1 SCROLL/GLISTEN/SHIMMER------------------------ */

var scrollSpeed = 1;       // Speed in milliseconds
var step = 4;               // How many pixels to move per step
var current = 0;            // The current pixel row
var imageHeight = 2000;     // Background image height
var headerHeight = 500;     // How tall the header is.

//The pixel row where to start a new loop
var restartPosition = -(imageHeight - headerHeight);

function scrollBg(){
   
    //Go to next pixel row.
    current -= step;
   
    //If at the end of the image, then go to the top.
    if (current == restartPosition){
        current = 0;
    }
   
    //Set the CSS of the header.
    $('.shine').css("background-position","0 "+current+"px");
   
   
}

//Calls the scrolling function repeatedly
var init = setInterval("scrollBg()", scrollSpeed);
/* Enzymes */

	/* $("#enzyme-green").css("left", $("#enzyme-green").position().left).circulate({
            speed: 1800,
            width: -290,
            height: 180,
            loop: true,
			enableTrail:true,
            zIndexValues: [1, 50, 50, 1],
			howManyFramesToSkip:10
    });
	
	 $("#enzyme-purple").css("left", $("#enzyme-purple").position().left).circulate({
            speed: 1200,
            width: -290,
            height: 220,
            loop: true,
			enableTrail:true,
            zIndexValues: [1, 60, 60, 1],
			howManyFramesToSkip:10
    });
	
	$("#enzyme-yellow").css("left", $("#enzyme-yellow").position().left).circulate({
            speed: 1500,
            width: -290,
            height: 210,
            loop: true,
			enableTrail:true,
            zIndexValues: [1, 60, 60, 1],
			howManyFramesToSkip:10
    });*/
    

