$(document).ready(function() {
    //Load content on page load
	$("#content").html('<ul><li>Loading Content...</li></ul>')
				 .load("/content/" + "projects.php", null, function() {
					  contentHeight = $("#content").height();
					  selectHeight = $("#select").height();
					  $("#spacer").height((contentHeight - selectHeight - 20) + "px")
					              .css({"top": selectHeight + 20 + "px" });
					  });

		
	//Load content on click
	$(".load").click(function(){
			  loadName = $(this).attr("id");
			  $("#content").html('<ul><li>Loading Content...</li></ul>')
						   .load("/content/" + loadName + ".php", null, function(){
								  contentHeight = $("#content").height();
								  selectHeight = $("#select").height();
											  
						         if(selectHeight < contentHeight) {
									 $("#spacer").css({"top": selectHeight + 40 + "px", "display": "block" })
												 .height((contentHeight - selectHeight - 40) + "px");
									}else{
									 $("#spacer").css({"display": "none"}); 
									return;
									}
			   					  });
			  });
	
	$(".blog").click(function(){
			  $("#content").html('<ul><li>Loading Content...</li></ul>')
						   .load("/blog/index.php", null, function(){
								  contentHeight = $("#content").height();
								  selectHeight = $("#select").height();
											  
						         if(selectHeight < contentHeight) {
									 $("#spacer").css({"top": selectHeight + 40 + "px", "display": "block" })
												 .height((contentHeight - selectHeight - 40) + "px");
									}else{
									 $("#spacer").css({"display": "none"}); 
									return;
									}
			   					  });
			  });

	
	//Image Swap
	$(".projectThumb img").live("mouseover",
						  function() {
								  iconName = $(this).attr("src");
								  origin = iconName.split("_static.")[0];
								  $(this).attr({src: "" + origin + "_rollover.jpg"});
						  });
	
	$(".projectThumb img").live("mouseout",
						  function() {
								  iconName = $(this).attr("src");
								  origin = iconName.split("_rollover.")[0];
								  $(this).attr({src: "" + origin + "_static.gif"});
						  });
	
    //Find & Open
	$(".projectThumb").live("click", function(e) {
			$("#backgroundPopup").show();
			htmlName = $(this).find("img").attr("name");
			$("#data").load("/content/" + htmlName + ".html", null, function() {
					//Set Variables
					var container = $(".container");
					var project = $(".project");
					var popupWidth = container.find(".project img:first").width();
					var popupHeight = container.find(".project img:first").height()+35;
					var windowWidth = document.documentElement.clientWidth;
					var windowHeight = document.documentElement.clientHeight;
					var x = ($(window).width() / 2 - popupWidth / 2) + $(window).scrollLeft();
					var y = ($(window).height() / 2 - popupHeight / 2) + $(window).scrollTop();

					//Slideshow Image to hide rest
					$(".container").each(function() {
									$(".project img", this).hide().filter(":first").show();
									});
	
					//Slide show switch
					$('ul.slideImages li a').click(function () {
							if (this.className.indexOf('active') == -1){
									var images = $(this).closest(".container .project").find("img");
									images.hide();
									images.filter(this.hash).show();
									$('ul.slideImages li a').removeClass('active');
									$(this).addClass('active');
									}
									return false;
							});
					
					//Set popup dimensions
					container.css("width" , popupWidth);
					container.css("height" , popupHeight);
	
					//Set popup CSS
					container.css({"position": "absolute", "background": "#000", "left": x + "px", "z-index": "2" });
					project.css({"width": (popupWidth), "height": (popupHeight) });
					
					//Determine Position
					if(popupHeight>windowHeight) {
						container.css({"top": $(window).scrollTop() + 10 + "px"}); 
						}else{
						container.css({"top": y + "px"});
						return false;
						}
				});
			});
	
	//Close property
	$("a.close").live("click", function() {
			$("#data").empty();
			$("#backgroundPopup").hide();
			});
	
	$("#backgroundPopup").live("click", function() {
			$("#data").empty();
			$("#backgroundPopup").hide();
			});
});

//Email Blocking
function block(name,domain) {
        str = "mailto:" + name + "@" + domain;
        window.location = str;
    }



