// JavaScript Document

$.fn.sumOuterWidth = function(useMargins) {
  var sum = 0;
  this.each(function() { 
    sum += $(this).outerWidth(useMargins);
  });
  return sum;
};

//contactSheet attachEnlarge script

function attachEnlarge(){
$(".portraitPartyImage, .portraitPartyImageHorizontal").click(function(){

var x = parseInt($(this).attr("positionh"));
var y = parseInt($(this).attr("positionv"));


var pos = $(this).offset();
var left = pos.left;
var right = $("div#screen").outerWidth(true) - left - 84.6;
var rightH = $("div#screen").outerWidth(true) - left - 127.8;
var top = pos.top;
var bottom = $("div#screen").outerHeight(true) - top - 127.8;
var bottomH = $("div#screen").outerHeight(true) - top - 84.6;

var src = $(this).attr("src");


//beginning of regular portrait party grow/shrink code
if ($("#imgHolder").css("display") == "block") {

if($(this).attr("class") == "portraitPartyImage"){
$("#imgHolder,.imgHolderImage").animate({ 
    width: 84.6,
    height: 127.8
  }, 200, function() {
    $("#imgHolder,.imgHolderImage").attr("src",src); 
$("#imgHolder").css("visbility","hidden");

//  $("#imgHolder").css("display","none");
    $("#imgHolder").css("left","");
    $("#imgHolder").css("right","");
	    $("#imgHolder").css("top","");
    $("#imgHolder").css("bottom","");




if (x > 4){
  $("#imgHolder").css("left","");
$("#imgHolder").css("right",right);
} else {
$("#imgHolder").css("left",left);
}


if (y > 2 ){
$("#imgHolder").css("bottom",bottom);
} else {
$("#imgHolder").css("top",top);
}


$("#imgHolder").css("visbility","visible");
$("#imgHolder").css("z-index","5");


$("#imgHolder").animate({ 
    width: 275.96,
    height: 450.625
  }, 200, function() {

    }
   );




   $(".imgHolderImage").animate({ 
    width: 275.96,
    height: 425
  }, 200, function() {

    }
   );

	

   }
   );

}
if($(this).attr("class") == "portraitPartyImageHorizontal"){
	
	
	
$("#imgHolder,.imgHolderImage").animate({ 
    width: 127.8,
    height: 84.6
  }, 200, function() {
    $("#imgHolder,.imgHolderImage").attr("src",src); 
$("#imgHolder").css("visbility","hidden");

//  $("#imgHolder").css("display","none");
    $("#imgHolder").css("left","");
    $("#imgHolder").css("right","");
	    $("#imgHolder").css("top","");
    $("#imgHolder").css("bottom","");




if (x > 2){
  $("#imgHolder").css("left","");
$("#imgHolder").css("right",rightH);
} else {
$("#imgHolder").css("left",left);
}


if (y > 2 ){
$("#imgHolder").css("bottom",bottomH);
} else {
$("#imgHolder").css("top",top);
}


$("#imgHolder").css("visbility","visible");
$("#imgHolder").css("z-index","5");


$("#imgHolder").animate({ 
    width: 450.625,
    height: 280.96
  }, 200, function() {

    }
   );




   $(".imgHolderImage").animate({ 
    width: 425,
    height: 275.96
  }, 200, function() {

    }
   );

	

   }
   );	

	
}
 
 } else {


if($(this).attr("class") == "portraitPartyImage"){


$("#imgHolder,.imgHolderImage").css("height","127.8px");
$("#imgHolder,.imgHolderImage").css("width","84.6px");

$("#imgHolder,.imgHolderImage").attr("src",src);



if (x > 4){

  $("#imgHolder").css("left","");
$("#imgHolder").css("right",right);
} else {
$("#imgHolder").css("left",left);
}

	


if (y > 2){
$("#imgHolder").css("bottom",bottom);
} else {
$("#imgHolder").css("top",top);
}



$("#imgHolder").css("display","block");

$("#imgHolder").css("z-index","5");

  $("#imgHolder").animate({ 
       width: 275.96,
    height: 450.625
  }, 200, function() {

}
   );




   $(".imgHolderImage").animate({ 
    width: 275.96,
    height: 425
  }, 200, function() {

    }
   );

	
}

if($(this).attr("class") == "portraitPartyImageHorizontal"){
	$("#imgHolder,.imgHolderImage").css("height","84.6px");
$("#imgHolder,.imgHolderImage").css("width","127.8px");
	$("#imgHolder,.imgHolderImage").attr("src",src);



if (x > 2){

  $("#imgHolder").css("left","");
$("#imgHolder").css("right",rightH);
} else {
$("#imgHolder").css("left",left);
}

	


if (y > 2){
$("#imgHolder").css("bottom",bottomH);
} else {
$("#imgHolder").css("top",top);
}



$("#imgHolder").css("display","block");
$("#imgHolder").css("z-index","5");


  $("#imgHolder").animate({ 
       width: 450.625,
    height: 280.96
  }, 200, function() {

    }
   );




   $(".imgHolderImage").animate({ 
    width: 425,
    height: 275.96
  }, 200, function() {

    }
   );

	
	
	
	
}



}
});
		

}



function shrink(){
if($("#imgHolder").css("width") == "450.625px"){
	
	
	
  $("#imgHolder,.imgHolderImage").animate({ 
    width: 127.8,
    height: 84.6
  }, 150, function() {
  $(this).css("display","none");
      $("#imgHolder").css("left","");
    $("#imgHolder").css("right","");
	    $("#imgHolder").css("top","");
    $("#imgHolder").css("bottom","");
	$("#imgHolder").css("z-index","-1");
    }
   );
	
	
	
}else{
  $("#imgHolder,.imgHolderImage").animate({ 
    width: 84.6,
    height: 127.8
  }, 150, function() {
  $(this).css("display","none");
      $("#imgHolder").css("left","");
    $("#imgHolder").css("right","");
	    $("#imgHolder").css("top","");
    $("#imgHolder").css("bottom","");
	$("#imgHolder").css("z-index","-1");
    }
   );
}

}

function download(file){
file = "../" + file;
  $("#imgHolder,.imgHolderImage").animate({ 
    width: 84.6,
    height: 127.8
  }, 150, function() {
  $(this).css("display","none");
  $("#imgHolder").css("z-index","-1");
      $("#imgHolder").css("left","");
    $("#imgHolder").css("right","");
	    $("#imgHolder").css("top","");
    $("#imgHolder").css("bottom","");
	window.location.href = 'php/download.php?file=' + file;
    }
   );




}

function init() {

       // quit if this function has already been called
       if (arguments.callee.done) return;
 
       // flag this function so we don't do the same thing twice
       arguments.callee.done = true;
 
       //position front page images

$(window).load(function(){


$("#infoMenu").click( function(){
$("body").after("<div id='infoFrame'></div>");
$("#infoFrame").css("left",$(window).width());
$("#infoFrame").css("font-family","FuturaBook, Helvetica, sans-serif");
$("#infoFrame").css("font-size","13px");


$("#infoFrame").load('./php/clientListLoader.php', function() {


$("#infoFrame").animate({
						left: '0px'
						}, 900, function() {

$("span#closeInfo").click(function(){
								$("#infoFrame").animate({
						left: $(window).width()
						}, 900, function() {
							$("#infoFrame").remove();
							});   
								   
								   });

});

});

							   
							   });

//menu animation script
$("ul.mainMenu li.sub").click(
function() {
var ulName = "#" + $(this).attr('id') + "List";

if ($(ulName).css("bottom") == "240px"){

$(ulName).animate({
    bottom: '74px'
  }, 200, function() {
    // Animation complete.
  });

} else {


$("ul.menuList").animate({
    bottom: '74px'
  }, 200, function() {
    // Animation complete.
	$(ulName).animate({
    bottom: '240px'
  }, 200, function() {
    // Animation complete.
  });
  });

 }

}

); 
//end of menu animation script

if($("img#frontPageImage").length > 0){

$("img#frontPageImage").css("left",$(window).width());
$("img#frontPageImage").css("display","block");

															
$("img#frontPageImage").animate({
							left: ($(window).width()/2) - ($("#frontPageImage").width()/2) + "px"
								},500, function(){
									
									});
}






  $("#loading").css("display","none");
        $("#gallery").css("visibility","visible");
	$(".galleryImage").css("visibility","visible");


attachEnlarge();

$("#imgHolder").click(function(){

shrink();
});


//attach click properties to download and close pic links
$("#downloadLink").click(function(){download($('img.imgHolderImage').attr('src'))
});
$("#closePic").click(function(){shrink()
});


$('img.next').click(function(){
shrink();
});
$('img.prev').click(function(){
shrink();
});

var maxH = $("#screen").height()-128;
$("img.galleryImage").each(function(){

if ($(this).height() > ($("#screen").height()-128)){
$(this).css("height",maxH);
}
$(this).css("visibility","visible");
});


						});



   }
 
   /* for Mozilla */
   if (document.addEventListener) {
       document.addEventListener("DOMContentLoaded", init, false);
   }
 
   /* for Internet Explorer */

   

 
   /* for other browsers */
   $(window).onload = init;


