
jQuery.greybox=function(options){this.settings=jQuery.extend({id:null,height:400,width:400,animation:false,overlay_clickable:true,callback:null,caption:""},options||{});this.overlay_id="GB_overlay_"+this.settings.id;this.window_id="GB_window_"+this.settings.id;this.caption_id="GB_caption_"+this.settings.id;this.frame_id="GB_frame_"+this.settings.id;this.closebutton_id="GB_closebutton_"+this.settings.id;this.generate_iframe=function(url,overflow,align){if(overflow)overflow=" style='overflow:"+overflow+";' ";else overflow="";if(align)align=" align='"+align+"'";else align="";return"<iframe"+overflow+align+" name='"+this.frame_id+"' id='"+this.frame_id+"' class='GB_frame' src='"+url+"'></iframe>";}
this.overlay_size=function(event){var that;if(!this.settings&&event){that=event.data.greyboxObject;}else{that=this;}
var w=jQuery(document).width();var h=jQuery(document).height();jQuery("#"+that.overlay_id).css({"height":h+"px","width":w+"px"});}
this.position=function(event){var that;if(!this.settings&&event){that=event.data.greyboxObject;}else{that=this;}
var w=jQuery(window).width();var h=jQuery(window).height();var offsetTop=jQuery(window).scrollTop();var offsetLeft=jQuery(window).scrollLeft();jQuery("#"+that.window_id).css({width:that.settings.width+"px",height:that.settings.height+"px",left:(offsetLeft+(w-that.settings.width)/2)+"px",top:(offsetTop+(h-that.settings.height)/2)+"px"});jQuery("#"+that.frame_id).css("height",(that.settings.height-32)+"px");}
this.updatePosition=function(event){var that;if(!this.settings&&event){that=event.data.greyboxObject;}else{that=this;}
var w=jQuery(window).width();var h=jQuery(window).height();var offsetTop=jQuery(window).scrollTop();var offsetLeft=jQuery(window).scrollLeft();jQuery("#"+that.window_id).css({left:(offsetLeft+(w-that.settings.width)/2)+"px",top:(offsetTop+(h-that.settings.height)/2)+"px"});}
this.resize=function(width,height){this.settings.width=width;this.settings.height=height;this.position();}
this.close=function(event){var that;if(!this.settings&&event){that=event.data.greyboxObject;}else{that=this;}
jQuery("#"+that.window_id+","+"#"+that.overlay_id).remove();if(that.settings.callback&&typeof(that.settings.callback)=="function"){that.settings.callback.apply();}}
this.show=function(html){jQuery(document.body).append("<div id='"+this.overlay_id+"' class='GB_overlay'></div>"+"<div id='"+this.window_id+"' class='GB_window'>"+"<div id='"+this.caption_id+"' class='GB_caption'></div>"+"<div id='"+this.closebutton_id+"' class='GB_closebutton'>&nbsp;</div>"+"</div>");jQuery("#"+this.closebutton_id).bind("click",{greyboxObject:this},this.close);if(this.settings.overlay_clickable){jQuery("#"+this.overlay_id).bind("click",{greyboxObject:this},this.close);}
jQuery(window).bind("scroll",{greyboxObject:this},this.updatePosition);jQuery(window).bind("resize",{greyboxObject:this},this.updatePosition);jQuery(window).bind("resize",{greyboxObject:this},this.overlay_size);this.overlay_size();jQuery("#"+this.window_id).append(html);jQuery("#"+this.caption_id).html(this.settings.caption);jQuery("#"+this.overlay_id).show();this.position();if(this.settings.animation){jQuery("#"+this.window_id).slideDown("slow");}else{jQuery("#"+this.window_id).show();}}};
