/*************************************************************************
* global-execute.js
* Collection of code that is supposed to execute on EVERY SINGLE PAGE either
* onload, or onDOMLOAD
*	
* Usage: 
*
* Dependencies: 		Mootools 1.2.1
* 						
* Author: 				Tri Doan
*
* v.1 (1/15/2009) 	- 	Initial release of Game Media Section
*
*
* PLEASE KEEP FUNCTION SECTIONS IN ALPHABETICAL ORDER (when possible)
*	-Onload Event (first load)
*	-IE Only	
*	-Page ID insertion
*	-EXECUTION
*
**************************************************************************/

/************************************************************************** 
*  ONLOAD EVENT 
*
*  Description:	Binds a onload event to a function.  This is not the same
*				as domready
*
*  To Do:		none;
***************************************************************************/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if(oldonload) oldonload();
      func();
    }
  }
}


/************************************************************************** 
*  IE Only
*
*  Description:	Run these only of browser is IE
*
*  To Do:		none;
***************************************************************************/
function pngFix() {
	if(Browser.Engine.trident) {
		arVersion = navigator.appVersion.split("MSIE")
		version = parseFloat(arVersion[1])

		if((version >= 5.5) && (document.body.filters)) {
		   for(i=0; i<document.images.length; i++) {
		      img = document.images[i]
		      imgName = img.src.toUpperCase()
		      if(imgName.substring(imgName.length-3, imgName.length) == "PNG") {
		         imgID = (img.id) ? "id='" + img.id + "' " : "";
		         imgClass = '';
			 imgScale = 'image';
			 if(img.className) {
			 	imgClass = 'class=\'' + img.className + '\' ';
			 	imgScale = (img.className.match(/scale/)) ? 'scale':'image';
			 }
		         imgClass = (img.className) ? "class='" + img.className + "' " : "";
		         imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
		         imgStyle = "display:inline-block;" + img.style.cssText;
		         if (img.align == "left") imgStyle = "float:left;" + imgStyle;
		         if (img.align == "right") imgStyle = "float:right;" + imgStyle;
		         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
		         strNewHTML = "<span " + imgID + imgClass + imgTitle
		         	+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		         	+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		         	+ "(src=\'" + img.src + "\', sizingMethod=\'" + imgScale + "\');\"></span>";
		         img.outerHTML = strNewHTML;
		         i = i-1;
		      }
		   }
		}
	}
}

/************************************************************************** 
*  Page ID insertion
*
*  Description:	Grabs the document name, removes '.html' and other '.'.  
*				Inserts it into body tag as an ID
*
*  To Do:		none;
***************************************************************************/
function insertPageID() {
	locA = window.location.href.split('/');
	locA = (locA[locA.length-1].split('.'))[0];
	document.getElementsByTagName('body')[0].id = locA;
}



/************************************************************************** 
*  EXECUTION
*
*  Description:	Execute above functions on dom load
*
*  To Do:		none;
***************************************************************************/
window.addEvent('domready', function() {
	pngFix();
	insertPageID();
});
