// JavaScript Document
$(document).ready(function() {
	 $(document).pngFix();					   
//on load
$(".description, .project_photo_container").hide();
$(".project").fadeTo(0,0);
$.fn.wait_fade = function(){
	var p=$(".project").index(this);
	var n=$(".project").length;
	$(this).fadeTo(800,1);
	setTimeout(function() {
		if((p+1)!=n){
	$(".project").eq(p+1).wait_fade();
	}				
	 },100);
	};
$(".project").eq(0).wait_fade();
	
var image_number;
var current_image_number;
var next_image_number;
var project_name_path;
var project_hash=window.location.hash.substr(1);
if(project_hash!="view_all" && project_hash!=""){
	$(".project_photo_container").fadeIn(300);
	/*$(".container").fadeOut(200);*/
	$("[title="+project_hash+"]").find(".title").css({"color":"#0033FF"});
	project_name_path=project_hash;
	var project_name=project_hash.replace("_"," ").toUpperCase();
	current_image_number=1;
	image_number=parseInt($("[title="+project_hash+"]").attr("alt"));
	next_image_number=2;
	$("#project_view_title").html(project_name);
	$("#image_current_number").html("1");
	$("#image_total_number").html(image_number);
	$(".project_image_mask").load("../project/"+project_name_path+"/"+project_name_path+".html");
}

					
	
//project
$(".project, .category").hover(function(){
	$(this).find("img").fadeOut(300);
	$(this).css({"zIndex":"2"});	},function(){
	$(this).find("img").fadeIn(200);
	$(this).css({"zIndex":"1"});
	});
$(".project").click(function(){
	$(".project_photo_container").fadeIn(300);
	/*$(".container").fadeOut(200);*/
	$(this).find(".title").css({"color":"#dfea47"});
	project_name_path=$(this).attr("title");
	var project_name=$(this).attr("title").replace("_"," ").toUpperCase();
	current_image_number=1;
	image_number=parseInt($(this).attr("alt"));
	next_image_number=2;
	$("#project_view_title").html(project_name);
	$("#image_current_number").html("1");
	$("#image_total_number").html(image_number);
	$(".project_image_wrapper").load("../project/"+project_name_path+"/"+project_name_path+".html");
	window.location.hash=project_name_path;
	$(".project_image_wrapper").css({"width":image_number*780, "left":"0px"});
});
//image navigation
$(".navigation").find("img").hover(function(){
	$(this).attr({"src":"../img/buttons/"+$(this).attr("id")+"2"+".jpg"});
	},function(){
	$(this).attr({"src":"../img/buttons/"+$(this).attr("id")+"1"+".jpg"});
});
$("#close").click(function(){
	/*$(".container").fadeIn(300);*/
	$(".project_photo_container").fadeOut(200);
	window.location.hash="view_all";
	$(".project_image_wrapper").html("");
	});
$("#plus").click(function(){
	  if(current_image_number==image_number){
		 $(".project_image_wrapper").fadeTo(100, .2, 
		function (){
		$(this).animate({left:"0px"},800, 
		function(){
		$(this).fadeTo(100, 1);
		});
		});
		 current_image_number=1;
		 $("#image_current_number").html("1");
	  } else {
		var scroll_to="-"+(current_image_number*780)+"px";		
		$(".project_image_wrapper").fadeTo(100, .2, 
		function (){
		$(this).animate({left:scroll_to},500, 
		function(){
		$(this).fadeTo(100, 1);
		});
		});
		current_image_number++;
		$("#image_current_number").html(current_image_number);
		}
		});
$("#minus").click(function(){
		 if(current_image_number==1){
		$(".project_image_wrapper").fadeTo(100, .2, 
		function (){
		var scroll_to="-"+((image_number-1)*780)+"px";
		$(this).animate({left:scroll_to},800, 
		function(){
		$(this).fadeTo(100, 1);
		});
		});
		 current_image_number=image_number;
		 $("#image_current_number").html(current_image_number);
	  } else {
		var scroll_to="-"+((current_image_number-2)*780)+"px";		
		$(".project_image_wrapper").fadeTo(100, .2, 
		function (){
		$(this).animate({left:scroll_to},500, 
		function(){
		$(this).fadeTo(100, 1);
		});
		});
		current_image_number=current_image_number-1;
		$("#image_current_number").html(current_image_number);
		}
		});



});
