bQuery(document).ready(function(){
	
	bQuery("ul.navigation-top-ul").superfish();
	bQuery("ul.navigation-top-ul ul li:first-child a").addClass("no-top-border");
	bQuery("ul.navigation-top-ul ul li:last-child a").addClass("no-bottom-border");
	
	bQuery("a[rel^='prettyPhoto']").prettyPhoto();
	
	// Portfolio Hover Sliders
	bQuery("#featured").hover(function(){
		bQuery(this).find(".top-slide").animate({top:"0"},{queue:false,duration:350,easing:'easeOutExpo'});
		bQuery(this).find(".bottom-slide").animate({bottom:"0"},{queue:false,duration:350,easing:'easeOutExpo'});
		bQuery(this).find(".arrow-left").animate({left:"0"},{queue:false,duration:350,easing:'easeOutExpo'});
		bQuery(this).find(".arrow-right").animate({right:"0"},{queue:false,duration:350,easing:'easeOutExpo'});
	}, function(){
		bQuery(this).find(".top-slide").animate({top:"-70px"},{queue:false,duration:350,easing:'easeOutExpo'});
		bQuery(this).find(".bottom-slide").animate({bottom:"-66px"},{queue:false,duration:350,easing:'easeOutExpo'});
		bQuery(this).find(".arrow-left").animate({left:"-50px"},{queue:false,duration:350,easing:'easeOutExpo'});
		bQuery(this).find(".arrow-right").animate({right:"-50px"},{queue:false,duration:350,easing:'easeOutExpo'});
	});
	
	// Portfolio Page Arrows
	var currentFeatureSlide = 1;
	var currentFeatureLocation = 0;
	bQuery("a.arrow-left").fadeTo(0,0.2);
	
	var totalFeatureSlides = Math.ceil( (bQuery(".featured-entry > div").size()) );
	var animationOn = false;
	
	bQuery("a.arrow-right").click(function(event){
    
		if (currentFeatureSlide != totalFeatureSlides) {
				
			if (currentFeatureSlide == 1) { bQuery("a.arrow-left").fadeTo(300,0.75); }
			newFeatureLocation = (currentFeatureLocation + 920);
			
			bQuery(".featured-entry").animate({left:"-"+newFeatureLocation},{queue:false,duration:450,easing:'easeInOutExpo'});
			currentFeatureSlide++;
			if (currentFeatureSlide == totalFeatureSlides) {
				bQuery("a.arrow-right").fadeTo(300,0.2); }
			currentFeatureLocation = newFeatureLocation;
			bQuery(".slide-page").removeClass("active");
			bQuery("#slide-page_"+currentFeatureSlide).addClass("active");
		  
		  // Reset timer
		  dotimer();
		  
		}
		
	});
    
	bQuery("a.arrow-left").click(function(event){
				   
		if (currentFeatureSlide != 1) {
			
			if (currentFeatureSlide == totalFeatureSlides) {
				bQuery("a.arrow-right").fadeTo(300,0.75); }
				
			newFeatureLocation = (currentFeatureLocation - 920);
			
			if (currentFeatureSlide > 2) {
				newFeatureLocationNum = "-"+newFeatureLocation; } else {
				newFeatureLocationNum = newFeatureLocation; }
			bQuery(".featured-entry").animate({left:newFeatureLocationNum},{queue:false,duration:450,easing:'easeInOutExpo'});
			currentFeatureSlide--;
			if (currentFeatureSlide == 1) {
				bQuery("a.arrow-left").fadeTo(300,0.2); }
			currentFeatureLocation = newFeatureLocation;
			bQuery(".slide-page").removeClass("active");
			bQuery("#slide-page_"+currentFeatureSlide).addClass("active");
			
			// Reset timer
			dotimer();
				
		}
		
	});
	
	bQuery("a.slide-page").hoverIntent(function(){
		bQuery(this).find("span").show();
		bQuery(this).find("span").animate({opacity:1,top:"-69px"},120);
	}, function() { 
		bQuery(this).find("span").animate({opacity:0,top:"-64px"},0);
		bQuery(this).find("span").hide();
	});
	
	bQuery("a.slide-page").click(function(event){
		gotoPage = this.id;
		gotoPage = gotoPage.split("_");
		actualPage = gotoPage[1] - 1;
		currentFeatureLocation = actualPage * 920;
		
		bQuery(".featured-entry").animate({left:"-"+currentFeatureLocation},{queue:false,duration:450,easing:'easeInOutExpo'});
		currentFeatureSlide = gotoPage[1];
		
		if (currentFeatureSlide == totalFeatureSlides) { bQuery("a.arrow-right").fadeTo(300,0.2); }
		if (currentFeatureSlide < totalFeatureSlides) { bQuery("a.arrow-right").fadeTo(300,0.65); }
		
		if (currentFeatureSlide == 1) { bQuery("a.arrow-left").fadeTo(300,0.2); }
		if (currentFeatureSlide > 1) { bQuery("a.arrow-left").fadeTo(300,0.65); }
		
		bQuery(".slide-page").removeClass("active");
		bQuery("#slide-page_"+currentFeatureSlide).addClass("active");
		
		// Reset timer
		dotimer();
	
	});
	
	
	/* Options on Hover (Gallery Links) */
	bQuery(".gallery-thumb").hoverIntent(function(){
	
		bQuery(this).find(".optionsOnHover").fadeIn("fast");
	
	}, function() {
		
		bQuery(this).find(".optionsOnHover").fadeOut("fast");
		
	});
	
	// START ROTATE CODE
	
	var timer;
	
  var donext = function (x){
    
    if (currentFeatureSlide != totalFeatureSlides) {
				
			if (currentFeatureSlide == 1) { bQuery("a.arrow-left").fadeTo(300,0.75); }
			newFeatureLocation = (currentFeatureLocation + 920);
			
			bQuery(".featured-entry").animate({left:"-"+newFeatureLocation},{queue:false,duration:450,easing:'easeInOutExpo'});
			currentFeatureSlide++;
			if (currentFeatureSlide == totalFeatureSlides) {
				bQuery("a.arrow-right").fadeTo(300,0.2); }
			currentFeatureLocation = newFeatureLocation;
			bQuery(".slide-page").removeClass("active");
			bQuery("#slide-page_"+currentFeatureSlide).addClass("active");
				
		} else if (currentFeatureSlide == totalFeatureSlides) {
		  
		  //alert("last");
		  
		  bQuery("a.arrow-right").fadeTo(300,0.75);
		  bQuery("a.arrow-left").fadeTo(300,0.2);
		  
		  newFeatureLocation = 0;
		  
		  bQuery(".featured-entry").animate({left:0},{queue:false,duration:450,easing:'easeInOutExpo'});
		  currentFeatureSlide = 1;
		  
		  currentFeatureLocation = newFeatureLocation;
		  
		  bQuery(".slide-page").removeClass("active");
			bQuery("#slide-page_"+currentFeatureSlide).addClass("active");
		
		}
    
  } 
  
  var dotimer = function (){
    if(timer != null) {
      clearInterval(timer);
    }
  
    timer = setInterval(function() {
      donext();
    }, 6000); // Change the time in between rotations here (in milliseconds)
                  
  }
  dotimer();
	
	
	
});