/* Author: Clicked Creative || http://www.clickedcreative.com */

jQuery(document).ready(function($){
	
        Cufon.replace('h2#heading');
	Cufon.replace('#mainNav a', {hover: true});
	Cufon.replace('.secondary_nav ul li a', {hover: true});
        Cufon.replace('.secondary_nav_grades ul li a', {hover: true});
        Cufon.replace('#leftContent .footer_bar', {hover: true});
        
	stackFlip = setInterval("animatePolaroid()", 2000);
	$('.polaroid a').live('click', function(){
		clearInterval(stackFlip);
	});
	

});


function animatePolaroid(){
	
	// Stick a copy of the 'top' picture at the bottom of the stack		
	$('.polaroid:last-child').clone().prependTo('#stack_wrapper');
	
	leftShift = 800;
	
	M = -500;
	N = 500;
	topShift = Math.floor(M + (1+N-M)*Math.random());
	
	if ($("html").hasClass("oldie"))
	{	
		// Animate the 'top' polaroid off the page
		$('.polaroid:last-child').animate({
			rotate: '-=270deg',
			left: -leftShift,
			top: topShift
			}, 1000, function() {
				// Animation complete callback
				$(this).remove();
		});
	}
	else
	{	
		
		// Animate the 'top' polaroid off the page
		$('.polaroid:last-child').animate({
			rotate: '-=270deg',
			opacity: 0.7,
			left: -leftShift,
			top: topShift
			}, 1000, function() {
				// Animation complete callback
				$(this).remove();
		});
	}
}
