(function($){var options={};var loaded=false;var ie=$.browser.msie;var cssFixedSupport=!ie||ie&&document.compatMode=="CSS1Compat"&&window.XMLHttpRequest;$.showtime=function(data,settings){if(!loaded){$.extend(options,$.showtime.settings,settings);$(document).bind('keydown.showtime',function(e){if(e.keyCode==27){$.showtime.close();}
return true;});if(data.loading||$.isFunction(data)){options.modalOverlay=true;}
if(ie){$('div#showtime').css('borderColor','#525252');}
var currentScrollTop=$('html').scrollTop();$(document).bind('showtime.complete',function(){$('html').animate({scrollTop:currentScrollTop},{duration:'fast',complete:function(){options.callBack();$(document).unbind('showtime.complete');}});return true;});$('html').animate({scrollTop:0},{duration:'fast',complete:function(){showOverlay(function(){if(data.loading){showLoading();}else{showLoading(function(){if(data.ajax){addExternalData(data.ajax);}else if(data.image){addImage(data.image);}else if(data.imageGallery){imageGallery(data.imageGallery);}else if(data.div){addDiv(data.div);}else if($.isFunction(data)){data.call($);}else{addString(data);}});}
loaded=true;});}});}
return loaded;}
$.extend($.showtime,{settings:{opacity:0.6,maxWidth:550,overlay:true,loading:true,modalOverlay:false,ajaxMethod:'post',callBack:function(){}},defaults:{loadingMessage:'Loading, please wait...',loadingImage:'../refs/images/loading.gif',closeImage:'../refs/images/closelabel.gif',backgroundImage:'../refs/images/b.png',showtimeHtml:'\
    <div id="showtime"> \
     <div id="showtime_container"> \
      <div id="showtime_content"></div> \
      <div id="showtime_footer"> \
       <div id="showtime_footer_buttons"> \
        <img id="close_button" src="" alt="Close Button" /> \
       </div> \
      </div> \
     </div> \
    </div>'},init:function(defaults){if(options.inited){return true;}else{options.inited=true;$.extend(options,$.showtime.settings,{});$.extend($.showtime.defaults,defaults);$('body').append($.showtime.defaults.showtimeHtml);var imageCache=[new Image(),new Image(),new Image()];imageCache[0].src=$.showtime.defaults.backgroundImage;imageCache[1].src=$.showtime.defaults.closeImage;imageCache[2].src=$.showtime.defaults.loadingImage;$('div#showtime').css('backgroundImage','url('+imageCache[0].src+')');$('#close_button').attr('src',$.showtime.defaults.closeImage);$('#close_button').click(function(){$.showtime.close();});}},setDefaults:function(defaults){$.extend($.showtime.defaults,defaults);return true;},showNextImage:function(){if(options.imageGallery.length>options.nextImage){var $img=options.imageGallery[options.nextImage];options.nextImage=options.nextImage+1;var $showtime=$('#showtime');var $container=$('#showtime_container');var $content=$('#showtime_content');var $footer=$('#showtime_footer');var footerHeight=$footer.outerHeight(true);var contentWidth=$img.width+'px';var contianerWidth=$img.width+20+'px';var totalWidth=$img.width+40;var contentHeight=$img.height+'px';var contianerHeight=$img.height+20+footerHeight+'px';var marginLeft=(totalWidth/2)*-1;var showtimeStyle={marginLeft:marginLeft,top:'5%',left:'50%'};var containerStyle={width:contianerWidth,height:contianerHeight};var contentStyle={width:contentWidth,height:contentHeight};var html='<div id="current_image" style="text-align: center;"><img src="'+$img.src+'" alt="" /></div>';$footer.fadeOut('fast');$content.fadeOut('fast',function(){$('#showtime_content').empty().append(html);$showtime.animate(showtimeStyle,'slow').fadeIn('slow');$container.animate(containerStyle,{duration:'slow',complete:function(){$content.css(contentStyle);$container.children().fadeIn('slow');}});});if(options.nextImage<options.imageGallery.length){var img=new Image();img.src=options.imageGallery[options.nextImage].src;}}},close:function(){$(document).unbind('keydown.showtime');hideDialog(function(){hideOverlay(function(){loaded=false;$('div#show_loading').remove();$('div#showtime_container').css({width:'',height:''});$('div#showtime_content').css({width:'',height:''});$(document).trigger('showtime.complete');});});}});$.fn.showtime=function(defaults){$.showtime.init(defaults);if($(this).length==0){return;}
var clickController=function(){var loaded=false;if(!loaded){var href=this.href;$.extend(options,$.showtime.settings,{});if(ie){$('div#showtime').css('borderColor','#525252');}
$(document).bind('keydown.showtime',function(e){if(e.keyCode==27){$.showtime.close();}
return true;});var currentScrollTop=$('html').scrollTop();$(document).bind('showtime.complete',function(){$('html').animate({scrollTop:currentScrollTop},{duration:'fast',complete:function(){options.callBack();$(document).unbind('showtime.complete');}});return true;});$('html').animate({scrollTop:0},{duration:'fast',complete:function(){showOverlay(function(){showLoading(function(){addExternalData(href);});});}});loaded=true;}
return false;}
return this.bind('click.showtime',clickController);}
function showOverlay(callback){if(!options.overlay){return;}
var cssAttributes;var closeFunction;if($('div#show_overlay').length==0){$('body').append('<div id="show_overlay"></div>');}
if(cssFixedSupport){cssAttributes={opacity:options.opacity};}else{cssAttributes={position:'absolute',opacity:options.opacity,height:getDocumentHeight(),width:$('body').outerWidth(true)};}
if(!options.modalOverlay){closeFunction=function(){$.showtime.close();};}else{closeFunction=function(){};}
$('div#show_overlay').hide().addClass("overlayShow").css(cssAttributes).click(closeFunction).fadeIn('slow',function(){if(callback){callback.call();}});}
function hideOverlay(callback){if(!options.overlay){return;}
var $overlay=$('div#show_overlay');$overlay.fadeOut('slow',function(){$overlay.removeClass("overlayShow");$overlay.addClass("overlayHide");$overlay.remove();if(callback){callback.call();}});}
function showLoading(callback){if(!options.loading){return;}
var loadingHTML='<div id="show_loading"><img height="15" width="15" src="'+$.showtime.defaults.loadingImage+'"/> <span>'+$.showtime.defaults.loadingMessage+'</span></div>';$('div#showtime_container').children().hide().end().append(loadingHTML);var leftMargin=(($('div#showtime').outerWidth()/2)*-1);$('div#showtime').css({position:cssFixedSupport?'fixed':'absolute',marginLeft:leftMargin,top:'5%',left:'50%'}).fadeIn('fast',function(){if(callback){callback.call();}});}
function showDialog(elemStyle){var containerWidth;var containerHeight;var contentWidth;var contentHeight;var totalWidth;var $showtime=$('div#showtime');var $container=$('div#showtime_container');var $content=$('div#showtime_content');var $footer=$('div#showtime_footer');var paddingLeft=parseInt($content.css('paddingLeft'),10);var paddingRight=parseInt($content.css('paddingRight'),10);var paddingTop=parseInt($content.css('paddingTop'),10);var paddingBottom=parseInt($content.css('paddingBottom'),10);var borderLeft=parseInt($showtime.css('borderLeftWidth'),10);var borderRight=parseInt($showtime.css('borderRightWidth'),10);var footerHeight=$footer.outerHeight(true);var minWidth=parseInt($container.css('width'),10);var minHeight=parseInt($content.css('height'),10);var maxWidth=options.maxWidth;var effWidth=elemStyle.width+paddingLeft+paddingRight;var effHeight=elemStyle.height+paddingTop+paddingBottom;if(effWidth>maxWidth){contentWidth=maxWidth-paddingLeft-paddingRight+'px';contianerWidth=maxWidth+'px';totalWidth=maxWidth+borderLeft+borderRight;}else if(effWidth>minWidth){contentWidth=elemStyle.width+'px';contianerWidth=effWidth+'px';totalWidth=effWidth+borderLeft+borderRight;}else{contentWidth=minWidth-paddingLeft-paddingRight+'px';contianerWidth=minWidth+'px';totalWidth=minWidth+borderLeft+borderRight;}
if(effHeight>minHeight){contentHeight=elemStyle.height+'px';contianerHeight=effHeight+footerHeight+'px';}else{contentHeight=minHeight+'px';contianerHeight=minHeight+paddingTop+paddingBottom+footerHeight+'px';}
var marginLeft=(totalWidth/2)*-1;var showtimeStyle={marginLeft:marginLeft,top:'5%',left:'50%'};var containerStyle={width:contianerWidth,height:contianerHeight};var contentStyle={width:contentWidth,height:contentHeight,fontSize:elemStyle.fontSize};$showtime.css('position','absolute');$showtime.animate(showtimeStyle,{duration:'slow',complete:function(){$('div#show_loading').remove();if(!cssFixedSupport){if($('div#show_overlay').length>0){$('div#show_overlay').animate({height:getDocumentHeight()},{duration:'fast'});}}}}).fadeIn('slow');$container.animate(containerStyle,{duration:'slow',complete:function(){$content.css(contentStyle);$container.children().fadeIn('slow');}});}
function hideDialog(callback){$('div#showtime').fadeOut('slow',function(){$('div#showtime_content').removeClass().addClass('content');if(callback){callback.call();}});}
function addImage(href){var img=new Image();img.src=href;var html='<div id="current_image" style="text-align: center;"><img src="'+img.src+'" alt="" /></div>';$('#showtime_content').empty().append(html);img.onload=function(){showDialog({width:img.width,height:img.height});}}
function imageGallery(container){var $images=$(container).children();var $firstImage=$images[0].src;options.imageGallery=$images;if($images.length>1){options.nextImage=1;$('#showtime_container').append('<img id="prev_button" src="refs/images/showtime/prev.gif" /><img id="next_button" src="refs/images/showtime/next.gif" onclick="$.showtime.showNextImage();" />');}
addImage($firstImage);}
function addDiv(id){var $div=$(id);if(id.match(/#/)){$('#showtime_content').empty().append($div.html());showDialog({width:$div.width(),height:$div.height(),fontSize:$div.css('fontSize')});}}
function addExternalData(href){var $container=$('div#showtime_container');var $content=$('div#showtime_content');if(href.match(/#/)){var div=href.substring(href.indexOf('#'));addDiv(div);}else{if(options.ajaxMethod=='post'){$.post(href,function(data){$content.empty().append(data);showDialog({width:$container.outerWidth(),height:$container.outerHeight()});});}else{$.get(href,function(data){$content.empty().append(data);showDialog({width:$container.outerWidth(),height:$container.outerHeight()});});}}}
function addString(str){var $content=$('div#showtime_content');$content.empty().append(str);$content.css('fontWeight','bold');showDialog({width:$content.width(),height:$content.outerHeight()});}
function getDocumentHeight(){var db=document.body;var dde=document.documentElement;return Math.max(db.scrollHeight,dde.scrollHeight,db.offsetHeight,dde.offsetHeight,db.clientHeight,dde.clientHeight);}})(jQuery);