
var positionTop='';
/*popup*/
(function($) {
	isIE=function(v){return typeof v=='undefined' && $.browser.msie?true:($.browser.version.substring(0,1) == v? true: false);}
	
	$.fn.modal=function(width){
	var $_self=$(this);
	var width=width||700;
	$(this).bind('click',function(e){
		e.preventDefault();
		var target=e.currentTarget;
		var $target=$(target);
		var $href=$target.attr('href');
		var title=$target.parents('.box:eq(0)').find('h3').html()||$target.attr('title');
		var ajaxMessage=$.ajax({ type: 'GET', url: $(this).attr('href'), async: false }).responseText;
		var message='<div class="modal-window">\
						<div class="modal-header"> <a href="#" class="modal-close">X</a><div style="margin-top:30px;width:300px;float:right">'+title+'</div></div>\
						<div class="modal-content clearfix">'
						+ajaxMessage+
						'</div>\
						<div class="modal-footer"></div>\
					</div>';
		if($(this).attr('type')=='simple')
			message='<div class="modal-window simple">\
							<div>\
							<a href="#" class="modal-close" style="height:20px;width:50px">close [x]</a><br clear="all" />'
							+ajaxMessage+
							'</div>\
						</div>';
		 $.blockUI({ message: message,
				  css: {
						width: width,
						position: 'absolute',
						background: 'none',
						textAlign: 'left',
						padding: 0, 
						border: 0,
						left:'50%',
						marginLeft: -width/2,
						cursor: 'auto',
						top: ($(document).scrollTop()+10)
						},
					overlayCss:{opacity:.8}
						});
		if(isIE7()){
			//$(window).scrollTop();
			positionTop='';
			fixModal();
		}
		 //$('.blockMsg .modal-thumbs').jScrollPane({showArrows:true,scrollbarWidth:9,dragMaxHeight:77,dragMinHeight:77});
	});
	
	
	
	$('.blockOverlay,.modal-close').live('click',function(e){e.preventDefault(); $.unblockUI();});
		return $_self;
	}

})(jQuery);

function isIE7(){
	return ($.browser.msie && $.browser.version.substr(0,1)<=7);
}

// for some stupid reason, modal is causing problem in IE7. And this is
// the stupid hack
function fixModal(){
	if(positionTop=='') positionTop = ($(document).scrollTop()); 
	$('.blockUI').css('top',0);
	$('.modal-window').css('top',positionTop);
}
if (isIE7()) {
	$(window).scroll( function (e){
		fixModal();
	});
}

$.fn.preload=function(){
	return this.each(function(i,o){
			  $(o).hide();
			  $(new Image()).load(function(){
							$(o).fadeIn('slow');			   
						   }).attr({src:o.src});
		});
}


$(function(){
	$('.modal-subscribe').modal();
})

