var fileBottomNavCloseImage = "typo3conf/ext/kch_flash/flashbox/images/close.gif";

var Flashbox = Class.create();

Flashbox.prototype = {
	initialize: function() {	
		if (!document.getElementsByTagName){ return; }

		var objBody = document.getElementsByTagName("body").item(0);
		
    var objOverlay = document.createElement("div");
    objOverlay.setAttribute('id','flashoverlay');
    objOverlay.style.display = 'none';
    objOverlay.onclick = function() { close(); return false; }
    objBody.appendChild(objOverlay);
		
		var objOutFlashbox = document.createElement("div");
		objOutFlashbox.setAttribute('id','outflashbox');
		objOutFlashbox.style.display = 'none';
		objBody.appendChild(objOutFlashbox);
		
		var objFlashbox = document.createElement("div");
		objFlashbox.setAttribute('id','flashbox');
		objOutFlashbox.appendChild(objFlashbox);
		
		var objFlashContainer = document.createElement("div");
		objFlashContainer.setAttribute('id','flashcontainer');
		objFlashbox.appendChild(objFlashContainer);
	
		var objBottomNav = document.createElement("div");
		objBottomNav.setAttribute('id','flashBottomNav');
		objFlashbox.appendChild(objBottomNav);
	
		var objBottomNavCloseLink = document.createElement("a");
		objBottomNavCloseLink.setAttribute('id','flashbottomNavClose');
		objBottomNavCloseLink.setAttribute('href','javascript:void(0);');
		objBottomNavCloseLink.onclick = function() { close(); return false; }
		objBottomNav.appendChild(objBottomNavCloseLink);
		
		var objBottomNavCloseImage = document.createElement("img");
		objBottomNavCloseImage.setAttribute('src', fileBottomNavCloseImage);
		objBottomNavCloseLink.appendChild(objBottomNavCloseImage);
	
  }
}


function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}


// -----------------------------------------------------------------------------------

//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},	
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});


// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPage(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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;
	if (self.innerHeight) {	// all except Explorer
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function initFlashbox() { myFlashbox = new Flashbox(); }
Event.observe(window, 'load', initFlashbox, false);

function writeFlash(swf,width,height,version,bgcolor,flvFile) {
  hideSelectBoxes();
  var arrayPageSize = getPage();
  $('flashoverlay').style.height = arrayPageSize[1] +'px';
  $('flashoverlay').style.display='block';    
  $('outflashbox').style.display='block';
  var documentTop = document.documentElement.scrollTop || document.body.scrollTop;
  var top = documentTop + 100;
  $('outflashbox').style.marginTop = top + 'px';
  $('flashbox').style.width=Number(width)+32+'px';
  
  var flashvars = {};
			flashvars.url = flvFile;
			var params = {};
			params.loop = "true";
			params.quality = "best";
			params.wmode = "transparent";
			params.bgcolor = "#8d8d8d";
			params.align = "center";
			var attributes = {};
			swfobject.embedSWF(swf, "flashcontainer", width, height, version, false, flashvars, params, attributes);
}



function close() {
  showSelectBoxes();
  $('flashoverlay').style.display='none';
  $('outflashbox').style.display='none';
  Element.replace("flashcontainer",'<div id="flashcontainer"></div>');
}

