/**
* Master Application Development Infrastructure (MADI) - madi@amalla.com
* Unpublished Confidential Information of Scott Pier. Do not disclose.
* @Copyright Scott Pier, 2003, All Rights Reserved. - spier@amalla.com
*/

// Set Window Sizes
var myWidth = 700, myHeight = 500;
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;
}

// Set cookies of values
setCookie("viewableWidth", myWidth, 30);
setCookie("viewableHeight", myHeight, 30);

// Function to set cookies
function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function thickboxResize() {
	var boundHeight = 500; // max height
	var boundWidth = 700; // max width

//	if (typeof window.innerWidth != 'undefined'){
//		viewportWidth = window.innerWidth,
//		viewportHeight = window.innerHeight
//	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
//	 else if (typeof document.documentElement != 'undefined'
//	     && typeof document.documentElement.clientWidth !=
//	     'undefined' && document.documentElement.clientWidth != 0){
//	       viewportWidth = document.documentElement.clientWidth,
//	       viewportHeight = document.documentElement.clientHeight
//	 }
	 
	 // older versions of IE
	 
//	 else{
//		viewportWidth = document.getElementsByTagName('body')[0].clientWidth,
//		viewportHeight = document.getElementsByTagName('body')[0].clientHeight
//	 }
	
	//New Window Height and Width Code
	var viewportWidth = 0, viewportHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	   //Non-IE
		viewportWidth = window.innerWidth;
		viewportHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
		  viewportWidth = document.documentElement.clientWidth;
		  viewportHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
		  viewportWidth = document.body.clientWidth;
		  viewportHeight = document.body.clientHeight;
	  }
	 
	$('a.thickbox').each(function(){
		var text = $(this).attr("href");

		if (Math.round(viewportHeight * .75) < boundHeight){
			text = text.replace(/height=[0-9]*/,'height=' + Math.round(viewportHeight * .75));
		} else {
			text = text.replace(/height=[0-9]*/,'height=' + boundHeight);
		}

		if (Math.round(viewportWidth * .75) < boundWidth){
			text = text.replace(/width=[0-9]*/,'width=' + Math.round(viewportWidth * .75));
		} else {
			text = text.replace(/width=[0-9]*/,'width=' + boundWidth);
		}

		$(this).attr("href", text);
	});
}

$(window).bind('load', thickboxResize );
$(window).bind('resize', thickboxResize );
