// (c) 2007 MAD-Works.com
// CLASS : MW_System_Load
// Init
function MW_System_Load(){
this.wib = screen.width;
this.heb = screen.height;
this.documes = (document.getElementById || document.createElement || document.getElementsByTagName) ? true : false;
this.objects = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
this.types = 'load';
}
MW_System_Load.prototype.addsevent = function(func){
if(this.objects.addEventListener){
this.objects.addEventListener(this.types,func,false);
return true;
} else if (this.objects.attachEvent){
this.objects.attachEvent("on" + this.types,func);
} else {
return false;
}
}
MW_System_Load.prototype.browser = function(){
this.ver = navigator.appVersion;
this.agent = navigator.userAgent.toLowerCase();
this.dom = document.getElementById ? 1:0;
this.all = document.all ? 1:0;
this.ie5 = (this.ver.indexOf("MSIE 5")>-1 && this.dom) ? 1:0;
this.ie6 = (this.ver.indexOf("MSIE 6")>-1 && this.dom) ? 1:0;
this.ie4 = (document.all && !this.dom) ? 1:0;
this.ie = this.ie4 || this.ie5 || this.ie6;
this.opera = this.agent.indexOf("opera")>-1;
this.gecko = (this.agent.indexOf("gecko")!=-1) ? 1:0;
this.bw = (this.ie || this.opera || this.gecko);
return this;
}
MW_System_Load.prototype.findobj = function(obj){
this.parent = window.document;
if(this.parent[obj]){ return this.parent[obj]; }
if(this.parent.all && this.parent.all[obj]){ return this.parent.all[obj]; }
if(this.parent.layers && this.parent.layers[obj]){ return this.parent.layers[obj]; }
if(this.parent.getElementById && this.parent.getElementById(obj)){ return this.parent.getElementById(obj); }
return null;
}
var MW = new MW_System_Load();
function MW_System_Hint(){}
MW_System_Hint.prototype.show = function(obj,str){
var hint = MW.findobj('hint');
if(!obj){ return; }
if(!MW.documes){ return; }
if(!hint){ return; }
hint.className = 'hint';
hint.style.left = 15;
hint.style.top = 50;

obj.onmouseout = function(advance){
hint.style.width = '';
hint.style.visibility = 'hidden';
if(hint.firstChild) hint.removeChild(hint.firstChild);
hint.appendChild(document.createTextNode(str));
};
obj.onmousemove = function(advance){
//str = str.replace(/</g,"&lt;");
//str = str.replace(/>/g,"&gt;");
hint.style.width = '';
hint.innerHTML = str;
vc = document.getElementsByTagName((document.compatMode && document.compatMode=="CSS1Compat") ? "HTML":"BODY")[0];
x = window.event ? event.clientX + vc.scrollLeft : advance.pageX;
y = window.event ? event.clientY + vc.scrollTop : advance.pageY;
vcwidth = vc.clientWidth ? vc.clientWidth + vc.scrollLeft : window.innerWidth + window.pageXOffset;
vcheight = vc.innerHeight ? window.innerHeight + window.pageYOffset : vc.clientHeight + vc.scrollTop;
  if(hint.offsetWidth>500){ hint.style.width = '200'; }
  if((x + hint.offsetWidth + 15) > vcwidth){
   hint.style.left = x - hint.offsetWidth - 4;
  } else {
   hint.style.left = x + 15;
  }
  if((y + hint.offsetHeight + 19) > vcheight){
   hint.style.top = y - hint.offsetHeight;
  } else {
   hint.style.top = y + 25;
  }
  //if(typeof(hint.style.MozOpacity)!="undefined"){
  hint.style.opacity = '.91';
  hint.style.filter = "alpha(opacity:91)";
  //}
  hint.style.visibility = 'visible';
};
}
MW_System_Hint.prototype.initialize = function(){
var hint = document.createElement("DIV");
hint.setAttribute('id','hint');
document.getElementsByTagName('body')[0].appendChild(hint);
hint.style.visibility = 'hidden';
var hintmarker = ['a','img'];
var textmarker = ['title','alt'];
var lenmarker = hintmarker.length;
for(var i=0; i<lenmarker; i++) {
atr = document.getElementsByTagName(hintmarker[i]);
for(var j=0; j<atr.length; j++)
if(viewhint=atr[j].getAttribute(textmarker[i])){
  atr[j].removeAttribute(textmarker[i]);
  HINT.show(atr[j],viewhint);
}
}
}
var HINT = new MW_System_Hint();
if(MW.objects){ MW.addsevent(HINT.initialize); }



///////////////////////////// Flash resize //////////////////////////////////

/**************************************************************
               Util Class description
***************************************************************/

Util = function() {	
	this.readyBound = false;
	
	var userAgent = navigator.userAgent.toLowerCase();
	
	//Figure out what browser is being used (from jQuery)
	this.browser = {
		version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
		safari: /webkit/.test( userAgent ),
		opera: /opera/.test( userAgent ),
		msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
		mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
	};
};

Util.readyList = [];
Util.isReady = false;

// crossbrowser add event
Util.prototype.addHandler = function(object, event, handler, useCapture) 
{ 
    if (object.addEventListener) 
    {   
        object.addEventListener(event, handler, useCapture ? useCapture : false);         
    } else if (object.attachEvent) 
        { 
            object.attachEvent('on' + event, handler); 
        } else 
            return ; 
};

// ready event
Util.prototype.ready = function(fn) {
	// Attach the listeners
	this.bindReady();
	
	// If the DOM is already ready
	if ( Util.isReady )
		// Execute the function immediately
		fn.call( document );

	// Otherwise, remember the function for later
	else
		// Add the function to the wait list
		Util.readyList.push( fn );	
};

// call function in readyList
Util.prototype.callReady = function() {
	// Make sure that the DOM is not already loaded
	if ( !Util.isReady ) {
		// Remember that the DOM is ready
		Util.isReady = true;
		// If there are functions bound, to execute
		if (Util.readyList) {
			// Execute all of them
			for ( var fn in Util.readyList )
				Util.readyList[fn].call( document );

			//Reset the list of functions
			Util.readyList = [];
		}
	}
};

// ready bind
Util.prototype.bindReady = function() {
	if ( this.readyBound ) return;
	this.readyBound = true;
	
	// Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
	if ( document.addEventListener && !this.browser.opera)
		// Use the handy event callback
		document.addEventListener( "DOMContentLoaded", this.callReady, false );
	
	var callReady = this.callReady;

	// If IE is used and is not in a frame
	// Continually check to see if the document is ready
	if ( this.browser.msie && window == top ) (function(){
		if (Util.isReady) return;
		try {
			// If IE is used, use the trick by Diego Perini
			// http://javascript.nwbox.com/IEContentLoaded/
			document.documentElement.doScroll("left");
		} catch( error ) {
			setTimeout( arguments.callee, 0 );
			return;
		}
		// and execute any waiting functions
		callReady();
	})();

	if ( this.browser.opera )
		document.addEventListener( "DOMContentLoaded", function () {
			if (Util.isReady) return;
			for (var i = 0; i < document.styleSheets.length; i++)
				if (document.styleSheets[i].disabled) {
					setTimeout( arguments.callee, 0 );
					return;
				}
			// and execute any waiting functions
			callReady();
		}, false);

	if ( this.browser.safari ) {
		var numStyles;
		(function(){
			if (Util.isReady) return;
			if ( document.readyState != "loaded" && document.readyState != "complete" ) {
				setTimeout( arguments.callee, 0 );
				return;
			}
			if ( numStyles === undefined )
				;//numStyles = jQuery("style, link[rel=stylesheet]").length;
			if ( document.styleSheets.length != numStyles ) {
				setTimeout( arguments.callee, 0 );
				return;
			}
			// and execute any waiting functions
			callReady();
		})();
	}

	// A fallback to window.onload, that will always work
	this.addHandler( window, "load", this.callReady );
};

var oUtil = new Util();

oUtil.ready(function(){
  // IMPORTANT!!! can be used if there is only one flash movie on the page which we want to be affected
  var object = document.getElementsByTagName('object')[0]; 
  var embed  = document.getElementsByTagName('embed')[0];
  var parent = object.parentNode;
  var ratio = parseInt(object.height)/parseInt(object.width);
  var setSize = function() {
    var width = parent.offsetWidth;
    object.width = 100 + '%';
    object.height = width * ratio + 'px';
    if ( embed ) {
      embed.style.width = 100 + '%';              // use style attribute for Opera less then 9.6
      embed.style.height = width * ratio + 'px';  // use style attribute for Opera less then 9.6
    }
  }
  setSize();
  oUtil.addHandler( window, "resize", setSize);
});
