
var it_matrix_faanywhere = {

	_debug: false,
	_restore_scroll: [{ body_overflow : null, html_overflow: null }],
	_container: null,
	_iframe: null,
	_disable_scroll: false,

	IFrame: function(parentElement)
	{
		// Create the iframe which will be returned
		var iframe = null;
		try {if (iframe == null) iframe = document.createElement("<iframe scrolling=\"no\">");} catch (e) {}
		try {if (iframe == null) iframe = document.createElement("iframe");} catch (e) {}
//

		// iframe.style.overflow = "hidden";

		// If no parent element is specified then use body as the parent element
		if(parentElement == null)
			parentElement = document.body;

		// This is necessary in order to initialize the document inside the iframe
		parentElement.appendChild(iframe);

		// Initiate the iframe's document to null
		iframe.doc = null;

		// Depending on browser platform get the iframe's document, this is only
		// available if the iframe has already been appended to an element which
		// has been added to the document
		if(iframe.contentDocument)
			// Firefox, Opera
			iframe.doc = iframe.contentDocument;
		else if(iframe.contentWindow)
			// Internet Explorer
			iframe.doc = iframe.contentWindow.document;
		else if(iframe.document)
			// Others?
			iframe.doc = iframe.document;

		// If we did not succeed in finding the document then throw an exception
		if(iframe.doc == null)
			throw "Document not found, append the parent element to the DOM before creating the IFrame";

		// Create the script inside the iframe's document which will call the
		iframe.doc.open();
		iframe.doc.close();

		// Return the iframe, now with an extra property iframe.doc containing the
		// iframe's document
		return iframe;
	},

	jsonpCallback: function(data) {
		it_matrix_faanywhere._iframe.doc.open();
		it_matrix_faanywhere._iframe.doc.write(data.iframeHtml);
		it_matrix_faanywhere._iframe.doc.close();
		it_matrix_faanywhere._iframe.style.visibility = "visible";
		
		  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;
		  }

		    posWidth = (myWidth - 760)/2;
		    posHeight = (myHeight - 439)/2;
		
		it_matrix_faanywhere.JSFX_FloatDiv("it_matrix_faanywhere_iframe", posWidth,posHeight).floatIt();
		
	},

	jsonpCall : function(scriptURL, scriptId) {
		var head = document.getElementsByTagName("head")[0];
		var script = document.createElement('script');
		if (scriptId == null)
			script.id = 'uploadScript';
		else
			script.id = scriptId;
		script.type = 'text/javascript';
		script.src = scriptURL;
		head.appendChild(script);
		var done = false;
		script.onload = script.onreadystatechange = function(){

			if ( !done && (!this.readyState ||
					this.readyState == "loaded" || this.readyState == "complete") ) {
				done = true;
				head.removeChild( script );
			}
		};
	},

	close: function(data) {
		if (it_matrix_faanywhere._iframe != null) {
			document.body.removeChild(it_matrix_faanywhere._container);
			it_matrix_faanywhere._container = null;
			document.body.removeChild(it_matrix_faanywhere._iframe);
			it_matrix_faanywhere._iframe = null;
			document.body.style.overflow = it_matrix_faanywhere._restore_scroll.body_overflow;
			document.getElementsByTagName("html")[0].style.overflow = it_matrix_faanywhere._restore_scroll.html_overflow;
			window.onresize = null;
			try {
				parent.frames.callbackFAAnywhere(data);
			}
			catch(err)
			{
				var txt="There was an error calling the function callbackFAAnywhere.\n\n";
				txt+="Error description: " + err.description + "\n\n";
				txt+="Click OK to continue.\n\n";
				if (it_matrix_faanywhere._debug) {
					alert(txt);
				}
			}
		}
	},

	create: function() {
		if (it_matrix_faanywhere._iframe == null) {
			it_matrix_faanywhere._iframe = "";
			it_matrix_faanywhere._restore_scroll.body_overflow = document.body.style.overflow;
			it_matrix_faanywhere._restore_scroll.html_overflow = document.getElementsByTagName("html")[0].style.overflow;
			if (it_matrix_faanywhere._disable_scroll) {
				// Try to avoid making scroll bars
				document.getElementsByTagName("html")[0].style.overflow='hidden';
				document.body.style.overflow='hidden';
			}
			it_matrix_faanywhere.grayOut(true, {'zindex':'50'});
			it_matrix_faanywhere._container = document.getElementById('it_matrix_faanywhere_darkfade_container');
			it_matrix_faanywhere._iframe = new it_matrix_faanywhere.IFrame(null);
			it_matrix_faanywhere._iframe.style.visibility = "hidden";
			it_matrix_faanywhere._iframe.id = "it_matrix_faanywhere_iframe";
			it_matrix_faanywhere._iframe.style.zIndex=55;
			it_matrix_faanywhere._iframe.style.position="absolute";
			it_matrix_faanywhere._iframe.doc.getElementsByTagName("html")[0].style.overflow='hidden';
			it_matrix_faanywhere._iframe.doc.body.style.overflow='hidden';
			it_matrix_faanywhere._iframe.style.overflow='hidden';
			//it_matrix_faanywhere._iframe.style.left="200px";
			//it_matrix_faanywhere._iframe.style.top="100px";
			it_matrix_faanywhere._iframe.style.left="50%";
			it_matrix_faanywhere._iframe.style.top="50%";
			//it_matrix_faanywhere._iframe.style.margin="-250px 0 0 -450px";
			it_matrix_faanywhere._iframe.style.zIndex=1000;
			it_matrix_faanywhere._iframe.style.width='760px';
			it_matrix_faanywhere._iframe.style.height='439px';
			it_matrix_faanywhere._iframe.style.display='block';

			it_matrix_faanywhere._iframe.onload = it_matrix_faanywhere.jsonpCall("http://faanywhere.alice.it/faanywhere/getFAAnywhere.js?callback=it_matrix_faanywhere.jsonpCallback");
			
		}
	},

	grayOut: function(vis, options) {
		// Pass true to gray out screen, false to ungray
		// options are optional.  This is a JSON object with the following (optional) properties
		// opacity:0-100         // Lower number = less grayout higher = more of a blackout
		// zindex: #             // HTML elements with a higher zindex appear on top of the gray out
		// bgcolor: (#xxxxxx)    // Standard RGB Hex color code
		// grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
		// Because options is JSON opacity/zindex/bgcolor are all optional and can appear
		// in any order.  Pass only the properties you need to set.
		var dark=document.getElementById('it_matrix_faanywhere_darkfade_container');
		if (!dark) {
			// The dark layer doesn't exist, it's never been created.  So we'll
			// create it here and apply some basic styles.
			// If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
			var tbody = document.getElementsByTagName("body")[0];
			if (navigator.userAgent.indexOf("MSIE")!=-1)
				var tnode = document.createElement('div');       // Create the layer.
			else
			var tnode = document.createElement('iframe');    // Create the layer.
			tnode.style.position='absolute';                 // Position absolutely
			tnode.style.top='0px';                           // In the top
			tnode.style.left='0px';                          // Left corner of the page
			tnode.style.overflow='hidden';                   // Try to avoid making scroll bars
			tnode.style.display='none';                      // Start out Hidden
			tnode.id='it_matrix_faanywhere_darkfade_container';                   // Name it so we can find it later
			tbody.appendChild(tnode);                            // Add it to the web page
			dark=document.getElementById('it_matrix_faanywhere_darkfade_container');  // Get the object.
		}
		if (vis) {
			it_matrix_faanywhere.darkResize(dark, options);
		} else {
			dark.style.display='none';
		}
		window.onresize = function () { 
			dark=document.getElementById('it_matrix_faanywhere_darkfade_container');  // Get the object.
			it_matrix_faanywhere.darkResize(dark, options);
		}
	},

	darkResize: function(dark, options) {
		var options = options || {};
		var zindex = options.zindex || 50;
		var opacity = options.opacity || 70;
		var opaque = (opacity / 100);
		var bgcolor = options.bgcolor || '#000000';
		// Calculate the page width and height
		if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
			var pageWidth = document.body.scrollWidth+'px';
			var pageHeight = document.body.scrollHeight+150+'px';
		} else if( document.body.offsetWidth ) {
			var pageWidth = document.body.offsetWidth+'px';
			var pageHeight = document.body.offsetHeight+150+'px';
		} else {
			var pageWidth='100%';
			var pageHeight='100%';
		}
		//set the shader to cover the entire page and make it visible.
		dark.style.opacity=opaque;
		dark.style.MozOpacity=opaque;
		dark.style.filter='alpha(opacity='+opacity+')';
		dark.style.zIndex=zindex;
		dark.style.backgroundColor=bgcolor;
		dark.style.width= pageWidth;
		dark.style.height= pageHeight;
		dark.style.display='block';
	},
	
	
ns : (navigator.appName.indexOf("Netscape") != -1),
d : document,
JSFX_FloatDiv: function(id, sx, sy)
{
	var d = it_matrix_faanywhere.d;
	var ns = it_matrix_faanywhere.ns;
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth :
		document.documentElement && document.documentElement.clientWidth ?
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ?
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0)
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ?
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/1;this.cy += (pY + this.sy - this.cy)/1;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	return el;
}
	
	
	
	
	
	
};
