	var $Modal,
		$ModalIFm,
		$ModalBck;
	function Modalresize(){
		var bodyw = $('body').width(),
			bodyh = $('body').height(),
			windw = $(window).width(),
			windh = $(window).height(),
			l = (windw - $Modal.outerWidth() )/2,
			t = (windh - $Modal.outerHeight() )/2;
		if (l<0) l=0;
		if (t<0) t=0;
		l += $(window).scrollLeft();
		t += $(window).scrollTop();
		$Modal.css({left:l,top:t}).show();
		$ModalBck.width( (bodyw < windw ? windw : bodyw) + 'px' )
				.height( (bodyh < windh ? windh : bodyh) + 'px' )
	}
	function openModal(sUrl, x, y, title) {
		$Modal = $('#jsWidget_Modal');
		$ModalIFm = $Modal.find('iframe');
		$ModalBck = $('#jsWidget_ModalBackground');
		$Modal.width(x+'px');
		$ModalIFm.height(y+'px').css({visibility:'hidden'});
		$(window).resize(Modalresize).trigger('resize');
		$ModalBck.fadeTo(0,0).show().fadeTo(150,0.7,function(){
				$ModalIFm.css({visibility:''});
		});
		$ModalIFm.attr('src',sUrl);
		if (title) $Modal.find('.title').html(title);
	}
	function closeModal() {
		$('#jsWidget_Modal, #jsWidget_ModalBackground').hide();
		$('#jsWidget_Modal iframe').removeAttr('src');
		$(window).unbind('resize',Modalresize);
	}

jQuery(function($){

	/* modal windows */
	var aModal = $('a[class*=modal]');

	if (aModal.length) {
		$('body').append("<div id='jsWidget_ModalBackground' style='display:none'/>")
			.append("<div id='jsWidget_Modal' style='display:none'><div class='header'><span class='title'></span><a href='#'><img src='/0/gfx/btn_close.gif' alt='close'></a></div><iframe frameborder=0 allowtransparency='true' /></div>");
		$('#jsWidget_Modal .header a').add('#jsWidget_ModalBackground').click(function(){
			closeModal();
			return false;
		});
		// Modal Popup (es: class="modal_500x400")
		aModal.click(function() {
			var a=this.className.split(/odal_/)[1];
			if(a){
				var c=a.split(/x|\s/);
				openModal($(this).attr('href'), c[0], c[1], $(this).attr('title'));
				return false;
			} 
		});
	}
});

