function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    
    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}

$(document).ready(function(){

	var hashOn = true;
	var projectImages;
	
	img = new Image();
    img.src = "../Images/ajaxLoader.gif";

	$("#centerImg a").fancybox();
	$("#slider").nivoSlider();
	
	$(".button").live('hover', function(){
		$(this).css("background-position", "right bottom");
		$(".buttonLeft", this).css("background-position", "center bottom");
	});
		
	$(".button").live('mouseleave', function(){
		$(this).css("background-position", "right top");
		$(".buttonLeft", this).css("background-position", "center top");
				
	});
	
	$("#centerImg .imgCover, #centerImg #zoom, #centerImg .info").live('hover', function(){
		$("#centerImg #zoom").show();
		$("#centerImg .imgCover").css("opacity", "0.5");
		$("#centerImg .imgCover").css("-ms-filter", '"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"');
		$("#centerImg .imgCover").css("filter", "alpha(opacity=50)");
		$("#centerImg .imgCover").css("-moz-opacity", "0.5");
		$("#centerImg .imgCover").css("-khtml-opacity", "0.5");
	});
		
	$("#centerImg .imgCover, #centerImg #zoom, #centerImg .info").live('mouseleave', function(){
		$("#centerImg #zoom").hide();
		$("#centerImg .imgCover").css("opacity", "0");
		$("#centerImg .imgCover").css("-ms-filter", '"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"');
		$("#centerImg .imgCover").css("filter", "alpha(opacity=0)");
		$("#centerImg .imgCover").css("-moz-opacity", "0");
		$("#centerImg .imgCover").css("-khtml-opacity", "0");
		
	});	
	
	$("#pathContent p").live('click', function() {
	
		if (navigator.appName == "Microsoft Internet Explorer") {
			if (getIEVersionNumber() < 8) return true;
		}

		if (hashOn == false) return false;
		
		hashOn = false;

		var correntLevel = $("#pathContent p").length;
		var level = $(this).prevAll("p").length + 1;
		var correntBox = "";
		var showBox = "";
		
		if (correntLevel <= level) {
			hashOn = true;
			return false;
		}
		
		if (correntLevel == 2) correntBox = $("#projectView");
		if (correntLevel == 3) correntBox = $("#projectImages");
		
		if (level == 1) showBox = $("#projectsList");
		if (level == 2) showBox = $("#projectView");		
		
		if (level == 1) {
			//if ($("#pathContent p").slice(0, 1).text() == $("#desktopBox").text()) var ID = "desktop";
			//if ($("#pathContent p").slice(0, 1).text() == $("#webBox").text()) var ID = "web";
			
		}
		
		if (level == 1) var ID = $("#projectsList .id").text();
		if (level == 2) var ID = $("#projectView .id").text();
		
		var extraDelay = 0;
		
		if ((correntLevel-level) == 2) {
			var extraDelay = 900;
			$("#pathContent p").slice(2, 3).animate({width: "0px"}, 700);
			$("#pathContent div").slice(2, 3).delay(800).animate({width: "0px"}, 100);
		}
		
		$("#pathContent p").slice(level, level+1).delay(100+extraDelay).animate({width: "0px"}, 700);
		$("#pathContent div").slice(level, level+1).delay(900+extraDelay).animate({width: "0px"}, 100);
		
		$(this).delay(1100+extraDelay)
		.animate({marginRight: "5px"}, 200)
		.animate({marginRight: "0px"}, 200)
		.animate({marginRight: "5px"}, 200)
		.animate({marginRight: "0px"}, 200)
		.animate({marginRight: "5px"}, 200)
		.animate({marginRight: "0px"}, 200, function() {
			$(this).nextAll().detach()
		});
				
		correntBox.delay(3500+extraDelay).slideUp(1000, function() {window.location.hash = ID;});
		showBox.delay(4500+extraDelay).slideDown(1000);
				
		$('html, body').stop().delay(4500+extraDelay).animate({scrollTop:$("body").height()}, 1100);
				
	});
	
	$("#projectImages .button").live("click", function() {
		$("#pathContent p").slice(1, 2).trigger("click");
	});
		
	$("#projectTypes #desktop, #projectTypes #web").live('click', function() {
		
		if (navigator.appName == "Microsoft Internet Explorer") {
			if (getIEVersionNumber() < 8) return true;
		}
		
		if (hashOn == false) return false;
		
		hashOn = false;
		
		var ID = $(this).attr("id");
		var box = $(this).parent().parent();
		var showBox = $("#projectsList");	
		var path = $("#projectTypes #" + ID).text();
		
		$("#path .ajaxLoader").show();
		
		$.ajax({
			type: "POST",
			url: "GetData.php",
			data: "data=" + ID,
			success: function(data){
				
				$("#path .ajaxLoader").fadeOut(1000);
				$("#path #pathContent").append('<div class="arrow last"></div><p class="last clearfix"><span>' + path + '</span></p>');
				
				var Width = $("#path #pathContent .last span").width() + 3;

				$("#path #pathContent .last span").css("width", Width + "px");
				
				$("#path #pathContent .last").hide().slideUp();
				$("#path #pathContent .arrow").delay(1100).show(1);
				$("#path #pathContent .arrow").removeClass("last");
								
				$("#path #pathContent .last").delay(1100).animate({width: 'toggle'}, 700);				
				$("#path #pathContent .last").removeClass("last");
				$("#projectsList .whiteBox").html(data);
				
				if (ID == "desktop") $("#projectTypes #webBox").delay(1500).fadeOut(1000);
				if (ID == "web") $("#projectTypes #desktopBox").delay(1500).fadeOut(1000);
				
				box.delay(2600).animate({
					width: "843px"
				}, 2000, function() {
					$(this).slideUp(1000, function() {window.location.hash = ID;});
					showBox.delay(1000).slideDown(1000);
				});
				
				$('html, body').delay(4000).animate({scrollTop:$("body").height()}, 1100);
				
			}
		});
				
		return false;
	
	});
	
	
	$("#projectsList .button").live('click', function() {
		
		if (navigator.appName == "Microsoft Internet Explorer") {
			if (getIEVersionNumber() < 8) return true;
		}
		
		if (hashOn == false) return false;
		
		hashOn = false;
		
		var ID = $(this).attr("id");
		var box = $("#projectsList");
		var showBox = $("#projectView");	
		var path = $("#projectsList #" + ID).text();
		
		$("#path .ajaxLoader").show();
		
		$.ajax({
			type: "POST",
			url: "GetData.php",
			data: "data=" + ID,
			success: function(data){
				
				$("#path .ajaxLoader").fadeOut(1000);
				$("#path #pathContent").append('<div class="arrow last"></div><p class="last clearfix"><span>' + path + '</span></p>');
				
				var Width = $("#path #pathContent .last span").width() + 3;
				$("#path #pathContent .last span").css("width", Width + "px");
				
				$("#path #pathContent .last").hide().slideUp();
				$("#path #pathContent .arrow").delay(1100).show(1);
				$("#path #pathContent .arrow").removeClass("last");
								
				$("#path #pathContent .last").delay(1100).animate({width: 'toggle'}, 700);
				$("#path #pathContent .last").removeClass("last");
				
				$("#projectView .whiteBox").html(data);
				
				box.delay(2000).slideUp(1000, function() {window.location.hash = ID;});
				showBox.delay(3000).slideDown(1000);
				
				$('html, body').delay(3000).animate({scrollTop:$("body").height()}, 1100);
				
			}
		});
				
		return false;
	
	});
	
	$("#projectView .button").live('click', function() {
		
		if (navigator.appName == "Microsoft Internet Explorer") {
			if (getIEVersionNumber() < 8) return true;
		}
		
		if (hashOn == false) return false;
		
		hashOn = false;
		
		var ID = $(this).attr("id");
		var box = $("#projectView");
		var showBox = $("#projectImages");	
		var path = $("#projectView #" + ID).text();
		
		$("#projectImages .title span").text($("#projectView .title span").text());
		
		$("#path .ajaxLoader").show();
		
		$.ajax({
			type: "POST",
			url: "GetData.php",
			data: "data=" + ID,
			success: function(data){
				
				$("#path .ajaxLoader").fadeOut(1000);
				$("#path #pathContent").append('<div class="arrow last"></div><p class="last clearfix"><span>' + path + '</span></p>');
				
				var Width = $("#path #pathContent .last span").width() + 3;
				$("#path #pathContent .last span").css("width", Width + "px");
				
				$("#path #pathContent .last").hide().slideUp();
				$("#path #pathContent .arrow").delay(1100).show(1);
				$("#path #pathContent .arrow").removeClass("last");
								
				$("#path #pathContent .last").delay(1100).animate({width: 'toggle'}, 700);
				$("#path #pathContent .last").removeClass("last");
				
				projectImages = data.split("\n");
				
				$.each(projectImages, function(i, line) {
					projectImages[i] = $.trim(line);
				});
				 					
				$("#imgLeft").css("display", "none");
				box.delay(2000).slideUp(1000, function() {window.location.hash = ID;});
				showBox.delay(3000).slideDown(1000, function() {setImage(projectImages[0]);});
				
				$('html, body').delay(3000).animate({scrollTop:$("body").height()}, 1100);
				
			}
		});
				
		return false;
	
	});
	
	$("#centerImg").live('click', function() {
		$.fancybox({
			'hideOnContentClick'	: true,
			'showCloseButton'		: false,
			'centerOnScroll'		: true,
			'href'					: $("#centerImg img").attr("src"),
			'type'					: 'image'
		});
	});
	
	$("#imgRight, #imgLeft").live('click', function() {
		if ($("img", this).attr("src") != "") setImage($("img", this).attr("src"));
	});
	
	function setImage(url) {
		for (x in projectImages) {
			if (url == projectImages[x]) {
				$("#centerImg img, #imgRight img, #imgLeft img").removeAttr("style");
				$("#centerImg img").attr("src", projectImages[x]);
				if (projectImages[parseInt(x)+1] != "") $("#centerImg h4").text(projectImages[parseInt(x)+1]).show(1);
				if (projectImages[parseInt(x)+1] == "") $("#centerImg h4").text("").hide(1);
				if (projectImages[parseInt(x)+2] != "") $("#centerImg p").text(projectImages[parseInt(x)+2]).show(1);
				if (projectImages[parseInt(x)+2] == "") $("#centerImg p").text("").hide(1);
				$("#imgRight img").attr("src", "");
				$("#imgLeft img").attr("src", "");
				
				$("#centerImg img").css("display", "none");
				$("#imgRight img").css("display", "none");
				$("#imgLeft img").css("display", "none");
				
				$("#imgRight").css("display", "block");
				$("#imgLeft").css("display", "block");

				if(projectImages[parseInt(x)-3] != "") $("#imgLeft img").attr("src", projectImages[parseInt(x)-3]);
				if(projectImages[parseInt(x)+3] != "") $("#imgRight img").attr("src", projectImages[parseInt(x)+3]);				
				if ($("#imgRight img").attr("src") == "") $("#imgRight").css("display", "none");
				if ($("#imgLeft img").attr("src") == "") $("#imgLeft").css("display", "none");
			}
		}
	}
	
		
	$("#centerImg img, #imgRight img, #imgLeft img").load(function() {
		
		if (navigator.appName == "Microsoft Internet Explorer") {
			if (getIEVersionNumber() < 8) return true;
		}
		
		if ($(this).attr("src") == "") return true;
		
		$(this).css("display", "block");
		
		var correntWidth = $(this).width();
		var correntHeight = $(this).height();
		var orginalWidth = $(this).width();
		var orginalHeight = $(this).width();
		
		var img = $(this);
		
		var maxWidth = 463;
		var maxHeight = 340;
		
		if (img.parent().attr("id") == "centerImg") var maxWidth = 590;
		if (img.parent().attr("id") == "centerImg") var maxHeight = 434;
		
		if (correntWidth > maxWidth) {
			img.width(maxWidth);
			img.css("top", "0px");
		}
		
		correntHeight = $(this).height();
		
		if (correntHeight > maxHeight && (correntHeight-maxHeight) < 11) img.height(maxHeight);
		if (correntHeight < maxHeight && (maxHeight-correntHeight) < 11) img.height(maxHeight);

		if (correntWidth == maxWidth) img.css("top", "0px");
		
		correntWidth = $(this).width();
		correntHeight = $(this).height();
		
		if (maxHeight >= correntHeight)
		img.css("top", ((maxHeight/2)-(correntHeight/2)) + "px");
		img.css("right", ((maxWidth/2)-(correntWidth/2)) + "px");
			
	});

	$(window).bind('hashchange', function() {
  		var hash = window.location.hash;
  		if (hashOn==false) {
  			hashOn = true;
  			return true;
  		}
  		//alert(hash);
	});

    if (window.location.hash.length) {
    	//alert(window.location.hash);
    }

});




















