$(document).ready(function() {
	$("body").append('<div id="mask-modal"></div>');
	
	$('a[name=modal]').live('click',function(e){

		$('#mask-modal').html('');
		
		e.preventDefault();
		var id = $(this).attr('href');

		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		$('#mask-modal').css({'width':maskWidth,'height':maskHeight});

		$('#mask-modal').fadeIn(500);
		$('#mask-modal').fadeTo("slow",0.7);

		var winH = $(window).height();
		var cliH = screen.availHeight;
		var winW = $(window).width();

		
		if($(this).attr('href') == "#next"){
			$(this).next().css('top',  (winW / 2) - ($(this).next().height() ) / 2 );
			$(this).next().css('left', (winW / 2) - ($(this).next().width() ) / 2  );
			$(this).next().fadeIn(1000);
		}else{
			//console.log('winH ' + winH);
			//console.log('winW ' + winW);
			//console.log('idH ' +  $(id).height());
			//console.log('idW ' +  $(id).width());
//			$(id).css('top',  (winH / 2 ) - ( $(id).height() ) / 2);
//			$(id).css('left', ((winW / 2 ) - ( $(id).width() ) / 2 ) -120 );
//			$(id).css('top',  (cliH / 2 ) - ( $(id).height() ) / 2);
			$(id).css('top',  '50%');
			$(id).css('margin-top',  - ( $(id).height() ) / 2);
			$(id).css('margin-left', - ( $(id).width() ) / 2 );
			$(id).fadeIn(1000);
		}
	});
	
	$('.WindowModal .Close, .overlay_zoom, #map_canvas img').click(function () {
		$('#release-preview').css({
			'z-index': '4000'
		});
	});

	$(".WindowModal .Close, .overlay_zoom, #map_canvas img").live('click',function(e){
		e.preventDefault();
		$('#mask-modal').html('');
		$('#mask-modal, .WindowModal, .overlay_zoom').hide();
		
		
	});

	$('#mask-modal').click(function () {
		$(this).hide();
		$('#mask-modal').html('');
		$('.WindowModal').hide();
		$('#release-preview').css({
			'z-index': '4000'
		});
	});
});
