(function(jQuery) {

jQuery(function(){
		   
	//Remove previous arrow
	jQuery('#previous').css('display','none');

	//Click either previous or next
	var count = 0;
	var limit = jQuery(".contentContainer").size() - 1;
	var nextDisplayed = true;
	var previousDisplayed = false;
	
	//Admin Control
	var adminDisplayed = 00;
	
	//Set document to be in the middle
	var windowHeight = jQuery(window).height(); 

	//Set top value of content
	if(windowHeight <= 700){	
		jQuery('.header').css("padding-top","0px");
		
	}else if((windowHeight > 700) && (windowHeight <= 900)){	
		jQuery('.header').css("padding-top","60px");
		
	}else if(windowHeight > 900){	
		jQuery('.header').css("padding-top","80px");
	}


	//Instantiate slideshow
	jQuery('.slideshowContainer').cycle({ fx:'scrollHorz', timeout:0, speed:500, startingSlide:0 });
	jQuery('.portfolioVisual').cycle({ fx:'fade', timeout:0, speed:500});
	
	
	
	//Portfolio View Slideshow
	var currentWork = "view1";

	//Portfolio and Branding Control
	jQuery('.portfolioViews a').click(function(e){
											   
		//Prevent anchor action									   
		e.preventDefault();		
		
		//Obtain ID of link
		var id = jQuery(this).attr('id');	
	
		//If the selected view doesn't equal the current view
		if(id != currentWork){
			
			//Remove the existing class 'active' and add it on the selected view
			jQuery('.portfolioInfoPanel' + count + ' #' + currentWork).removeClass('active');
			jQuery('.portfolioInfoPanel' + count + ' #' + id).addClass('active');
			
			//Swap the display none class
			jQuery('.slide' + count + ' a#' + currentWork).addClass('importantDisplayNone');
			jQuery('.slide' + count + ' a#' + id).removeClass('importantDisplayNone');
		
			//Get the cycle ID and cycle to it
			var cycleNumber = id.split("view"); 
			var slideToDisplay = cycleNumber[1] - 1;
			jQuery('.portfolioSlideshowContainer' + count).cycle(slideToDisplay);
			
			currentWork = id;
		}
	});


	

	//Page Control - Slide through pages
	jQuery('.jqueryControl a').click(function(e){
		
		e.preventDefault();
		
		//Find value of id
		var id = jQuery(this).attr('id');
		
		//Set the current work back to view1
		if(currentWork != 'view1'){
			jQuery('.portfolioInfoPanel' + count + ' #' + currentWork).removeClass('active');
			jQuery('.portfolioInfoPanel' + count + ' #view1').addClass('active');
			jQuery('.slide' + count + ' a#view1').removeClass('importantDisplayNone');
			jQuery('.slide' + count + ' a#' + currentWork).addClass('importantDisplayNone');				
			jQuery('.portfolioSlideshowContainer' + count).cycle(0);
		}		
		currentWork = "view1";		
		
		//Next
		if(id == 'next'){
			
			//Prevent if reached the end
			if(count < limit){	count++; jQuery('.slideshowContainer').cycle(count); jQuery('.jqueryControl a#previous').fadeIn(); }
			
			//Hide next if at the end
			if(count == limit){ jQuery('.jqueryControl a#next').fadeOut(); }
			
		//Previous
		}else{
			
			//Prevent less than 0
			if(count > 0){ count--; jQuery('.slideshowContainer').cycle(count); jQuery('.jqueryControl a#next').fadeIn();	}
			
			//Hide previous at the start
			if(count == 0){	jQuery('.jqueryControl a#previous').fadeOut(); }
		}
	});
	
	
	// Admin Control
	jQuery('a.adminLink').click(function(e){
		e.preventDefault();

		var id = jQuery(this).attr('id');
		var completed = false;

		if((id != adminDisplayed) && (completed == false)){
			if(adminDisplayed != 00){ jQuery('.adminArticle' + adminDisplayed).slideUp("slow"); }
			jQuery('.adminArticle' + id).slideDown("slow");		
			adminDisplayed = id;
			completed = true;
		}
		
		if((id == adminDisplayed) && (completed == false)){ jQuery('.adminArticle' + adminDisplayed).slideUp("slow"); completed = true;	}
	});	
});

})(jQuery);
