var div_FlashBox_id = "FlashBox";
var bgcolor = "bgcolor";
var xml_file = "xml/FlashBox.xml";
var width = 0;
var height = 0;
var div_FlashBox = {};
var var_name = "my_FlashBox";
eval("var "+var_name+"=''");
var realID = 0;
var myswf = "";
var state = 0;


var FlashBox = new Class({
	
	initialize: function(){
		this.setInnerHTML();
		myswf = this.createFlashBox();
		this.hide();
		this.onResize();
	},
	setInnerHTML: function(){
		var objBody = document.getElementsByTagName("body").item(0);
		div_FlashBox = document.createElement('div');
		div_FlashBox.setAttribute('id',div_FlashBox_id);
		div_FlashBox.style.zIndex="9999";
		div_FlashBox.style.overflow = "hidden";
		div_FlashBox.style.position="absolute";
		div_FlashBox.style.top="0px";
		div_FlashBox.style.left="0px";
		div_FlashBox.style.width = "0px";
		div_FlashBox.style.height = "0px";
		objBody.appendChild(div_FlashBox);
	},
	createFlashBox: function(){
	
		myswf1 = new Swiff('js/flashbox/flashbox.swf', {
					id: 'swf_FlashBox', 
					width: '100%',//width, 
					height: '100%',//height, 
					container: div_FlashBox_id,
					params: {
					wmode: 'transparent', 
					bgcolor: bgcolor
				}, 
					vars: {
					xmlFile: xml_file, 
					instanceName: var_name
				}
		});
		return myswf1;
	},
	hide : function(){
		div_FlashBox.style.width = "1px";
		div_FlashBox.style.height = "1px";
		state = 1;
	},
	show : function(id){
		arrayPageSize = my_FlashBox.getSize();
		width = arrayPageSize[0];
		height = arrayPageSize[1];
		div_FlashBox.style.width = width+"px";
		div_FlashBox.style.height = height+"px";
		//Swiff.remote(myswf.toElement(), "loadById", id);
		realID = id;
		this.realShow.delay(500);
		state = 0;
	},
	realShow : function(){
		Swiff.remote(myswf.toElement(), "loadById", realID);
	},
	onResize: function(){
		window.addEvent('resize', function(){
			if(state == 0){
				arrayPageSize = my_FlashBox.getSize();
				width = arrayPageSize[0];
				height = arrayPageSize[1];
			//	console.log("div_FlashBox Width = "+div_FlashBox.offsetWidth);
			//	console.log("div_FlashBox Height = "+div_FlashBox.offsetHeight);
				div_FlashBox.style.width = width+"px";
				div_FlashBox.style.height = height+"px";
			//	console.log("despues");
			//	console.log("div_FlashBox Width = "+div_FlashBox.offsetWidth);
			//	console.log("div_FlashBox Height = "+div_FlashBox.offsetHeight);
			}
		});
	},	
	getSize : function(){
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
	//	console.log(self.innerWidth);
	//	console.log(document.documentElement.clientWidth);
	
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// For small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
	
		// For small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
	//	console.log("pageWidth " + pageWidth)
	
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}
	
	
});
window.addEvent('load', function(){
								 
	eval(var_name+" = new FlashBox();");
	
});

/*
var anchors = document.getElementsByTagName('a');
		var areas = document.getElementsByTagName('area');

		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			
			var relAttribute = String(anchor.getAttribute('rel'));
			
			if (anchor.getAttribute('href') && (relAttribute.match('FlashBox'))){
				anchor.onclick = function () {my_FlashBox.show(this.href); return false;}
			}
		}
		for (var i=0; i< areas.length; i++){
			var area = areas[i];
			
			var relAttribute = String(area.getAttribute('rel'));
			
			if (area.getAttribute('href') && (relAttribute.match('FlashBox'))){
				area.onclick = function () {my_FlashBox.show(this.href); return false;}
			}
		}

*/