﻿$(document).ready(function() {
	slide();
	webmenu();
	graphicmenu();
	interiormenu();
	corporatemenu();
	shuffle($("#thumbs a"));
	thumbfade();
	ajax();
});

function slide() {
	$("#menu li.sliding_element a").each(function(i){
		$(this).hover(
		function()
		{
			$(this).animate({ paddingLeft: 7 }, 100);
		},
		function()
		{
			$(this).animate({ paddingLeft: 0 }, 100);
		});
	});
}

function webmenu(){
	hiConfig = {
		sensitivity: 3,
		interval: 200,
		timeout: 0,
		over: function(){
			$(this).css("cursor", "pointer");
			$(this).parent().animate({ height: "81px" }, {queue:false, duration:"fast"} );
			$(this).parent().find("span").css("margin-top", "-10px");
			$(this).parent().find("span").animate({opacity: "show"}, "fast");
		},
		out: function(){
			$(this).parent().animate({ height: "46px" }, {queue:false, duration:"fast"} );
			$(this).parent().find("span").animate({opacity: "hide"}, "fast");
		}
	}
	$("#iconbar li a.web").hoverIntent(hiConfig)
}

function graphicmenu(){
	hiConfig = {
		sensitivity: 3,
		interval: 200,
		timeout: 0,
		over: function(){
			$(this).css("cursor", "pointer");
			$(this).parent().animate({ height: "82px" }, {queue:false, duration:"fast"} );
			$(this).parent().find("span").css("margin-top", "-10px");
			$(this).parent().find("span").animate({opacity: "show"}, "fast");
		},
		out: function(){
			$(this).parent().animate({ height: "47px" }, {queue:false, duration:"fast"} );
			$(this).parent().find("span").animate({opacity: "hide"}, "fast");
		}
	}
	$("#iconbar li a.graphic").hoverIntent(hiConfig)
}

function corporatemenu(){
	hiConfig = {
		sensitivity: 3,
		interval: 200,
		timeout: 0,
		over: function(){
			$(this).css("cursor", "pointer");
			$(this).parent().animate({ height: "91px" }, {queue:false, duration:"fast"} );
			$(this).parent().find("span").css("margin-top", "-10px");
			$(this).parent().find("span").animate({opacity: "show"}, "fast");
		},
		out: function(){
			$(this).parent().animate({ height: "56px" }, {queue:false, duration:"fast"} );
			$(this).parent().find("span").animate({opacity: "hide"}, "fast");
		}
	}
	$("#iconbar li a.corporate").hoverIntent(hiConfig)
}

function interiormenu(){
	hiConfig = {
		sensitivity: 3,
		interval: 200,
		timeout: 0,
		over: function(){
			$(this).css("cursor", "pointer");
			$(this).parent().animate({ height: "80px" }, {queue:false, duration:"fast"} );
			$(this).parent().find("span").css("margin-top", "-10px");
			$(this).parent().find("span").animate({opacity: "show"}, "fast");
		},
		out: function(){
			$(this).parent().animate({ height: "45px" }, {queue:false, duration:"fast"} );
			$(this).parent().find("span").animate({opacity: "hide"}, "fast");
		}
	}
	$("#iconbar li a.interior").hoverIntent(hiConfig)
}

function shuffle(e) {
	var replace = $("<a>");
	var size = e.size();
	while (size >= 1) {
		var rand = Math.floor(Math.random() * size);
		var temp = e.get(rand);
		replace.append(temp);
		e = e.not(temp);
		size--;
	}
	$("#thumbs").html(replace.html());
}

function thumbfade(){
	var hash = window.location.hash.substr(1);
	if (hash != "") {
		if(hash == "all") {
			$("#thumbs img").animate({opacity: 1}, "fast")
		}
		else {
			$("#thumbs img[class=" + hash + "]").animate({opacity: 1}, "fast");
			$("#thumbs img[class!=" + hash + "]").animate({opacity: 0.1}, "fast");
		}
		$("h2 a.active").removeClass("active");
		$("h2 a[href=" + "#" + hash + "]").addClass("active");
	}

	$("h2 a").click(function () {
		var project = $(this).attr("href").replace(/#/g, "");
		if(project == "all") {
			$("#thumbs img").animate({opacity: 1}, "fast")
		}
		else {
			$("#thumbs img[class=" + project + "]").animate({opacity: 1}, "fast");
			$("#thumbs img[class!=" + project + "]").animate({opacity: 0.1}, "fast");
		}
		$("h2 a.active").removeClass("active");
		$(this).addClass("active");
	});

	$("#iconbar li a").click(function () {
		var project = $(this).attr("href").replace(/#/g, "");
		if(project == "all") {
			$("#thumbs img").animate({opacity: 1}, "fast")
		}
		else {
			$("#thumbs img[class=" + project + "]").animate({opacity: 1}, "fast");
			$("#thumbs img[class!=" + project + "]").animate({opacity: 0.1}, "fast");
		}
		$("h2 a.active").removeClass("active");
		$("h2 a[href=" + "#" + project + "]").addClass("active");
	});
}

function ajax(){
	$.ajaxSetup ({
		cache: true
	});
	var ajax_load = "<img src='images/ajax-loader.gif' alt='Loading...' />";  
	$("#thumbs a img").click(function(){
		var loadUrl = "projects/" + $(this).attr("class") + "/" + $(this).attr("alt") + ".html";
		$("#project").slideUp(function() {
			$("#loader").hide().html(ajax_load).fadeIn("fast");
			$(this).html(ajax_load).load(loadUrl, function() {
				$("#project img").hide().load(function() {
					$(this).fadeIn("fast");
					$("#loader img").remove();
					$("#project").slideDown();
				});
			});
		});
	});
}
