$(document).ready(function() {

	//adds arrow for nav development only
   $("#subNav li .current").append("<img src='images/base/pageArrow.png' alt='' width='35' height='20' class='arrow' />")
   var xPos = Math.round(($("#subNav li .current").width( )-15)/2)
   $("#subNav li .current img").css('left',xPos)


     $("li.menu").hover(

      function () {
        $(this).stop().children(".submenu").css("display","none").fadeIn('fast');
        $(this).children().addClass("current")
        
        
      }, 
      function () {
       $(this).stop().children(".submenu").fadeOut('fast')
       $(this).children().removeClass("current")
      }
    );
  
  
  //projects
 $("#projectsWrap").hide()

  
  $(".project").each(function(index){
	
});
  
  //project link
  $("ul#projectList li a").click(function() {
 	var $th = $(this).parent();
 	var theIndex = $th.parent().children().index($th)
 	$("#projectsWrap").fadeIn(function() {
  setHeight(theIndex)
});
 	var yPos = theIndex * -750;
 	$("#projectsHolder").stop().animate( { left:yPos }, 1000 );
 	//console.log(theIndex)
  });
  //close 
  $("#closeWindow").click(function () { 
   $("#projectsWrap").fadeOut()
   //console.log("close")
   });

var slideCount=0
 
 function setHeight(daIndex) {
 //console.log('setHeight= '+daIndex)
 	var newHeight = $("#projectsHolder").children().eq(daIndex).height();
 	newHeight += 100;
 	slideCount = daIndex
 	
 	$("#projectsWrap").animate( { height:newHeight+"px" }, 500 );
 	
 }
 
   //more links
  var liItems = $("#projectList").children().size()
  var liItemsMax = ((liItems-1)*750)*-1+"px"
 // console.log(liItemsMax+'LI items')
 
  //right
	 function advanceSlide() {
	  var yPos = $("#projectsHolder").css('left')
     if(yPos==liItemsMax){alert("No More Projects!")}else {
			$("#projectsWrap a.MoreRight").unbind('click', advanceSlide) 
			
			yPos = parseFloat(yPos)-750
			$("#projectsHolder").stop().animate( { left:yPos }, 1000, function() {
				$("#projectsWrap a.MoreRight").bind('click', advanceSlide);
				
			});
			//expand box
			slideCount++
			
			setHeight(slideCount);
    	}
    }
    $("#projectsWrap a.MoreRight").bind('click', advanceSlide) 
    
    
    //left
     function reverseSlide() {
     var yPos = $("#projectsHolder").css('left')
     if(yPos=="0px"){alert("No More Projects!")}else {
	 	$("#projectsWrap a.MoreLeft").unbind('click', reverseSlide) 
    	
  		
		yPos = parseFloat(yPos)+750
		$("#projectsHolder").stop().animate( { left:yPos }, 1000, function() {
			$("#projectsWrap a.MoreLeft").bind('click', reverseSlide);
		
		});
		//expand box
			slideCount--
			
			setHeight(slideCount);
		}
    }
    $("#projectsWrap a.MoreLeft").bind('click', reverseSlide) 
    
    
    //photogallery
    function loadImage(theImg,newImg){
//$(".projectImg img,.projectImg strong").animate({opacity:"0"},1000);
$(theImg).find('img').animate({opacity:'0'},1000)

var img = new Image();
	$(img).load(function () {
		$(this).hide();
		$(theImg).find('img').replaceWith(this);
		$(this).fadeIn();
	}).error(function () {
// notify the user that the image could not be loaded
	}).attr('src',newImg);

}
    
     $(".projectPreviews li a").click(function () { 
     	
     	var newImg = $(this).attr('href');     	loadImage($($(this).parent().parent().parent().find(".projectImg")),newImg)
     	return false;
    
      });
    
 }); 