 
var modalWindow = {written:false,isVisible:false,onclose:null,ext:'png'};

//SHOW A CENTERED modalBox DIV
modalWindow.show = function(url,w,h){
if(!w)w=200;
if(!h)h=150;
if ($.browser.msie &&(v=parseInt($.browser.version,10))&&v< 7 &&v> 4)
modalWindow.ext='gif';

if(!modalWindow.written){
modalWindow.modalContainer = $("<div id='modWcontainer'></div>");
modalWindow.modalContainer.html('<div id="modWmodal">\
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="modTopside" unselectable="on"><tr>\
			<td style="background:transparent URL('+scriptassets+'w1.'+modalWindow.ext+');width:91px !important;height:66px;" unselectable="on">&nbsp;</td>\
			<td style="background:transparent URL('+scriptassets+'w2.'+modalWindow.ext+');height:66px;font-size:4px;" unselectable="on">&nbsp;<div id="modWtilebar"></div></td>\
			<td style="background:transparent URL('+scriptassets+'w3.'+modalWindow.ext+') right top;width:91px !important;height:66px;text-align:center;" unselectable="on"> <a id="modWclose" href="#"  unselectable="on">&nbsp;</a></td>\
</tr></table><table border="0" width="100%" cellspacing="0" cellpadding="0"><tr>\
			<td width="32" valign="top" unselectable="on"><img border="0" src="'+scriptassets+'w4.'+modalWindow.ext+'" width="32" height="100%" unselectable="on"></td>\
			<td id="modWframeHelper"><iframe id="modWframe" frameborder="0" style="margin:0px;padding:0px;width:100%;height:100%;" src="blank.htm"></iframe></td>\
			<td width="32" valign="top" unselectable="on"><img border="0" src="'+scriptassets+'w5.'+modalWindow.ext+'" width="32" height="100%" unselectable="on"></td></tr></table>\
<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr>\
			<td style="background:transparent URL('+scriptassets+'w6.'+modalWindow.ext+');width:91px;height:5px;" unselectable="on"></td>\
			<td style="background:transparent URL('+scriptassets+'w7.'+modalWindow.ext+');height:5px;font-size:4px;line-heigt:0;" unselectable="on">&nbsp;</td>\
<td style="background:transparent URL('+scriptassets+'w8.'+modalWindow.ext+');width:91px;height:5px;" unselectable="on"></td>\
</tr></table></div>');

modalWindow.blackMask = $("<div id='modWoverlay' unselectable='on'></div>");
modalWindow.modalContainer.append(modalWindow.blackMask);
$(document.body).append(modalWindow.modalContainer);

modalWindow.modalBox=$("#modWmodal");
modalWindow.frame=$("#modWframe");
modalWindow.frameHelper=$('#modWframeHelper');

modalWindow.blackMask.css('opacity', 0.7);
modalWindow.blackMask.css("filter", "alpha(opacity=70)");
modalWindow.blackMask.css("z-index", 1000);
 modalWindow.modalBox.css("z-index", 1001);
$('#modWclose').bind('click',modalWindow.hide);
modalWindow.modalBox.draggable({handle:'#modWtilebar',iframeFix:true,grid:[5,5],start:function(){modalWindow.draghelper(1);},stop:function(){modalWindow.draghelper(0);}});
modalWindow.written=true;
}


if(url)
modalWindow.frame.attr('src',url);


modalWindow.frameHelper.width(w+'px');
modalWindow.frameHelper.height(h+'px');
modalWindow.modalBox.width((w+64)+'px');//fixup


if(!modalWindow.isVisible){
modalWindow.blackMask.height($(document).height());
modalWindow.blackMask.show();

modalWindow.modalBox.css("top", Math.max(($(window).height() - (h))*0.5-70+$(document).scrollTop(),0));
modalWindow.modalBox.css("left",  Math.max(($(window).width()- (w+64))*0.5,0));

modalWindow.modalBox.hide();
modalWindow.frame.hide();
if($.browser.msie)
modalWindow.modalBox.slideDown(300,function(){modalWindow.frame.fadeIn('fast');});
else
modalWindow.modalBox.fadeIn(300,function(){modalWindow.frame.fadeIn('fast');});

 //$(this).hide("drop", { direction: "down" }, 1000);


}else{
if(!url){//reposition
modalWindow.modalBox.css("top", Math.max(($(window).height() - (h))*0.5-70+$(document).scrollTop(),0));
modalWindow.modalBox.css("left",  Math.max(($(window).width()- (w+64))*0.5,0));
} 
modalWindow.frame.fadeTo(20,0.5).fadeTo(150,1);


}
modalWindow.isVisible=true;
    return false;
};
//REMOVES A modalBox
modalWindow.draghelper = function(on){
if(on){
modalWindow.frame.fadeTo(150,0).hide();
modalWindow.frameHelper.fadeTo(150,0.7);
}else{
modalWindow.frame.fadeTo(150,1);
modalWindow.frameHelper.fadeTo(150,1);
}
};
//REMOVES A modalBox
modalWindow.hide = function(){
if($.browser.msie)
modalWindow.modalBox.slideUp(300);
else
modalWindow.modalBox.fadeOut(300);
modalWindow.blackMask.delay(300).hide();
modalWindow.isVisible=false;
if(modalWindow.onclose)
modalWindow.onclose();
};


 

