//////////////////////////////////////////////////////////////
// Set Variables
/////////////////////////////////////////////////////////////

var transitionSpeed = 500;
var scrollSpeed = 500;
var fadeDelay = 100;
var currentProject = "";
var nextProject = "";

//////////////////////////////////////////////////////////////
// Functions
/////////////////////////////////////////////////////////////

function getProject(project) {	
	return jQuery("#project-"+project);
}

function getProjectLink(project) {
	return jQuery("#thumb-"+project+" a");
}

function showHashProject(project, animate) {	
	
	
	
	nextProject = getProject(project);	

	if (!getProjectLink(project).hasClass("selected")) {		
		
		
		// Fade in the next project
		nextProject.delay(fadeDelay).fadeIn(transitionSpeed);
		
		// Add the selected class to the thumbnail
		jQuery(".projectThumbs a.selected").removeClass("selected");
		getProjectLink(project).addClass("selected");
		section = getProjectLink(project).attr("class").split(' ')[0];
		
		// Adjust the height of project container
		jQuery("#"+section+" .projects").animate({
			height: nextProject.outerHeight()
		}, scrollSpeed );				
	}
	
	// Scroll to the top of the projects
	jQuery.scrollTo("#"+section+" .projects", scrollSpeed, { offset:0 });
}

function showProject(section, project, animate) {	
	
	if (jQuery("#"+section+" .projectThumbs a.selected").attr("href")) {
		currentProject = getProject(jQuery("#"+section+" .projectThumbs a.selected").attr("href").replace("\#",""));		
	}	
	nextProject = getProject(project);	

	if (!getProjectLink(project).hasClass("selected")) {
				
		// Fade out the current project
		if (currentProject) {currentProject.fadeOut(transitionSpeed);}
		jQuery("#"+section+" .projects").animate({
			height:0
		}, scrollSpeed );				
		
		// Fade in the next project
		nextProject.delay(fadeDelay).fadeIn(transitionSpeed);
		
		// Add the selected class to the thumbnail
		jQuery("#"+section+" .projectThumbs a.selected").removeClass("selected");
		getProjectLink(project).addClass("selected");
		
		// Adjust the height of project container
		jQuery("#"+section+" .projects").animate({
			height: nextProject.outerHeight()
		}, scrollSpeed );				
	}
	
	// Scroll to the top of the projects
	jQuery.scrollTo("#"+section+" .projects", scrollSpeed, { offset:-100, axis:'y' });
	jQuery("#header").css("z-index", "999");
	jQuery(".projects").css("z-index", "1");
}

function hideProject(section) {
	currentProject = getProject(jQuery("#"+section+" .projectThumbs a.selected").attr("href").replace("\#",""));		
	
	// Fade out the current project
	currentProject.fadeOut(transitionSpeed);
	
	// Remove the selected class from thumbnail
	jQuery("#"+section+" .projectThumbs a.selected").removeClass("selected");
	
	// Close the project container
	jQuery("#"+section+" .projects").delay(fadeDelay).animate({
		height: 0
	}, transitionSpeed );	
}

function createProjectSlider() {
	jQuery(".projectThumbs a").each(function(){
		var project = jQuery(this).attr("href").replace("\#","");	
		var autoSlide = true;
		if(project == 'tv-video'){
			autoSlide = false;
		}

		jQuery(".slideshow", getProject(project)).easySlider({
			speed: transitionSpeed,
			project: project,
			continuous: true,
			numeric: true,
			auto: autoSlide,
			pause: 6000,
			vertical: 'true',
			numericId: 'controls-'+project,
			controlsBefore: '<div class="slideshowControls clearfix">',
			controlsAfter: '</div>',
			prevID: 'prevBtn',
			nextID: 'nextBtn',
			prevText: '',
			nextText: ''
			
			

		});
	});
}

function createCloseProjectButton() {	
	jQuery(".closeBtn").click(function() {
		hideProject(jQuery(this).attr("class").split(' ')[0]);
	});
}


//////////////////////////////////////////////////////////////
// Initialize
/////////////////////////////////////////////////////////////


jQuery.noConflict();
jQuery(document).ready(function(){	
	
	// Rename project ids
	jQuery(".projectDetails").each(function(){
		jQuery(this).attr("id","project-"+jQuery(this).attr("id"));
	});

	// Add click events to project thumbnails
	jQuery(".projectThumbs a").click(function() {		
		showProject(jQuery(this).attr("class"), jQuery(this).attr("href").replace("\#",""));
	});
	
	// Call inititial functions
	createCloseProjectButton();	
	createProjectSlider();

	// Show project is there is a hash in the URL
	var project = location.hash.replace("\#","");
	if (getProject(project).length) {
		showHashProject(project, true);
	}
	
	
	
	
	
	jQuery("#main-slideshow").easySlider({
			speed: transitionSpeed,
			continuous: true,
			numeric: true,
			auto: true,
			pause: 6000,
			vertical: 'true',
			controlsBefore: '<div class="slideshowControlsTop">',
			controlsAfter: '</div>',
			controlsShow: false,
			prevID: 'prevBtn',
			nextID: 'nextBtn',
			prevText: '',
			nextText: ''
		});
	
	
	
});



















        jQuery(function() {
            var offset = jQuery("#header").offset();
            var topPadding = 288;
            jQuery(window).scroll(function() {
                if (jQuery(window).scrollTop() > (offset.top -288)) {
                    jQuery("#header").stop().animate({
                        marginTop: jQuery(window).scrollTop() - offset.top + topPadding
                    });
                } else {
                    jQuery("#header").stop().animate({
                        marginTop: 0
                    });
                };
            });
        });
		

        jQuery(function() {
			jQuery(".soloSection").css("min-height", (jQuery(window).height() -100));
			jQuery("#homeMessage").css("min-height", (jQuery(window).height() -560));
			jQuery("#home").css("min-height", (jQuery(window).height() -100));
			
        });
		
		
		jQuery(function() {
			jQuery(window).resize(function(){
				jQuery(".soloSection").css("min-height", (jQuery(window).height() -100));
				jQuery("#homeMessage").css("min-height", (jQuery(window).height() -560));
				
				jQuery(".projects .inside").css("margin-left", -((jQuery(window).width() -920)/2)-160);
				jQuery(".projects .inside").css("margin-right", -((jQuery(window).width() -920)/2));
				
				jQuery(".projects .inside").css("padding-left", ((jQuery(window).width() -920)/2));
				jQuery(".projects .inside").css("padding-right", ((jQuery(window).width() -920)/2));
																					 
			});
			
        });
		
		
		
		
		
		
		
		
		
		
		
jQuery(document).ready(function(){	
								
	
	
	
	jQuery('.profile .control').click(function(){
		if(jQuery(this).parent().parent().hasClass('opened')){
			jQuery(this).parent().siblings('.profile-content').animate({height: 65}, 500);		
			jQuery(this).parent().parent().removeClass('opened');	
		}
		else{
			jQuery(this).parent().siblings('.profile-content').animate({height: 300}, 500);		
			jQuery(this).parent().parent().addClass('opened');	
		}
	});
	
	jQuery("#mainNav a:hover").css({'color': '#6d4c3d', backgroundPosition: '-1500px'});
	jQuery('#mainNav a').not('.selected')
        .css( {backgroundPosition: "-1500px 0"} )
        .mouseover(function(){
            jQuery(this).stop().animate({backgroundPosition:"(100px 0)"}, {duration:500, complete:function(){
				jQuery(this).css({'color': "#ffffff"})																							   
			}})
        })
        .mouseout(function(){
			jQuery(this).css({'color': "#6d4c3d"});
            jQuery(this).stop().animate({backgroundPosition:"(-1500px 0)"}, {duration:400, complete:function(){
                jQuery(this).css({backgroundPosition: "-1500px 0"});			
            }})
        });
	
	jQuery(".projects .inside").css("margin-left", -((jQuery(window).width() -920)/2)-160);
				jQuery(".projects .inside").css("margin-right", -((jQuery(window).width() -920)/2));
				
				jQuery(".projects .inside").css("padding-left", ((jQuery(window).width() -920)/2));
				jQuery(".projects .inside").css("padding-right", ((jQuery(window).width() -920)/2));
});
