$(document).ready(function() {
	
	// Initialize menu items ----->
	
	$(".menu-sub").hide(); // Hide sub menu items
	$(".menu-sub.current").show(); // Show sub menu items that are selected
		
	// Show/hide sub menu items ----->
	
	$(".menu-column").hover(
		function() {
			$(this).children(".menu-sub").show();
			$(this).children(".menu-sub, .menu-header").addClass("active"); // Add "active" class to selected item
		},
		function() {
			$(this).children(".menu-sub").hide();
			$(this).children(".menu-sub, .menu-header").removeClass("active"); // Remove "active" class to selected item
			$(this).children(".menu-sub.current").show();
		}
	);
	
	// Search ----->
	
	$("#search input").hover(
		function() {
			$(this).addClass("focus");
		},
		function() {
			$(this).removeClass("focus");
		}
	);
	
	$("#search input").focus(function(){	
		if($(this).val() == 'Search'){
			$(this).val('');
		}
		$(this).addClass("focus");
	});

	$("#search input").blur(function(){
		if($(this).val() == ''){
			$(this).val('Search');
		}
		$(this).removeClass("focus");
	});
	
	// Homepage slideshow ----->
	
	var countHome = $("#slideshow-homepage .slide").length; // Count number of slides to start at random position
	
	$('.slide-caption').hide(); // Hide all slide captions
	
	$('#slideshow-homepage').cycle({ 
		fx: 'fade',
		speed: 1000,
		timeout: 20000,
		startingSlide: Math.floor(Math.random()*countHome),
		next: '#arrows .next', 
		prev: '#arrows .prev',
		after: function(curr,next,opts) {
			$('#slide-caption-container').each(function(){
				currCaption = $(this).children();
			});
			$('.slide-caption').hide();
			$(currCaption[opts.currSlide]).show();
		}
	});
			
	// Category slideshow ----->
	
	var countCat = $("#slideshow-category .slide").length; // Count number of slides to start at random position
	
	$('#slideshow-category').cycle({ 
		fx: 'fade',
		speed: 1000,
		timeout: 20000,
		startingSlide: Math.floor(Math.random()*countCat),
		next: '#arrows .next', 
		prev: '#arrows .prev',
		after: function(curr,next,opts) {
			$('#category-projects').each(function(){
				currProject = $(this).children();
			});
			$('.project').removeClass('active');
			$(currProject[opts.currSlide]).addClass('active');
		}
	});
		
	// Lazy load ----->
	
	$("#content-container .large").lazyload({
		placeholder : "images/site/lazy.gif",
		effect: "fadeIn"
	});
	
	// Back to top ----->
	
	$(".top").click(function(){
		$("html, body").animate({scrollTop:0});
		return false;
	});
	
});
