function PhotoGallery(){this.data=new Object();this.currentImageId=0;this.currentFirstImage=0;this.currentLastImage=0;this.maxHeight=386;this.maxWidth=579}var photogallery=new PhotoGallery();function ShowBigImage(){$imageAsset=$(".imageAsset",$("#gallery"));if($imageAsset.children("img").is(":hidden")){$(".links #cancelcard").trigger("click")}$imageAsset.children("img").remove();$imageAsset.addClass("loading1");var a="imageid-"+photogallery.currentImageId;var b=new Image();$(b).load(function(){$(this).hide();if(parseInt(splitString($(this).attr("id")),10)==photogallery.currentImageId){$imageAsset.removeClass("loading1").append(this);$("#postcardemail input[name=image_height]").val(b.height);$("#postcardemail input[name=image_width]").val(b.width);$imageAsset.css({height:photogallery.maxHeight+"px",width:photogallery.maxWidth+"px"});if(b.width>b.height){$imageAsset.children("img").css({width:photogallery.maxWidth+"px",height:Math.ceil((b.height/b.width)*photogallery.maxWidth)+"px"})}else{$imageAsset.children("img").css({height:photogallery.maxHeight+"px",width:Math.ceil((b.width/b.height)*photogallery.maxHeight)+"px"})}$(this).fadeIn();$("#postcardemail input[name=image_url]").val($imageAsset.children("img").attr("src"))}}).error(function(){alert("Unable to Load image, please reload the image by clicking the Thumbnail. ")}).attr("id",a).attr("src",ParsePhotoURL(global.SERVER+"/"+photogallery.data[photogallery.currentImageId].photo,"m"));InsertRelatedInfo()}var RenderGallery=function(){$carousel=$(".carousel",$("#gallery"));if(photogallery.data.length<12){$carousel.attr("align","center")}$("#pageloader").css("height",$("body").height());$("#pageloader").show();$("#gallery").show();window.scrollTo(0,0);$(".imageAsset",$("#gallery")).children("img").remove();$carousel.children("ul").remove();photogallery.currentImageId=parseInt(splitString($("#imageholder").children("img").attr("id")),10);ShowBigImage();var a="<ul>";$.each(photogallery.data,function(b,c){a+="<li><div><img id='thumbid-"+b+"' class='thumbs' src='/"+ParsePhotoURL(c.photo,"s")+"' /></div></li>"});a+="</ul>";$carousel.append(a);$carousel.children("ul").width(photogallery.data.length*71);$carousel.find("img").unbind("click").bind("click",function(){photogallery.currentImageId=parseInt(splitString($(this).attr("id")),10);RenderState();ShowBigImage()});if(photogallery.currentImageId>=photogallery.currentLastImage){FindCorrectImage()}RenderState();InsertRelatedInfo();return false};function FindCorrectImage(){while(photogallery.currentImageId!=photogallery.currentLastImage){photogallery.currentLastImage++;photogallery.currentFirstImage++}var a=(photogallery.currentLastImage-11)*-71;$(".carousel ul",$("#gallery")).css("margin-left",a+"px")}function RenderState(){$(".carousel div",$("#gallery")).removeClass("selected");$(".carousel #thumbid-"+photogallery.currentImageId,$("#gallery")).parent().addClass("selected");if(photogallery.currentImageId==0){$("#prevImageButton").addClass("deactivated")}else{$("#prevImageButton").removeClass("deactivated")}if(photogallery.currentFirstImage==0){$("#prevGroupButton").addClass("deactivated")}else{$("#prevGroupButton").removeClass("deactivated")}if((photogallery.data.length-1)==photogallery.currentImageId){$("#nextImageButton").addClass("deactivated")}else{$("#nextImageButton").removeClass("deactivated")}if(photogallery.currentLastImage>=photogallery.data.length-1){$("#nextGroupButton").addClass("deactivated")}else{$("#nextGroupButton").removeClass("deactivated")}}function InsertRelatedInfo(){$("#gallery .caption, #imageholder .caption").empty().append("<label>"+photogallery.data[photogallery.currentImageId].title+"</label>");$("#gallery .mediaCredit .name, #imageholder .mediaCredit .name").empty().append("<label>"+photogallery.data[photogallery.currentImageId].owner+"</label>");$("#gallery .shortintro .name, #imageholder .shortintro .name").empty().append("<label>"+photogallery.data[photogallery.currentImageId].owner+"</label>");$("#imageholder .flickr-link, #gallery .flickr-link").children("a").attr("href","http://"+photogallery.data[photogallery.currentImageId].originalurl)}function RenderAlbumFunctions(){if(photogallery.data.length){photogallery.currentFirstImage=0;photogallery.currentLastImage=11;InsertRelatedInfo();$imageholder=$("#imageholder");$carousel=$(".carousel",$("#gallery"));$imageAsset=$(".imageAsset",$("#gallery"));$gallery=$("#gallery");$("#icon_holder div").bind("click",function(){$imageholder.children("img").remove();photogallery.currentImageId=parseInt(splitString($(this).children("img").attr("id")),10);$imageholder.append("<img src='/"+ParsePhotoURL(photogallery.data[photogallery.currentImageId].photo,"m")+"' id='imageid-"+photogallery.currentImageId+"' />");$("#icon_holder").children("div").removeClass("selected");$(this).addClass("selected");InsertRelatedInfo()});$imageholder.find(".galleryLink a").bind("click",RenderGallery);$imageholder.hover(function(){$imageholder.find(".shortintro").hide();$imageholder.find(".infoHoverContent").show();$imageholder.find(".infoHoverBG").fadeTo("fast",0.5).show()},function(){$imageholder.find(".infoHoverBG").fadeOut("fast");$imageholder.find(".shortintro").show();$imageholder.find(".infoHoverContent").hide()});$("#close_gallery").bind("click",function(){$("#gallery").fadeOut("normal",function(){$("#pageloader").hide()})});$("#nextImageButton").click(function(){if(!($(this).hasClass("deactivated")||$(this).hasClass("temp-deactivated"))){photogallery.currentImageId=parseInt(splitString($imageAsset.children("img").attr("id")),10);photogallery.currentImageId++;$carousel.find("#thumbid-"+(photogallery.currentImageId-1)).parent().removeClass("selected");if(photogallery.currentImageId>photogallery.currentLastImage){$("#nextGroupButton").trigger("click")}else{RenderState()}ShowBigImage()}});$("#prevImageButton").click(function(){if(!($(this).hasClass("deactivated")||$(this).hasClass("temp-deactivated"))){photogallery.currentImageId=parseInt(splitString($imageAsset.children("img").attr("id")),10);photogallery.currentImageId--;$carousel.find("#thumbid-"+(photogallery.currentImageId+1),$("#gallery")).parent().removeClass("selected");if(photogallery.currentImageId<photogallery.currentFirstImage){$("#prevGroupButton").trigger("click")}else{RenderState()}ShowBigImage()}});$("#prevGroupButton").click(function(){if(!($(this).hasClass("deactivated")||$(this).hasClass("temp-deactivated"))){$("#prevGroupButton").addClass("deactivated");$("#nextGroupButton").removeClass("deactivated");var a=parseInt($carousel.children("ul").css("margin-left"),10)+$carousel.find("li").width()+"px";$carousel.children("ul").animate({marginLeft:a},"normal",function(){$("#prevGroupButton").removeClass("deactivated");photogallery.currentFirstImage--;photogallery.currentLastImage--;RenderState()})}});$("#nextGroupButton").click(function(){if(!($(this).hasClass("deactivated")||$(this).hasClass("temp-deactivated"))){$("#nextGroupButton").addClass("deactivated");$("#prevGroupButton").removeClass("deactivated");var a=parseInt($carousel.children("ul").css("margin-left"),10)-$carousel.find("li").width();$carousel.children("ul").animate({marginLeft:a},"normal",function(){$("#nextGroupButton").removeClass("deactivated");photogallery.currentFirstImage++;photogallery.currentLastImage++;RenderState()})}});$imageAsset.hover(function(){if($("#sendecard").is(":hidden")){$imageAsset.find(".shortintro").hide();$imageAsset.find(".infoHoverContent").show();$imageAsset.find(".infoHoverBG").fadeTo("fast",0.5).show()}},function(){$imageAsset.find(".infoHoverBG").fadeOut("slow");$imageAsset.find(".infoHoverContent").hide();$imageAsset.find(".shortintro").show()});$imageAsset.find(".pictopia-link p").click(function(){$gallery.find(".arrow").addClass("temp-deactivated");$imageAsset.data("imagewidth",$imageAsset.children("img").css("width"));$imageAsset.children("img").animate({width:"0px"},"fast",function(){$imageAsset.children("img").hide();$("#sendecard").show();var a=$imageAsset.width();$("#sendecard").animate({width:a},"fast")})});$("#cancelcard").click(function(){$gallery.find(".arrow").removeClass("temp-deactivated");$imageAsset.find("table.postcard_table input[type=text], table.postcard_table textarea").attr("value","");$("#sendecard").animate({width:"0px"},"fast",function(){$("#sendecard").hide();$imageAsset.children("img").show();$imageAsset.children("img").animate({width:$imageAsset.data("imagewidth")},"fast",function(){$("#sendecard input.errorclass").removeClass("errorclass")})})});$("#close_gallery").hover(function(){$(this).css("background","url(/static/images/close_button_red.gif) top left no-repeat")},function(){$(this).css("background","url(/static/images/close_button.gif) top left no-repeat")})}}var renderAlbum=function(data){photogallery.data=eval(data);if(photogallery.data.length){for(var i=0;i<photogallery.data.length;i++){if(photogallery.data[i].weight==10){photogallery.currentImageId=i;$("<img id='imageid-"+i+"' src='/"+ParsePhotoURL(photogallery.data[i].photo,"m")+"' />").appendTo("#imageholder");$("<div><img id='imageid-"+i+"' src='/"+ParsePhotoURL(photogallery.data[i].photo,"s")+"' /></div>").appendTo("#icon_holder");break}}for(var i=0;i<photogallery.data.length;i++){if($("#icon_holder").children("div").length<4){if(photogallery.data[i].weight!=10){$("<div><img id='imageid-"+i+"' src='/"+ParsePhotoURL(photogallery.data[i].photo,"s")+"' /></div>").appendTo("#icon_holder")}}else{break}}$("#icon_holder").children("div:even").addClass("thumbsleft");$("#icon_holder").children("div:odd").addClass("thumbsright");$("#icon_holder").children("div:first").addClass("selected")}else{$("#galleryWrap").hide()}RenderAlbumFunctions()};$(document).ready(function(){$.get(global.SERVER+"/ajax/album/"+MODEL+"/"+PHOTO_OBJECT_ID+"/*/*/*/",renderAlbum)});