//Pop-up Window v2.0
//Pops up inline using iframe
//by sam mateosian
//big room studios

//sample html:

//<script language=javascript type="text/javascript" src="popup.js">

//<a href="http://www.bigroomstudios.com/" onclick="popup(this.href,'800','600');return false;">www.bigroomstudios.com</a>


var popup_iframe_id = "iframe_popup";


function popup(url, width, height) {
	
	var popup_div = new getObj('popup');
	
	var frame_html = '<iframe class="popup_hidden" id="iframe_popup" name="iframe_popup" frameborder="0" scrolling="no"></iframe>';

	var div_html = popup_div.obj.innerHTML;
	
	if(!div_html){
	
		popup_div.obj.innerHTML = frame_html;
	}
	
	var iframe = new getObj(popup_iframe_id);
	
	iframe.obj.src = url;
	
	show_popup(width, height);
}


function show_popup(width, height) {
	
	
	var iframe = new getObj(popup_iframe_id);
	
	var left = (getWindowWidth() - width) / 2;
	
	var top = (getWindowHeight() - height) / 2 + getScrollY() - 100;
	
	iframe.style.width = width + 'px';
	
	iframe.style.height = '25px';
	
	iframe.style.left = left  + 'px';
	
	iframe.style.top = top + 'px';
}


function hide_popup(){
	
	var iframe = new getObj(popup_iframe_id);
	
	iframe.obj.className = "popup_hidden";
	
	iframe.obj.src = '';
	
	var popup_div = new getObj('popup');
	
	//popup_div.obj.innerHTML = '';
	
}


function resize_popup(){
	
	var iframe = new getObj(popup_iframe_id);
	
	iframe.obj.className = "popup_visible";
	
	//var width = iframe.obj.contentDocument.body.scrollWidth;
	
	var iframe_div = new getFrameObj('frame', popup_iframe_id);
	
	var modules_div = new getFrameObj('modules', popup_iframe_id);
	
	var height;
	
	if(iframe_div.obj.offsetHeight){
	
		height = iframe_div.obj.offsetHeight;
		
		//alert(height);
		
	}else{
		
		height = iframe_document.body.scrollHeight;
	}
	
	if(height > 600){
		
		height = 600;
		modules_div.style.height = 540+ 'px';
		
		//resize_popup();
	}
		
	//var left = (document.body.clientWidth - width) / 2;
	
	var top = (getWindowHeight() - height) / 2 + getScrollY() - 100;
	
	//iframe.style.width = width + 'px';
	
	iframe.style.height = height + 'px';
	
	//iframe.style.left = left  + 'px';
	
	iframe.style.top = top + 'px';
	
}

