
var flashObject
flashObject="<object width=\"||WIDTH||\" height=\"||HEIGHT||\" id=\"flashVideo\" align=\"middle\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\">";
flashObject+="<param name=\"movie\" value=\"||SRC||\" />";
flashObject+="<param name=\"menu\" value=\"false\" />";
flashObject+="<param name=\"quality\" value=\"best\" />";
flashObject+="<param name=\"scale\" value=\"exactfit\" />";
flashObject+="<param name=\"bgcolor\" value=\"#000000\" />";
flashObject+="<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
flashObject+="<embed width=\"||WIDTH||\" height=\"||HEIGHT||\" src=\"||SRC||\" name=\"flashVideo\" menu=\"false\" quality=\"best\" scale=\"exactfit\" bgcolor=\"#000000\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
flashObject+="</object>";

//
//	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;
	}
});



function fncInitVideoBox(){
	var objBody = document.getElementsByTagName("body").item(0);
	
	// background div over all the content (dark)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objBody.appendChild(objOverlay);
	
	// big div over all the content and above objOverlay, close de videoBox when clicked
	var objVideobox = document.createElement("div");
	objVideobox.setAttribute('id','videoBox');
	objVideobox.style.display = 'none';
	//objVideobox.onclick = function() { fncHideVideo(); return false; }
	objBody.appendChild(objVideobox);
	
	// div with the videoContainer
	var objOuterVideoContainer = document.createElement("div");
	objOuterVideoContainer.setAttribute('id','outerVideoContainer');
	objVideobox.appendChild(objOuterVideoContainer);
	
	// div with close link
	var objVideoClose = document.createElement("div");
	objVideoClose.setAttribute('id','videoClose');
	objOuterVideoContainer.appendChild(objVideoClose);
	
	// div with the exact size of the flash player
	var objVideoContainer = document.createElement("div");
	objVideoContainer.setAttribute('id','videoContainer');
	objOuterVideoContainer.appendChild(objVideoContainer);
	
	// close link
	var objCloseLink = document.createElement("a");
	objCloseLink.setAttribute('href','#');
	objCloseLink.innerHTML="FECHAR";
	objCloseLink.onclick = function() { fncHideVideo(); return false; }
	objVideoClose.appendChild(objCloseLink);
}

function fncShowVideo(strFlashFile,numWidth,numHeight){
	// calculate top offset for the videoBox and display
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var videoBoxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
	
	Element.setHeight('overlay',arrayPageSize[1]);
	Element.setHeight('videoBox',arrayPageSize[1]);
	
	Element.setWidth('videoContainer',numWidth);
	Element.setHeight('videoContainer',numHeight);
	
	var numWidth2 = new Number(numWidth);
	Element.setWidth('outerVideoContainer',numWidth2+20); // width + (videoContainer padding * 2)
	Element.setHeight('outerVideoContainer',Number(numHeight)+20); // height + (videoContainer padding * 2)
	Element.setTop('outerVideoContainer',videoBoxTop);
	
	new Effect.Appear('overlay', { duration: 0.5, from: 0.0, to: 0.8, afterFinish: function(){ new Effect.Appear('videoBox', { duration: 0 }); } });
	
	var videoHTML
	videoHTML = flashObject.replace(/\|\|SRC\|\|/g , strFlashFile);
	videoHTML = videoHTML.replace(/\|\|WIDTH\|\|/g , numWidth);
	videoHTML = videoHTML.replace(/\|\|HEIGHT\|\|/g , numHeight);
	
	Element.setInnerHTML('videoContainer',videoHTML);
}

function fncHideVideo(){
	Element.setInnerHTML('videoContainer','');
	new Effect.Fade('videoBox', { duration: 0 });
	new Effect.Fade('overlay', { duration: 0.5 });
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	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 if (document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // repete
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.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;
}

// INICIALIZACAO
Event.observe(window,'load',fncInitVideoBox,false);


