(function(b){b.fn.smart_modal=function(e){return this.each(function(){if(this._sm){return}if(typeof(e)!="undefined"){var f=b.extend({},b.fn.smart_modal.defaults,e)}else{var f=b.fn.smart_modal.defaults}if(typeof(sm_count)=="undefined"){sm_count=0}sm_count++;this._sm=sm_count;a[sm_count]={config:f,target_sm:this};b(this).smart_modal_add_show(this)})};b.fn.smart_modal_add_show=function(e){return b.smart_modal.show(e)};b.fn.smart_modal_show=function(){return this.each(function(){b.smart_modal.open(this)})};b.fn.smart_modal_hide=function(){return this.each(function(){b.smart_modal.hide(this,true)})};b.fn.smart_modal.defaults={show:false,hide:false,modal_styles:{display:"block",zIndex:7777779},resize:true,hide_on_overlay_click:true};b.smart_modal={hash:{},show:function(f){var g=f._sm,e=a[g];d(e.target_sm).click(function(){b.smart_modal.open(f);return false});return false},hide:function(g,f){var k=g._sm,e=a[k];if(e.config.hide_on_overlay_click){var j="#sm_olay, .sm_close"}else{var j=".sm_close"}if(f){b.smart_modal.remove(g)}d(j).click(function(){b.smart_modal.remove(g);return false})},remove:function(f){var g=f._sm,e=a[g];d("#sm_content").remove();d("#sm_olay").remove();if(e.config.hide){e.config.hide()}},open:function(f){var j=f._sm;var e=a[j];b.smart_modal.insert_overlay();b.smart_modal.insert_content_container();var g=b.smart_modal.get_content(b(e.target_sm));d("#sm_content").html(g);if(e.config.modal_styles){d("#sm_content").css(e.config.modal_styles)}if(e.config.resize){b.smart_modal.resize_container()}b.smart_modal.for_ie(d("#sm_olay"));if(e.config.show){e.config.show()}b.smart_modal.hide(f)},resize_container:function(){var f=0,e=0;d("#sm_content *").load(function(){d("#sm_content *").each(function(){var g=d(this).outerWidth(),h=d(this).outerHeight();if(g>f){f=g}e+=h});if(f>0&&e>0){d("#sm_content").css("width",(f+d("#sm_content .sm_close:first").outerWidth())+"px").css("height",(e)+"px").css("margin-left","-"+(f/2)+"px")}})},insert_overlay:function(){if(!d("#sm_olay").length){d("body").append('<div id="sm_olay"></div>')}d("#sm_olay").css({height:"100%",width:"100%",position:"fixed",left:0,top:0,"z-index":7777778,opacity:50/100})},insert_content_container:function(){if(!d("#sm_content").length){d("body").append('<div id="sm_content"></div>')}},get_content:function(e){c="<div class='sm_close'><p>close</p></div>";if(e.attr("rel")){div_id=d("#"+e.attr("rel"));div_class=d("."+e.attr("rel"));if(div_id.length){c+=div_id.html()}else{if(div_class.length){c+=div_class.html()}}}else{if(e.attr("href")){if(e.attr("title")){c+="<h3 class='sm_title'>"+e.attr("title")+"</h3><img src='"+e.attr("href")+"' alt='"+e.attr("title")+"' />"}else{c+="<img src='"+e.attr("href")+"' alt='sm_modal' />"}}else{c=c+e.html()}}return c},for_ie:function(e){if(ie6&&b("html,body").css({height:"100%",width:"100%"})&&e){b("html,body").css({height:"100%",width:"100%"});i=b('<iframe src="javascript:false;document.write(\'\');" class="overlay"></iframe>').css({opacity:0});e.html('<p style="width:100%;height:100%"/>').prepend(i);e=e.css({position:"absolute"})[0]}}};var a=b.smart_modal.hash,d=jQuery;ie6=b.browser.msie&&(b.browser.version=="6.0")})(jQuery);
