var SLmodalWindow = {
	parent:"body",
	windowId:null,
	content:null,
	width:null,
	height:null,
	callingHeight:$(window).height(),
	close:function()
	{
		try {
			$('#homepageRotation').cycle('resume');
		} catch(err){}
		
		$(".SLmodal-window").remove();
		$(".SLmodal-overlay").remove();
		if ($.browser.msie) {
			$('select').show();
		}
		$("#theSLSpinnerDiv").remove();
	},
	open:function()
	{
		try {
			$('#homepageRotation').cycle('pause');
			if ($.browser.msie) {	scroll(0,0); }
		} catch(err){}
		
		var SLmodal = "";
		SLmodal += "<div class=\"SLmodal-overlay\"></div>";


		if (SLmodalWindow.height < $(window).height()) {
			SLmodal += "<div id=\"" + this.windowId + "\" class=\"SLmodal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:0px; margin-left:-" + (this.width / 2) + "px;\">";
		} else {
			SLmodal += "<div id=\"" + this.windowId + "\" class=\"SLmodal-window\" style=\"width:" + this.width + "px; height:" + (this.callingHeight-10) + "px; margin-top:0px; margin-left:-" + (this.width / 2) + "px;\">";
		}
		SLmodal += this.content;
		SLmodal += "</div>";	
		
		var theSLSpinner = "";
		theSLSpinner += "<div id=\"theSLSpinnerDiv\"><img src=\"/System-Selector/img/largebusy.gif\" width=\"143\" height=\"143\" /></div>";
		$(this.parent).append(theSLSpinner);
		
		
		if ($.browser.msie) {
			$('select').hide();
		}

		$(this.parent).append(SLmodal);
		
		$(".SLmodal-window").append("<a class=\"SLclose-window\"></a>");
		$(".SLclose-window").click(function(){SLmodalWindow.close();});
		$(".SLmodal-overlay").click(function(){SLmodalWindow.close();});
	}
};


var openMySLModal = function(source, width, height)
{
	randnum = Math.random();
  SLmodalWindow.windowId = "mySLModal";
  SLmodalWindow.width = width;
//  SLmodalWindow.height = height;
	if (SLmodalWindow.callingHeight >= height) {
		SLmodalWindow.height = height;
	} else {
		SLmodalWindow.height = SLmodalWindow.callingHeight - 10;
		if (source.indexOf("?") != -1) {
			source = source + "&thePassedHeight="+SLmodalWindow.height;
		} else {
			source = source + "?thePassedHeight="+SLmodalWindow.height;
		}
	}
	
	
  SLmodalWindow.content = "<iframe id='"+ randnum +"' width='"+ SLmodalWindow.width +"' height='"+ SLmodalWindow.height +"' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'>&lt/iframe>";
  SLmodalWindow.open();
};

$(document).ready(function(){
	$(window).resize(function() {
  	SLmodalWindow.callingHeight = $(window).height();
	});
});

