$(document).ready(function() {
$("body.book li.book").css("display", "block");
$("body.logos li.logos").css("display", "block");
$("body.web li.web").css("display", "block");
$("body.packaging li.packaging").css("display", "block");
$("body.marketing li.marketing").css("display", "block");
	//nav selection
$("body.book #navigation li.books").addClass("selected");
$("body.logos #navigation li.logos").addClass("selected");
$("body.marketing #navigation li.marketing-materials").addClass("selected");
$("body.web #navigation li.web-interactive").addClass("selected");
$("body.packaging #navigation li.packaging").addClass("selected");
$("body.About #navigation li.about").addClass("selected");
$("body.Contact #navigation li.contact-me").addClass("selected");
$("body.selected #navigation li.showall").addClass("selected");
$.get("http://heidismets.com/blog/newest.php", function(data){
   $("div#recent-blog").append(data);
	$("#navigation li:not(.filter-portfolio-by, .twit, .rss, .fb)").hover(
	  function () {
		$(this).addClass('selected2');
	  }, 
	  function () {
		$(this).removeClass('selected2');
	  }
	);
	});
$("div#content span").prependTo("div#content p:last");
$("div#content span").append("  ");
	
	//project specific copy
		$("div.image img[src*='solutions/03.jpg']").each(function() {
			$(this).after("<a href=\"http://naturalbuildingsolutions.com\" alt=\"Natural Building Solutions\">LAUNCH.</a>");
			$(this).parent().height(404);
		});
		
		$("div.image img[src*='wilds/01']").each(function() {
			$(this).after('<p><span>NOT LIVE YET.</span></p>');
			$(this).parent().height(367);
		});
		
		$("div.image img[src*='nse']").each(function() { 
			$(this).after("<a href =\"http://nsecomposites.com\" alt=\"NSE Composites\">LAUNCH.</a>");
			$(this).parent().height(428);		//nse img linking
			$(this).wrap(document.createElement("a"));
			$("div.image a").attr('href','http://nsecomposites.com');
		});
		
		$("div.image img[src*='solutions/03']").each(function() {
			$(this).wrap(document.createElement("a"));
			$("div.image a").attr('href','http://naturalbuildingsolutions.com');
		});
//end project specific copy

	$("div.image").each(function() {
		var h = $(this).height() - 3;
		var w = $(this).width() + 0;
		$(this).width(w);
		$(this).children(".shadowy").height(h);
	});
	$("img.shadow[src*='noshadow']").removeClass('shadow'); //images with noshadow
	$("body.sliderbody").each(function() { //for ie returning null on objects that don't exists...

	
	$(".anythingSlider img[src*='noslide']").each(function() {  //exception for slider folders
		$(this).clone().prependTo("div.asdf").addClass('rmvd');
		$(this).parent().remove();
		});
		$('.rmvd').addClass("shadow");
	var slidew = $(".anythingSlider img").width();
	var slideh = $(".anythingSlider img").height();
	$(".anythingSlider div.wrapper").height(slideh).width(slidew - .5);
	$(function () {
		var thelink = location.href;
		var pos = thelink.indexOf("olive");
		if (pos>=0) {
		$(".anythingSlider div.wrapper").height(slideh).width(slidew);
		}
	});

	$("div.anythingSlider").height(slideh).width(slidew);//make slider height match images
	var bn = $("body.sliderbody div#navbottom").css('bottom');
	//$("body.sliderbody div#navbottom").css('bottom', 0 - slideh - 70);
	var ims = $("img:not(li img)").size() - 5;
	$("div.asdf").height(slideh * ( ims + 1) + ( ( ( ims ) * 2) * 60)  ); //uses slide height plus number of non-slide images to calculate new height of document
		if (ims == 0) {
		$("div.asdf").height(slideh + 20);
		}
	
	});
			//to keep nav button on globally
			var thelink = location.href;
			var pos = thelink.indexOf("logos");
			if (pos>=0) {
				$("div#navigation li.logos").addClass("selected");
			}
			
			var pos1 = thelink.indexOf("projects");
			if (pos1>=0) {
				$("div#navigation li.showall").addClass("selected");
			}
			var pos2 = thelink.indexOf("books");
			if (pos2>=0) {
				$("div#navigation li.books").addClass("selected");
			}
			var pos3 = thelink.indexOf("marketing");
			if (pos3>=0) {
				$("div#navigation li.marketing-materials").addClass("selected");
			}
			var pos4 = thelink.indexOf("packaging");
			if (pos4>=0) {
				$("div#navigation li.packaging").addClass("selected");
			}
			var pos5 = thelink.indexOf("web");
			if (pos5>=0) {
				$("div#navigation li.web-interactive").addClass("selected");
			}
	
		 /* $("div.image a").each(function() {
		var ah = $(this).parent().height();
		console.log(ah);
		$(this).parent().height(ah - 30);
		});*/

	
	

function getHeight() {
        var y = 0;
        if (self.innerHeight) {
            y = self.innerHeight;
			}
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                y = document.documentElement.clientHeight;
        }
        else if (document.body)
        {
                y = document.body.clientHeight;
        }
        return y;
}
var hhh = getHeight();
var mainh = $("div#main").height();
function setHeight() {
	//make heights behave in every browser

	if (mainh < 720) {
		$("div#main").height(780);
		$("div#sidebar").height(780);
		if (hhh > 780) {
			$("div#main").height(hhh);
			$("div#sidebar").height(hhh);
			}
		}
		else {
			$("div#sidebar").height(mainh);
			}
}	
var hhh = getHeight();
setHeight();	
	/* templating for images that could fit 2 per row */
	$("div.image").each(function() {
		var size = $(this).first().width();
		if (size < 400) {
		$(this).first().addClass('smallpic');
		}
	});
	
			//if only one image	
var imsz = $("div.image img").size();
if (imsz == 1) {
$("div#navbottom").css("visibility","hidden");
var hhh = getHeight();
setHeight();	


$("div#main").height(900);
		$("div#sidebar").height(900);
		
}

	
	
	for (i=0;i<=25;i=i+2) {
		$("div.smallpic").eq(i+1).addClass('right');
		$("div.smallpic").eq(i+1).css("float", "right");
	};
	$("body img[src*='red-label-moto/01.jpg']").each(function() {
		$("this").after("<img class= \"hidden\" src=\"/public/images/red03.jpg\" alt=\"red\" >");
		});
	$("img[src*='red-label-moto/01.jpg']").hover(function() {
		$(this).attr("src","/public/images/red03.jpg");
		},
		function() {
		$(this).attr("src","http://heidismets.com/content/4.projects/7.red-label-moto/01.jpg");
		});
		
		$("img[src*='http://heidismets.com/content/4.projects/2.urban-wilds/01.jpg']").after("<p><span>NOT LIVE YET</span></p>");
		
		//add slideshow text
		$(".anythingSlider").after("<p><span class=\"slideshow\">SLIDESHOW</span></p>");
		var toppy = $(".anythingSlider").height();
		var toppy1 = toppy + 4;
		var toppy2 = toppy + 6;
		$("div#thumbNav").css("top", toppy1);
		$("a.forward, a.back").css("top", toppy2);
		//ie7 fix
		var ie = navigator.appVersion.indexOf("MSIE 7.");
		if (ie > 0) {
			$("div#thumbNav").css("top", toppy1 - 4);
			$("a.forward, a.back").css("top", toppy2 - 2);
			}

	
	/* shadow script */
	var gradientshadow={}
gradientshadow.depth=10 //Depth of shadow in pixels
gradientshadow.containers=[]

gradientshadow.create=function(){
var a = document.all ? document.all : document.getElementsByTagName('*')
for (var i = 0;i < a.length;i++) {
	if (a[i].className == "shadow") {
		for (var x=0; x<gradientshadow.depth; x++){
			var newSd = document.createElement("DIV")
			newSd.className = "shadow_inner"
			newSd.id="shadow"+gradientshadow.containers.length+"_"+x //Each shadow DIV has an id of "shadowL_X" (L=index of target element, X=index of shadow (depth) 
			if (a[i].getAttribute("rel"))
				newSd.style.background = a[i].getAttribute("rel")
			else
				newSd.style.background = "black" //default shadow color if none specified
			document.body.appendChild(newSd)
		}
	gradientshadow.containers[gradientshadow.containers.length]=a[i]
	}
}
gradientshadow.position()
window.onresize=function(){
	gradientshadow.position()
}
}

gradientshadow.position=function(){
if (gradientshadow.containers.length>0){
	for (var i=0; i<gradientshadow.containers.length; i++){
		for (var x=0; x<gradientshadow.depth; x++){
  		var shadowdiv=document.getElementById("shadow"+i+"_"+x)
			shadowdiv.style.width = gradientshadow.containers[i].offsetWidth + "px"
			shadowdiv.style.height = gradientshadow.containers[i].offsetHeight + "px"
			shadowdiv.style.left = gradientshadow.containers[i].offsetLeft + x + "px"
			shadowdiv.style.top = gradientshadow.containers[i].offsetTop + x + "px"
		}
	}
}
}

if (window.addEventListener)
window.addEventListener("load", gradientshadow.create, false)
else if (window.attachEvent)
window.attachEvent("onload", gradientshadow.create)
else if (document.getElementById)
window.onload=gradientshadow.create
		
	
});

