////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// videoBox
	//
	//
	//
function initVideoBox() {
	var anchors = document.getElementsByTagName('a');
	for(var i=0; i < anchors.length; i++) {
		if(anchors[i].getAttribute('rel') == 'videoBox') {
			var a = anchors[i];
			var theUrl = a.getAttribute('href').split('?');
			a.swf = theUrl[0];
			a.video = theUrl[1].split('=')[1];
			
			var theDesc = a.getAttribute('title');
			a.desc = theDesc;
			a.onclick = showVideoBox;
		}
	}
}

function showVideoBox() {
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
	
	var theWindow = document.getElementsByTagName('body')[0];
	
	var videoBox_overlay = document.createElement('div');
	videoBox_overlay.setAttribute('id', 'videoBox_overlay');
	videoBox_overlay.onclick = removeVideoBox;
	theWindow.appendChild(videoBox_overlay);
	
	var videoBox = document.createElement('div');
	videoBox.setAttribute('id', 'videoBox');
	
	var videoBox_container = document.createElement('div');
	videoBox_container.setAttribute('id', 'videoBox_container');
	videoBox.appendChild(videoBox_container);
	
	var videoBox_window = document.createElement('div');
	videoBox_window.setAttribute('id', 'videoBox_window');
	videoBox_container.appendChild(videoBox_window);
	
	var flashWarning = document.createElement('p');
	flashWarning.setAttribute('id', 'flashWarning');
	var flashLink = document.createElement('a');
	flashLink.setAttribute('href', 'http://www.adobe.com/go/getflashplayer');
	var flashImg = document.createElement('img');
	flashImg.setAttribute('src', 'http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif');
	flashImg.setAttribute('alt', 'Get Adobe Flash player');
	flashLink.appendChild(flashImg);
	flashWarning.appendChild(flashLink);
	videoBox_window.appendChild(flashWarning);
	
	var videoBox_info = document.createElement('div');
	videoBox_info.setAttribute('id', 'videoBox_info');
	videoBox_container.appendChild(videoBox_info);
	
	if(this.desc) {
		var videoBox_desc = document.createElement('p');
		videoBox_desc.setAttribute('id', 'videoBox_desc');
		videoBox_desc.appendChild(document.createTextNode(this.desc))
		videoBox_info.appendChild(videoBox_desc);
	}
	
	var videoBox_close = document.createElement('a');
	videoBox_close.setAttribute('id', 'videoBox_close');
	videoBox_close.onclick = removeVideoBox;
	videoBox_info.appendChild(videoBox_close);
	
	theWindow.appendChild(videoBox);

	var arrayPageSize = getPageSize();
	videoBox_overlay.style.width = arrayPageSize[0] + 'px';
	videoBox_overlay.style.height = arrayPageSize[1] + 'px';
	
	if (navigator.userAgent.toLowerCase().indexOf('mac') != -1 && navigator.userAgent.toLowerCase().indexOf('firefox')!=-1 || navigator.userAgent.toLowerCase().indexOf('camino')!=-1) {
		videoBox_overlay.style.backgroundImage = 'url(images/videoBox_fallBackTile.png)';
		videoBox_overlay.style.backgroundRepeat = 'repeat';
	}else{
		videoBox_overlay.style.backgroundColor = "#000000";
		videoBox_overlay.style.display = 'none';
		new Effect.Appear('videoBox_overlay', { duration: 0.3, from: 0.0, to: 0.8 });
	}
	
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 5);
	var lightboxLeft = arrayPageScroll[0];

	videoBox.style.top = lightboxTop + "px";
	videoBox.style.left = lightboxLeft + "px";
	
	var theSWF = this.swf;
	var theVideo = this.video;
	
	setTimeout(function() {
		writeFlashContent(theSWF, 'videoBox_swf', '9.0.115', '#FFFFFF', 'videoBox_window', '630', '380', 'flashVid', theVideo);
	}, 700);
	
	return false;
}


function removeVideoBox() {
	$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
	
	Element.remove('videoBox_container');
	new Effect.Fade('videoBox_overlay', { duration: 0.3, queue: 'end', afterFinish: function(){	Element.remove('videoBox_overlay'); } });
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	// set any link in a lightbox caption to open new window
	//
	//
function lightboxCaptionLinks() {
	if(!document.getElementById('imageDetails')) return false;
	var anchors = document.getElementById('imageDetails').getElementsByTagName('a');
	for(var i = 0; i < anchors.length; i++) {
		anchors[i].setAttribute('target', '_blank');
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	// getPageScroll()
	//
	// Returns array with x,y page scroll values.
	// Core code from - quirksmode.com
	//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	// getPageSize()
	// 
	// Returns array with page width, height and window width, height
	// Core code from - quirksmode.com
	// Edit for Firefox by pHaez
	//
function getPageSize(){

	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;

	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;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

addLoadEvent(function(){
	initVideoBox();
	lightboxCaptionLinks();
});