/*
Fancy Folio
Created: 15/10/2009
By: Catalin Pinte
Contact Info: pinte_catalin@yahoo.com
*/
var slideShow = function() {
   var $start,
       $stop;
   return {
	    $start : function(){  $start = setInterval("Slide_Show()", 3000 /* slide durration miliseconds */); },  
        $stop : function(){
		   clearInterval($start);
		}
   }
}();

if(!$.cookie){ 
       slideShow.$start();
}else{
	if($.cookie('FancyFolio - slideshow') == "stop"){ 
        $(".play").show(); $(".stop").hide();
     } else { 
	    slideShow.$start();	 // this starts slideshow		
     }
}

Slide_Show();
var $timeout;
$("#recent_area ul li a").click(function(){
		    clearTimeout($timeout);
			if($.cookie('FancyFolio - slideshow') != "stop"){ 
			    slideShow.$stop(); // stops slideshow because user selected a project
			    $timeout = setTimeout(function(){ slideShow.$start(); }, 4000); // continue  slideshow after 5 seconds
			}
            Change_Slide($(this).parent());
			return false;
			
	});

$("#project_controller .play").click(function(){
	  slideShow.$start();	
	  Slide_Show();
	  $(".stop").show();
	  $(".play").hide();
	  $.cookie('FancyFolio - slideshow', "start" ,{ expires: 30, path: '/' });

});

$("#project_controller .stop").click(function(){
      slideShow.$stop();
	  $(".play").show();
	  $(".stop").hide();
	  $.cookie('FancyFolio - slideshow', "stop" ,{ expires: 30, path: '/' });
});


//this is slide_show function 
function Slide_Show(){
			var $active = $('#recent_area li.active');
			if ($active.length == 0) $active = $('#recent_area li:last');
			var $next =  $active.next("li").length ? $active.next("li")
			: $('#recent_area li:first');   
			$active.removeClass("active");
		    Change_Slide($next);
}

//this changes slide image
function Change_Slide($element){
		  $("#recent_area li.active").removeClass("active");
		  $element.addClass('active');
	      $("#project img").fadeOut(1000); // fadeOut speed
		  $("#project_id").text($element.attr("title"));
          $("#p_details").attr("href", $element.find("a").attr("href") ); //$element.find("a").attr("href")
		  $element.find("img").clone().appendTo("#project").fadeIn(1200 /* fadeIn speed */, function(){$(this).prev().remove(); });
		  $("#recent_area ul li a").attr("style","text-decoration:none");
		  $element.find("a").attr("style","text-shadow: 1px 1px 5px  white; text-decoration:underline;");
}
