
var isie6= (navigator.userAgent.indexOf('MSIE 6')!=-1);
if(!isie6){
(function($) {
$.modalBox =function(url,options,callback)
{
	$.modalBox.show(url,options,callback);
	
}
$.extend
(
	$.modalBox, 
	{
		options:{},
		content:null,
		show:function(url,options,_callback)
		{
			var _options = $.modalBox.options = {fixed:false,type:"iframe",fitwindow:false};
			//var fixed =false;
			if(typeof options=='object'){
				if(options.type) _options.type  = options.type;
				if(options.fixed)  _options.fixed = options.fixed;
				if(options.fitwindow)  _options.fitwindow = options.fitwindow;
				//_options.fitwindow = true;
			}
			$('#po_wrap').css({position: (options.fixed?'fixed':'absolute'),top:(options.fixed?0:$(window).scrollTop())});
			var obj_content;
			switch(_options.type)
			{
				case "image":
					$('#po_client').html('<img src="'+ url +'" />');
					obj_content = $('#po_client img');
					break;
				case "ajax":
					//$('#po_client').html('<div style="height:'+_options.height+'px;width:'+_options.width+'px" id="po_client_content"></div>');
					$('#po_client').html('<div id="po_client_content"></div>');
					obj_content = $('#po_client_content');
					break;
				default:
					//$('#po_client').html('<iframe  frameborder="0" framespacing="0" width="'+_options.width+'" height="'+_options.height+'" src="'+ url +'"></iframe>');
					if(url.indexOf('?')>0)
						url+= '&modalbox=';
					else
						url+= '?modalbox=';
						
					$('#po_client').html('<iframe  frameborder="0" framespacing="0" src="'+ url +'"></iframe>');
					obj_content = $('#po_client iframe');
					break;
			}
			$.modalBox.content=obj_content;
			$('#po_overlay').fadeIn(200);
			$('#po_wrap').show();
			if(_options.type=='ajax')
			{
				obj_content.load(url,'',function(){
					$("#po_window").show();
				});
				 _po_resize();
			}else
			{
				obj_content.load(function()
				{
					$("#po_window").show();
					if(_options.type!='image')
					{
						this.contentWindow.modal={ 
							callback: _callback,
							frameWindow:this,
							parentWindow:window,
							hide:$.modalBox.hide
						}
						
						var clientWindow = this.contentWindow.document.getElementById('clientWindow');
						if(clientWindow)
						{
							var body=this.contentWindow.document.body;
							body.style.margin = body.style.padding = body.style.border = '0px';
							this.width  = clientWindow.offsetWidth;
							body.scroll = "no" // IE;
							this.height = clientWindow.offsetHeight;
						}else
						{
							this.width  = 700;
							_options.fitwindow=true;
						}
						if(_options.fitwindow)
						{
							$.modalBox.options.fixed=true;
							$('#po_wrap').css({position: 'fixed',top:0});
						}
						
						try{
							this.contentWindow.onmodal();
						}catch(e){}
					}
					 _po_resize();
				});
			}
			 $(window).bind("resize",_po_resize);
			
		},
		hide:function()
		{
			$(window).unbind("resize",_po_resize);
			$('#po_wrap').hide();
			$("#po_window").hide();
			$('#po_overlay').fadeOut(200);
			$('#po_client').html('');
		}
	}
);
var ie = document.all;
function _po_resize()
{
	if($.modalBox.options.fixed!=true)
	{
		if(ie)$("#po_wrap").height($(window).height());		
	}else{
		if($.modalBox.options.fitwindow)
		{
			var h = $(window).height()-80;
			$.modalBox.content.height(h);
			$.modalBox.content.get(0).contentWindow.onresize();
			//alert($.modalBox.content.get(0).tagName)
		}
	}
}
$.fn.modalBox = function(url,options)
{
	
	//if(!isie6) return;
	this.click(function()
	{
		
		if(this.tagName=="A")
		{
			url = this.href;
			re = new RegExp('\.([a-z0-9]*)$', 'i');
			re.exec(url);
			if(options==null)
			{
				options = {type:"iframe"};
				switch(RegExp.$1)
				{
					case 'jpg':
					case 'png':
					case 'jpeg':
					case 'gif':
					case 'bmp':
						options.type="image";
						break;
					case 'flv':
						options.type="flv";
						break;
					default:
						if(this.getAttribute('rel')=='ajax_modal')
							options.type="ajax";
				}
			}
		}
		$.modalBox.show(url,options);
		return false;
	})
	
}
$(document).ready(function(){
	$('body').prepend('<DIV id="po_overlay"></DIV>');
	$('body').prepend('<TABLE id="po_wrap" border=0 CELLSPACING=0 CELLPADDING=0> \
		<TR> \
			<TD align="center" id="po_window_wrap"> \
				<TABLE id=po_window border=0 CELLSPACING=0 CELLPADDING=0> \
					<TR> \
						<TD class="border_tl">&nbsp;</TD> \
						<TD class="border_t">&nbsp;</TD> \
						<TD class="border_tr">&nbsp;</TD> \
					</TR> \
					<TR> \
						<TD class="border_l">&nbsp;</TD> \
						<TD id="po_client" bgcolor=white  valign="top" align="left"> \
						</TD> \
						<TD class="border_r">&nbsp;</TD> \
					</TR> \
					<TR> \
						<TD class="border_bl">&nbsp;</TD> \
						<TD class="border_b">&nbsp;</TD> \
						<TD class="border_br">&nbsp;</TD> \
					</TR> \
				</TABLE> \
			</TD> \
		</TR> \
	</TABLE>');
	$("#po_wrap").hide();
	$("#po_window").hide();
	$('#po_overlay').css('opacity', 0.6);
	$('#po_window_wrap, #po_overlay').mousedown(function(e)
	{
		if(e.target.id=='po_window_wrap' ||e.target.id=='po_overlay'  )
			$.modalBox.hide();
	})
	
});
})(jQuery);

$(document).ready(function(){

	jQuery('a[rel*=modal]').modalBox();
	jQuery('a[rel*=ajax_modal]').modalBox();
	
});

};
