$j(document).ready(function(){
	
	$j("a[rel^='prettyPhoto']").prettyPhoto({
		animation_speed: 'normal', /* fast/slow/normal */
		opacity: 0.35, /* Value between 0 and 1 */
		allow_resize: true, /* Resize the photos bigger than viewport. true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'facebook' , /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		gallery_markup:'', /* hide minigallery. Delete this string if need to show minigallery */
		changepicturecallback:function(){
			clearInterval(timer)
		},
		callback:function(){
			dotimer()
		}
	});
	
		
	// Portfolio Hover Sliders
	$j("#featured").hover(function(){
		if (autoRotate == 1){ clearInterval(timer); }
		$j(this).find(".top-slide").animate({top:"0"},{queue:false,duration:350,easing:'easeOutExpo'});
		$j(this).find(".bottom-slide").animate({bottom:"0px"},{queue:false,duration:350,easing:'easeOutExpo'});
		$j(this).find(".arrow-left").animate({left:"406px"},{queue:false,duration:350,easing:'easeOutExpo'});
		$j(this).find(".arrow-right").animate({right:"416px"},{queue:false,duration:350,easing:'easeOutExpo'});
	}, function(){
		if (autoRotate == 1){ dotimer(); }
		$j(this).find(".top-slide").animate({top:"-399px"},{queue:false,duration:350,easing:'easeOutExpo'});
		$j(this).find(".bottom-slide").animate({bottom:"-43px"},{queue:false,duration:350,easing:'easeOutExpo'});
		$j(this).find(".arrow-left").animate({left:"-13px"},{queue:false,duration:350,easing:'easeOutExpo'});
		$j(this).find(".arrow-right").animate({right:"-13px"},{queue:false,duration:350,easing:'easeOutExpo'});
	});
	
	// Portfolio Page Arrows
	var currentFeatureSlide = 1;
	var currentFeatureLocation = 0;
	$j("a.arrow-left").fadeTo(0,0.2);
	
	var totalFeatureSlides = Math.ceil( ($j(".featured-entry > div").size()) );
	var animationOn = false;
	
	$j("a.arrow-right").click(function(event){
									 
		if (currentFeatureSlide != totalFeatureSlides) {
				
			if (currentFeatureSlide == 1) { $j("a.arrow-left").fadeTo(300,1); }
			newFeatureLocation = (currentFeatureLocation + 908);
			
			$j(".featured-entry").animate({left:"-"+newFeatureLocation},{queue:false,duration:450,easing:'easeInOutExpo'});
			currentFeatureSlide++;
			if (currentFeatureSlide == totalFeatureSlides) {
				$j("a.arrow-right").fadeTo(300,0.2); }
			currentFeatureLocation = newFeatureLocation;
			$j(".slide-page").removeClass("active");
			$j("#slide-page_"+currentFeatureSlide).addClass("active");
				
		}
		
	});
	
	$j("a.arrow-left").click(function(event){
								   
		if (currentFeatureSlide != 1) {
			
			if (currentFeatureSlide == totalFeatureSlides) {
				$j("a.arrow-right").fadeTo(300,1); }
				
			newFeatureLocation = (currentFeatureLocation - 908);
			
			if (currentFeatureSlide > 2) {
				newFeatureLocationNum = "-"+newFeatureLocation; } else {
				newFeatureLocationNum = newFeatureLocation; }
			$j(".featured-entry").animate({left:newFeatureLocationNum},{queue:false,duration:450,easing:'easeInOutExpo'});
			currentFeatureSlide--;
			if (currentFeatureSlide == 1) {
				$j("a.arrow-left").fadeTo(300,0.2); }
			currentFeatureLocation = newFeatureLocation;
			$j(".slide-page").removeClass("active");
			$j("#slide-page_"+currentFeatureSlide).addClass("active");
				
		}
		
	});
	
	
	
	
	if (autoRotate == 1){	
		// START ROTATE CODE
		var timer;
	  	var donext = function (x){
	    
		    if (currentFeatureSlide != totalFeatureSlides) {
		    
		    	if (currentFeatureSlide == 1) { $j("a.arrow-left").fadeTo(300,1); }
				newFeatureLocation = (currentFeatureLocation + 908);
				
				$j(".featured-entry").animate({left:"-"+newFeatureLocation},{queue:false,duration:450,easing:'easeInOutExpo'});
				currentFeatureSlide++;
				if (currentFeatureSlide == totalFeatureSlides) {
					$j("a.arrow-right").fadeTo(300,0.2); }
				currentFeatureLocation = newFeatureLocation;
				$j(".slide-page").removeClass("active");
				$j("#slide-page_"+currentFeatureSlide).addClass("active");
						
			} else if (currentFeatureSlide == totalFeatureSlides) {
				
				$j("a.arrow-right").fadeTo(300,1);
				$j("a.arrow-left").fadeTo(300,0.2);
				
				newFeatureLocation = 0;
				
				$j(".featured-entry").animate({left:0},{queue:false,duration:450,easing:'easeInOutExpo'});
				currentFeatureSlide = 1;
				
				currentFeatureLocation = newFeatureLocation;
			  
			  	$j(".slide-page").removeClass("active");
				$j("#slide-page_"+currentFeatureSlide).addClass("active");
			
			}
		} 
	  
	  	var dotimer = function (){
	    	if(timer != null) {
	     		clearInterval(timer);
	    	}
	  
	    	timer = setInterval(function() {
	      		donext();
	    	}, 4500); // Change the time in between rotations here (in milliseconds)
	                  
		}
	  
	  	dotimer();
  	}
	
});
