var $img;
var $img_holder; 
var $img_url;
var $debug;
var $img_height = 0;
var $img_width = 0;
var $browser_height = 0
var $browser_width = 0;
var $ABOUT_THE_DESIGN = Array();

function initStuff() {
	$img_holder = document.getElementById( "image-preview-holder" );
	$debug = document.getElementById( "debug-div" );
	browser_size();
}

window.onresize = function() { 
	browser_size();
	center_image();
}

function browser_size() {
  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;
  }

$browser_height = myHeight;
$browser_width = myWidth;
//alert( $browser_height + " | " + $browser_width );
}

function email( $user, $domain ) {
	location.href = "mailto:" + $user + "@" + $domain;
}

function center_image( $force ) {
	try {
		if( $force || $img_holder.innerHTML != "" ) {
			var $top =  ( $browser_height - $img_height ) / 2;
			var $left = ( $browser_width - $img_width ) / 2;
			$img_holder.innerHTML = "<a href=\"javascript:clear_image_holder();\">" + 
				"<img src=\"" + $img_url + "\" title=\"Click To Close\" " + 
				"style=\"border: 1px solid #777; position: absolute; z-index: 100; top: " + 	$top + "px; left: " + $left + "px;\" />" + 
				"</a>";
		}
	} catch( $e )  {
		alert( "Exception: center_image(): " + $e );
	} 
}

function clear_image_holder() {
	try {
		if( $img_holder ) {
			$img_holder = document.getElementById( "image-preview-holder" );
		}

		$img_holder.innerHTML = "";	
	//	$img_holder.style.display = "none";
	} catch( $e ) {
		alert( "Exception: clear_image_holder: " + $e );
	}
}

function show_image_preview( $image_url, $width, $height ) {
	try {
		clear_image_holder();
		$img_height = $height;
		$img_width = $width;
		$img_url = $image_url;
		center_image( true );
	} catch( $e ) {
		alert( "Exception: show_image_preview: " + $e );
	}
}

function show_about_the_design( $id ) {
	document.getElementById( "about-the-design-text" ).innerHTML = $ABOUT_THE_DESIGN[ $id ];
}

var windowObject = {
	onload: [],
	loaded: function()
	{
		if (arguments.callee.done) return;
		arguments.callee.done = true;
		for (i = 0;i < windowObject.onload.length;i++) windowObject.onload[i]();
	},
	addLoadFunction: function(fireThis)
	{
		for(var index = 0; index < arguments.length; index++) {
			this.onload.push(arguments[index]);
		}
		if (document.addEventListener) 
			document.addEventListener("DOMContentLoaded", windowObject.loaded, null);
		if (/KHTML|WebKit/i.test(navigator.userAgent))
		{ 
			var _timer = setInterval(function()
			{
				if (/loaded|complete/.test(document.readyState))
				{
					clearInterval(_timer);
					delete _timer;
					windowObject.loaded();
				}
			}, 10);
		}
		/*@cc_on @*/
		/*@if (@_win32)
		var proto = "src='javascript:void(0)'";
		if (location.protocol == "https:") proto = "src=//0";
		document.write("<scr"+"ipt id=__ie_onload defer " + proto + "><\/scr"+"ipt>");
		document.close();
		var script = document.getElementById("__ie_onload");
		script.onreadystatechange = function() {
		    if (this.readyState == "complete") {
		        setTimeout( function() { windowObject.loaded(); }, 100 );  
		    }
		};
		/*@end @*/
	
	   window.onload = windowObject.loaded;
	}
};

windowObject.addLoadFunction( initStuff );

