function getWidth() {
	var returnValue = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		returnValue = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		returnValue = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		returnValue = document.body.clientWidth;
	}
	return parseInt(returnValue);
}

function getHeight() {
	var returnValue = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		returnValue = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		returnValue = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		returnValue = document.body.clientHeight;
	}
	return parseInt(returnValue);
}

function repaint(){
	preview_dialog_obj	= document.getElementById('preview_dialog');
	preview_iframe_obj	= document.getElementById('preview_iframe');
	preview_dialog_obj.style.left	= getWidth()/2 - 193 + 'px';
	preview_dialog_obj.style.top	= getHeight()/2 - 233 + 'px';
}

function toggle_preview(__resource){
	overlay_obj			= document.getElementById('overlay');
	preview_dialog_obj	= document.getElementById('preview_dialog');
	preview_iframe_obj	= document.getElementById('preview_iframe');

	overlay_obj.style.display = overlay_obj.style.display == 'none' ? 'block' : 'none';
	preview_dialog_obj.style.display = preview_dialog_obj.style.display == 'none' ? 'block' : 'none';
	preview_iframe_obj.src = '/preview/?'+__resource;
}

window.onload = function(){
	repaint();
}

window.onresize = function(){
	repaint();
}
