cashFrame = function() { }

cashFrame.vpos = "middle";
cashFrame.maskColor = "#555555";
cashFrame.borderColor = "#FFFFFF";
cashFrame.embedHTML = false;

cashFrame.launch = function( params, host ) {
	if( host == null )
		host = "cash.motion-twin.com";
	window.scrollTo(0,0);

	this.hideFlash();

	if( this.embedHTML ){
		var cid = "cashFrameUniqDiv_"+Math.random();
		document.write("<div id=\""+cid+"\"></div>");
		this.container = document.getElementById(cid);


		var html = "";
		html += '<div id="mtcashframed" style="width: 100%; text-align: center;">';
			html += '<div style="padding: 5px; margin: auto; height: 500px; width: 760px; background-color: '+cashFrame.borderColor+';">';
				html += '<iframe name="mtcashframef" id="mtcashframef" style="position: static; margin: 0px; padding: 0px; width: 760px; height: 500px; border: 0px;" frameBorder="0" src="http://'+host+'/frame/init?'+params+'"></iframe>';
			html += '</div>';
		html += '</div>';

	}else{
		this.container = document.createElement("div");
		this.container.id = "mtcashframeContainer";
		document.body.insertBefore(this.container,document.body.firstChild);

		var vcss = "top: 50%; margin-top: -255px;";
		if( cashFrame.vpos != "middle" ){
			vcss = "top: "+cashFrame.vpos+"px;";
		}

		var html = "";
		html += '<div id="mtcashframed" style="z-index: 150; display: block; position: fixed; height: 100%; width: 100%;left: 0px; top: 0px;">';
			html += '<div class="mtcashframemask" id="mtcashframemask"></div>';
			html += '<div style="position: absolute; z-index: 146; left: 50%; margin-left: -385px; '+vcss+' padding: 5px; height: 500px; background-color: '+cashFrame.borderColor+';">';
				html += '<div class="mtcashframeclosebtn" onclick="cashFrame.close();" style="cursor: pointer; position: absolute; left: 737px; top: -20px; z-index: 147; width: 33px; height: 25px;"></div>'
				html += '<iframe name="mtcashframef" id="mtcashframef" style="position: static; margin: 0px; padding: 0px; width: 760px; height: 500px; border: 0px;" frameBorder="0" src="http://'+host+'/frame/init?'+params+'"></iframe>';
			html += '</div>';
		html += '</div>';
		html += '<style type="text/css">';
		html += '#mtcashframeContainer {';
		html += 'position: static;';
		html += '}';
		html += '.mtcashframemask {';
		html += 'background-color: '+cashFrame.maskColor+'; height: 100%; width: 100%; left: 0; top: 0; bottom: 0; position: absolute; z-index: 144; opacity: 0.5; filter: alpha(opacity=50);';
		html += '}';
		html += '.mtcashframeclosebtn {';
		html += 'background : transparent url(\'http://'+host+'/img/off.png\') no-repeat top left;';
		html += '}';
		html += '.mtcashframeclosebtn:hover {';
		html += 'background : transparent url(\'http://'+host+'/img/offover.png\') no-repeat top left;';
		html += '}';
		html += '</style>';
		html += '<!--[if IE 6]>';
		html += '<style type="text/css">';
		html += '#mtcashframemask {';
		html += 'height : expression(eval(document.compatMode && document.compatMode==\'CSS1Compat\') ? documentElement.clientHeight : document.body.clientHeight);';
		html += 'top : expression(eval(document.compatMode && document.compatMode==\'CSS1Compat\') ? documentElement.scrollTop : document.body.scrollTop);';
		html += '}';
		html += '</style>';
		html += '<![endif]-->';
	}

	this.container.innerHTML = html;
}

cashFrame.hideFlash = function(){
	var l = document.getElementsByTagName("embed");
	for( var i=0; i<l.length; i++ ){
		var e = l[i];
		if( e.style.visibility != null )
			e.setAttribute("mtcashframe_oldVis",e.style.visibility);
		e.style.visibility = 'hidden';
	}
	l = document.getElementsByTagName("object");
	for( var i=0; i<l.length; i++ ){
		var e = l[i];
		if( e.style.visibility != null )
			e.setAttribute("mtcashframe_oldVis",e.style.visibility);
		e.style.visibility = 'hidden';
	}
}

cashFrame.showFlash = function(){
	var l = document.getElementsByTagName("embed");
	for( var i=0; i<l.length; i++ ){
		var e = l[i];
		e.style.visibility = e.getAttribute("mtcashframe_oldVis");
	}
	l = document.getElementsByTagName("object");
	for( var i=0; i<l.length; i++ ){
		var e = l[i];
		e.style.visibility = e.getAttribute("mtcashframe_oldVis");
	}
}

cashFrame.close = function (){
	if( this.container == null )
		return;
	document.body.removeChild( this.container );
	if( this.onClose != null )
		this.onClose();
	this.showFlash();
}


