var IframeResize = { 
	resize: function() { 
 
		if( typeof( window.innerWidth ) == 'number' ) {
		  //Non-IE
		  myWidth = window.innerWidth;
		  myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		  //IE 6+ in 'standards compliant mode'
		  myWidth = document.documentElement.clientWidth;
		  myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		  //IE 4 compatible
		  myWidth = document.body.clientWidth;
		  myHeight = document.body.clientHeight;
		}
		
		// alert("silhouette2 eventhandler " + myHeight + "x" + myWidth);
		
		var iframeMinWidth = 1060;
			
		if (myWidth > iframeMinWidth) 
			var left = (myWidth - iframeMinWidth)/2;
		else
			var left = 23;
				
		var new_height = myHeight-80;
		
		if (myWidth > iframeMinWidth)
			var new_width = iframeMinWidth;
		else
			var new_width = myWidth - (left * 2);

		var silhouette_frame = document.getElementById("frame");
		silhouette_frame.style.height = new_height + "px";
		silhouette_frame.style.width = new_width + "px"; 
		silhouette_frame.style.left = left + "px"; 
		jQuery("#silhouette_dialog_closer").css("left",(left-20)+"px");
 
		var silhouette_bg = document.getElementById("sil-bg");
		silhouette_bg.style.height = myHeight + "px";
		silhouette_bg.style.width = myWidth + "px"; 
	}, 
	init: function() { 
	},  
	open: function(url) {
		if (!document.getElementById("sil-container")) {    
			
			//http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
			var myWidth = 0, myHeight = 0;
			if( typeof( window.innerWidth ) == 'number' ) {
			  //Non-IE
			  myWidth = window.innerWidth;
			  myHeight = window.innerHeight;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			  //IE 6+ in 'standards compliant mode'
			  myWidth = document.documentElement.clientWidth;
			  myHeight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			  //IE 4 compatible
			  myWidth = document.body.clientWidth;
			  myHeight = document.body.clientHeight;
			}
			
			var docHeight = myHeight;
			var docWidth = myWidth;
			
			var iframeMinWidth = 1060;
				
			var topOffset = 32;
			if (docWidth > iframeMinWidth) 
				var left = (docWidth - iframeMinWidth)/2;
			else
				var left = 23;
				
			var height = docHeight - (topOffset * 2);
			//var width = docWidth - (left * 2);
			if (docWidth > iframeMinWidth)
				var width = iframeMinWidth;
			else
				var width = docWidth - (left * 2);
			
			var str = '<div id="sil-bg" style="background: #666; opacity: 0.6; filter: alpha(Opacity=60); ';
			str += 'position: absolute; left: 0; top: 0; width: 100%; height: ' + docHeight + 'px;">&nbsp;</div> ';
			str += '<iframe id="frame" style="position: absolute; z-index: 50; background: #fff; ';
			str += 'left: ' + left + 'px; top: ' + topOffset + 'px; width: ' + width + 'px; height: ' + height + 'px; overflow-x: hidden; z-index: 1000;';
			str += 'background: transparent no-repeat 0 0;" ';
			str += 'src="' + url + '" frameborder="0"></iframe>';
			str += '<div id="silhouette_dialog_closer" style="position: absolute; top: ' + topOffset + 'px; left: ' + (left-20) + 'px; ">'+
						'<a href="#" id="closer"><img src="http://www.silhouette.com/ext/_imgs/_overlay/closer.png" style="border: none;"/></a><br/>'+
						'<a href="#" id="reopener"><img src="http://www.silhouette.com/ext/_imgs/_overlay/reopener.png" style="border: none;"/></a>'+
					'</div> ';
			var elem = document.createElement("div");
			elem.id = "sil-container";
			elem.innerHTML = str;
			document.body.appendChild(elem);
 
			document.getElementById("sil-bg").onclick = function() {
				document.getElementById("sil-container").style.display = "none";
				document.getElementById("sil-bg").style.display = "none";
			};
			
			// Reopener Event Handler
			document.getElementById("reopener").onclick = function() {
				// Close Layover before
				document.getElementById("sil-container").style.display = "none";
				document.getElementById("sil-bg").style.display = "none";
				
				// then reload content in a new window
				window.open( document.getElementById("frame").src );
			};
			// Closer Event Handler
			document.getElementById("closer").onclick = function() {
				// Close Layover before
				document.getElementById("sil-container").style.display = "none";
				document.getElementById("sil-bg").style.display = "none"; 
			};
 
		     // Tie our silhouette resize handler to the window
		     window.onresize = this.resize;
		} else {
				document.getElementById("frame").src = url;
				document.getElementById("sil-container").style.display = "block";
				document.getElementById("sil-bg").style.display = "block";
		}
	}
}