$.gallery = { images: Array(), default_width: 300, default_height: 200, current_image: 0, initialize: function() { if ($("#gallery_overlay").length < 1) { $("body").append(""); $("body").append( "" ); } width = 500; $("#gallery_overlay").click(function() {$.gallery.hide()}); $("#btnClose").click(function() {$.gallery.hide()}); $("#gallery_overlay").css("opacity", 0); $("#gallery_overlay").css("z-index", 2000); $("#gallery_overlay").css({ position: "relative", position: "absolute", left: "0", right: "0", top: "0", bottom: "0", width: "100%", height: $(document).height(), background: "black", display: "none" }); if ($.browser.msie) $("#gallery_overlay").css("width", $(window).width()); $(document).keydown( function( e ) { if (e == null) { // ie keycode = event.keyCode; } else { // mozilla keycode = e.which; } if(keycode == 27) // close $.gallery.hide() }); //$("#gallery_content_wrapper").click(function() {$.gallery.hide()}); $("#gallery_content_wrapper").css({ position: "relative", position: "absolute", top: "200px", left: "0", width: "100%", height: "auto", zIndex: "2001" }); $("#gallery_content").css({ position: "relative", background: "white", margin: "0px auto", width: $.gallery.default_width, height: $.gallery.default_height, display: "none" }); $("#gallery_content_inner").css({ position: "static", background: "white", overflow: "hidden", padding: "1px", textAlign: "left" }); $("#gallery_loader").css({ position: "relative", position: "absolute", bottom: "20px", display: "none", left: "0px", right: "0px", height: "22px", background: "url('images/ajax-loader.gif') 50% 50% no-repeat" }); $("#gallery_close_button").css({ position: "relative", position: "absolute", width: "100%", height: "15px", left: "0px", bottom: "8px", textAlign: "center", zIndex: "100" }); $("#gallery_content_inner .gallery_button").css({ position: "relative", position: "absolute", cursor: "pointer", width: "21px", height: "21px", top: "10px", zIndex: 2002 }); $("#gallery_content_inner .gallery_button").css("opacity", 0); $("#gallery_content_inner").hover( function() { $(".gallery_button", this).stop(true).fadeTo("fast", 1); }, function() { $(".gallery_button", this).stop(true).fadeTo("fast", 0); } ); $("#gallery_close").css({ position: "absolute", right: "0px", top: "5px", overflow: "hidden", textAlign: "right", zIndex: 2003 }); $("#btnClose").css({ color: "#666666", textAlign: "right", zIndex: 2004 }); $(window).scroll(function(){ var new_top = ($(window).height() - $("#gallery_content_wrapper").height()) / 2 + $(window).scrollTop(); $('#gallery_overlay').css("top", $(window).scrollTop()); $("#gallery_content_wrapper").css("top", new_top); }); }, showURL: function(width, height, url) { $.gallery.initialize(); $.gallery.resize(width, height); $("#gallery_content_inner *").not(".gallery_button").remove(); $("#gallery_overlay").show().css("opacity", 0.7); $("#gallery_content").fadeIn("fast", function() { $("#gallery_content_inner").html(""); }); }, showHTML: function(width, height, html, iframe, adjustSize) { iframe = iframe || false; adjustSize = adjustSize || false; $.gallery.initialize(); $.gallery.resize(width, height); $("#gallery_content_inner *").not(".gallery_button").remove(); $("gallery_loader").hide(); $(".gallery_button").hide(); $("#gallery_overlay").show().css("opacity", 0.7); $("#gallery_content").fadeIn("fast", function() { if (iframe) { $("#gallery_content_inner").append(""); } else { $("#gallery_content_inner").append(html); } if (adjustSize) $.gallery.resize(html.width(), html.height()); }); }, show: function(img, start) { //$.gallery.initialize(); $.gallery.images = new Array(); $.gallery.images[0] = img; $.gallery.current_image = 0; /*$(selector).each(function() { $.gallery.images[$.gallery.images.length] = $(this).attr("href"); if ($(start).attr("href") == $(this).attr("href")) $.gallery.current_image = $.gallery.images.length-1; }); */ $("#gallery_content").css({width: $.gallery.default_width, height: $.gallery.default_height}); $("#gallery_overlay").show().css("opacity", 0.7); $("#gallery_content").fadeIn("fast", function() { $.gallery.loadCurrentImage(); }); },/* show: function(selector, start) { $.gallery.initialize(); $.gallery.images = new Array(); $(selector).each(function() { $.gallery.images[$.gallery.images.length] = $(this).attr("href"); if ($(start).attr("href") == $(this).attr("href")) $.gallery.current_image = $.gallery.images.length-1; }); $("#gallery_content").css({width: $.gallery.default_width, height: $.gallery.default_height}); $("#gallery_overlay").show().css("opacity", 0.7); $("#gallery_content").fadeIn("fast", function() { $.gallery.loadCurrentImage(); }); }, */ loadCurrentImage: function() { $("#gallery_loader").show(); $(".gallery_button").show(); var img = new Image(); img.onerror = function() { $("#gallery_loader").hide(); } img.onload = function() { $("#gallery_loader").hide(); //$('html').css('overflow-y', 'hidden'); /* Get the layer that is visible now */ current_layer = $("#gallery_content_inner .image:first"); /* Add the new layer on top */ if ($.browser.msie) top_layer = $("
"); else top_layer = $("
"); $(top_layer).css("opacity", 0); $("#gallery_content_inner").append(top_layer); /* We need to do some checks to see what layer should be visible during resize in order not to show padding */ if ($(current_layer).height() > img.height) { /* Old layer is higher, so resize before showing new layer */ $.gallery.resize($(current_layer).width(), img.height, function() { if ($(current_layer).width() > img.width) { $.gallery.resize(img.width, img.height, function() { $(top_layer).fadeTo("fast", 1.0, function() { $(current_layer).remove(); }); }); } else { $(top_layer).fadeTo("fast", 1.0, function() { $.gallery.resize(img.width, img.height, function() { $(current_layer).remove(); }); }); } }); } else { /* Old layer is smaller, now check for widths */ if ($(current_layer).width() > img.width) { /* Old layer is wider, so resize before showing new layer */ $.gallery.resize(img.width, $(current_layer).height(), function() { $(top_layer).fadeTo("fast", 1.0, function() { $(current_layer).remove(); $.gallery.resize(img.width, img.height, function() { }); }); }); } else { /* Old layer is less wide, so show the new layer and then resize */ $(top_layer).fadeTo("fast", 1.0, function() { $.gallery.resize(img.width, img.height, function() { $(current_layer).remove(); }); }); } } }; img.src = $.gallery.images[$.gallery.current_image]; }, next: function() { $.gallery.current_image = ($.gallery.current_image+1)%$.gallery.images.length; $.gallery.loadCurrentImage(); }, previous: function() { $.gallery.current_image = $.gallery.current_image-1; if ($.gallery.current_image < 0) $.gallery.current_image = $.gallery.images.length-1; $.gallery.loadCurrentImage(); }, hide: function(callback) { //$('html').css('overflow-y', 'auto'); $("#gallery_content").fadeOut(10, function() { $("#gallery_content_inner *").not(".gallery_button").remove(); $("#gallery_overlay").hide(); if (callback) callback(); }); }, resize: function(width, height, callback) { width = Math.min(800, width); height = Math.min(600, height); var padding = parseInt($("#gallery_content_inner").css("padding")); width += 2 * padding; height += 2 * padding; var new_top = ($(window).height() - height) / 2 + $(window).scrollTop(); $("#gallery_content_inner .gallery_button").css({top: height / 2 - 10}); if ($.browser.msie) { $("#gallery_content_wrapper").css({top: new_top, left: 0}, "fast"); } else { $("#gallery_content_wrapper").stop(true).animate({top: new_top, left: 0}, "fast"); } if ($.browser.msie) { $("#gallery_content").css({width: width, height: height}); if (callback) callback(); } else { $("#gallery_content").stop(true).animate({width: width, height: height}, "fast", callback); } } }