
/*
	Author: BDQWorks/BDQThemes/Jason Saeho Lee
	Version: 1.0.1
	Updated: May 20th, 2011
*/

	$(window).bind("load", function() {
		autoRotate=setInterval("rotateImages()", 8000);
		
		sparkle();
	});
	
	function rotateImages(){
		    
			$went = false;
			$id = $("#slideshow .cur").attr("class");
			$max = 29;
			var slide = new Array("aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk","ll","mm","nn","oo","pp","qq","rr","ss","tt","uu","vv","ww","xx","yy","zz","aaa","bbb", "ccc");
			$(".slide").show();
			
			for ($i = 0; $i < $max; $i++) {
				
			  if ($id==slide[$i]+' slide cur' && $went==false) {
				$off = $i - 1;
				$on  = $i + 1;  
				
				if ($off < 0)
				  $off = $max-1;
				
				if ($on == $max)
				  $on = 0;
				
				for ($z = 0; $z < $max; $z++) {
				  if ($z==$on || $z==$i)
				    $("."+slide[$z]).css({opacity:1.0});
				  else
					$("."+slide[$z]).css({opacity:0.0});  
				}
			  
				$on = $on+1;
					
			  $("."+slide[$i]).stop().animate({opacity:0.0}, {duration:500, complete: function() {
				  for ($x = 1; $x <= $max; $x++) {
				    if ($x==$on)
					  $("#featured"+$x).removeClass('prev').addClass('cur');
					else
				  	  $("#featured"+$x).removeClass('cur').addClass('prev');
				  }
			    }
			  });
			  	
			  $("#second_bg").fadeOut(550, function() { 
			    for ($y = 1; $y <= $max; $y++) {
				  if ($y==$on)
				    $("#second_bg").addClass('slideshow-bg-'+$y);
				  else
				    $("#second_bg").removeClass('slideshow-bg-'+$y);
				}
				
				$("#second_bg").fadeIn(200);
			  });
			  
			  $went = true;
			  }
			}
			
			
		};
		
