$(document).ready(function(){

	$("body").append('\
				<style>\
					.modal{\
						position: fixed;\
						z-index:100;\
						top: 0px;\
						left: 0px;\
						height:100%;\
						width:100%;\
						background: #000;\
						display: none;\
					}\
					\
					.modal-window{\
						position: fixed;\
						z-index: 102;\
						display:none;\
						top:50%;\
						left:50%;\
						background-color:#FFFFFF;\
						padding:0px;\
					}\
					\
					#modal-window-inner{\
						background-color:#FFFFFF;\
					}\
					.modal_close{\
						padding:3px;\
						text-decoration: none;\
						color: #000000;\
					}\
					#modal-window-inner iframe{\
						border:none;\
					}\
				</style>\
				\
				<div class="modal"></div>\
				<div class="modal-window" style="">\
					<div align="right">\
					<a href="javascript: void(0)" class="modal_close"><b>CLOSE X</b></a>&nbsp;\
					</div>\
					<div id="modal-window-inner"></div>\
				</div>\
					 ');

	$(".show-modal").click(function () {
		
		modalShow($(this));

    });
	
	$(".modal_close").click(function () {
	
		modalHide();
		
    });
	
	$(".modal").click(function () {
	
		modalHide();
		
    });

	function getRevVars(thisx)
	{
		var vars = [], hash;
		var hashes = thisx.attr("rev").split(';');
		
		for(var i = 0; i < hashes.length; i++)
		{

			hash = hashes[i].split(':');
			
			hash[0] = hash[0].replace(/^\s+/, '');
			
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
			
		}
		return vars;
	}

	function modalShow(thisx){
		$(".modal").css("opacity", 0.8);
		$(".modal").fadeIn("fast");



		var modalWindow = $(".modal-window");
		modalWindow.fadeIn("fast");
		
		
		var modWidth = getRevVars(thisx)["width"];
		var modHeight = getRevVars(thisx)["height"];
		
		modalWindow.width(modWidth);
		modalWindow.height(modHeight);
		
		
		modalWindow.css({
			"margin-left": -(modWidth/2),
			"margin-top": -(modHeight/2)
		});
		
		if(modalWindowContent = getRevVars(thisx)["iframe"]){
			$("#modal-window-inner").html('<iframe frameborder="0" src="'+modalWindowContent+'" width="'+modWidth+'" height="'+(modHeight-20)+'"></iframe>');
		}
		else if(modalWindowContent = getRevVars(thisx)["html"]){
			modalWindow.append('<div id="modal-window-inner">'+modalWindowContent+'</div>');
		}
		else if(modalWindowContent = getRevVars(thisx)["image"]){
			modalWindow.append('<image id="modal-window-inner" src="'+modalWindowContent+'" />');
		}
		
		
		


	}
	
	function modalHide(){
		$(".modal").fadeOut("fast");
		$(".modal-window").fadeOut("fast");
		/*$("#modal-window-inner").remove();*/
	}	
	
});