// JavaScript Document

function fn_delay() {
	// ie6 delay and scroll to top so that we see the modal window
	$(this.parent).scrollTo(0,0);
}

var modalWindow = {
	parent:"body",
	windowId:null,
	content:null,
	width:null,
	height:null,
	close:function()
	{
		$(".modal-window").remove();
		$(".modal-overlay").remove();
	},
	open:function()
	{
		var modal = "";
		modal += "<div class=\"modal-overlay\"></div>";
		modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
		modal += this.content;
		modal += "</div>";	
		
		// alert("modalWindow : modal=" + modal);

		$(this.parent).append(modal);

		$(".modal-window").append("<a class=\"close-window\">Close <strong>X</strong></a>");
		$(".close-window").click(function(){modalWindow.close();});
		$(".modal-overlay").click(function(){modalWindow.close();});

		$(".modal-window").append("<span class=\"close-window-link\"></span>");
		$(".close-window-link").click(function(){modalWindow.close();});
		
		// alert("ready to reload");
		// $(".modal-window").reload();
		// alert("reloaded");
		
		// fn_delay();
		
		setTimeout("fn_delay()",1000);

	}
};

var openMyModal = function(type,source,width,height) {
	// alert("openMyModal : type=" + type + " source=" + source + " width=" + width + " height=" + height);
	modalWindow.windowId = "myModal";
	modalWindow.width = width;
	modalWindow.height = height;
	switch(type) {
		case "url" :
			modalWindow.content = "<iframe width='" + width + "' height='" + height + "' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";
		break;
		default:
			modalWindow.content = source;
		break;
	}
	modalWindow.open();
};	
