if(!ALIGN) {var ALIGN={};}

ALIGN.browserWidth = document.documentElement.offsetWidth ? document.documentElement.clientWidth : document.documentElement.offsetWidth;
ALIGN.browserHeight = document.documentElement.offsetHeight ? document.documentElement.clientHeight : document.documentElement.offsetHeight;

$(document).ready(function() {
	if(ALIGN.browserHeight == 0) {
		ALIGN.browserHeight = $('html').outerHeight(true);
	}
});

ALIGN.scrollTop = 0;

/*	ALIGN.showHelp
 *	displays lightbox-style window with flash video, iframe, or image
 *	
 *	required variables:
 *	p: Object with below paramters
 * 
 *	p = {
 *		file: required to show any content ( required ),
 *		width: integer defining number of pixels to allow for content ( optional, defaults to 640px ),
 *		height: integer defining number of pixels to allow for content ( optional, defaults to 400px ),
 *		flashSkinFile: path and filename.swf to prefered skin file ( options, defaults to '/SiteCollectionDocuments/VideoPlayer/Scripts/Skins/SteelExternalAll.swf' ),
 *		menu: boolean defining if right click flash control menu should be allowed or not ( optional, defaults to false )
 *	}
 */	
ALIGN.showHelp = function(p) {
	/* check for required variables and explain if error */
	if(p == undefined) { alert('error in lb.js: ALIGN.showhelp line 20\n\nrequired parameter \'p\' is not defined.'); return };
	if(typeof p !== 'object') {
		/*	compensate for older parameter listing so we don't have to rewrite every call to showHelp
		 *	p = filename as string
		 *	arguments[1] integer as width
		 *	arguments[2] integer as height
		 */
		if(window.console !== undefined) {
			var errorParams = p + (arguments[1] != undefined ? ', ' + arguments[1]: '') + (arguments[2] != undefined ? ', ' + arguments[2]: '');
			console.warn('Legacy code calling lb.js: ALIGN.showhelp line 20\nrecommended parameter \'p\' is not of type object.\nUse syntax:\nALIGN.showHelp({file:\'/path/filename.flv\'}\n\nActual parameters sent to showHelp: [' + errorParams + ']');
		}; 
		if(typeof p == 'string') {
			p = {
				file: p,
				width: arguments[1],
				height: arguments[2]
			};
		}
	};
	if(p.file == undefined) { alert('error in lb.js: ALIGN.showhelp line 20\n\nrequired parameter \'file\' is not defined, therefore showHelp cannot determine what to show.'); return };
	if(document.getElementById('flashcontent') == undefined) {alert('Missing element \"flashcontent\" on page, required so showHelp can place content on the page.'); return};
	
	/* check for IE6 to hide all select tags on the page */
	if(navigator.userAgent.indexOf('MSIE 6.0') != -1 && document.getElementsByTagName('select')) {
		for(var i=0; i < document.getElementsByTagName('select').length; i++) {
			document.getElementsByTagName('select')[i].style.visibility='hidden';
		}
	}
	
	var windowShadow = document.getElementById('grayBackground');
	
	/* Set defaults for all modes */
	var itemHeight = p.height || 400;
	var itemWidth = p.width || 640;
	var borderHeight = 0;
	var borderWidth = 0;
	if(p.menu == undefined) {
		p.params = { menu: false };
	} else {
		p.params = { menu: p.menu };
	}

	/* set base parameter -CS- 11-1-10*/
	if( p.base != undefined ) {
	    p.params.base = p.base;
	}	

	windowShadow.style.visibility='visible';
	/* remove scrollbars from page, temporary can potentially allow scrolling behind the flash window? */
	document.getElementsByTagName('html')[0].style.overflow = 'hidden';

	/* here's where the work starts */
	
	if( p.file.indexOf('.flv') > 0 ) {
		if(p.flashSkinFile == undefined) {
			p.flashvars = { 
				flashSkinFile: '/SiteCollectionDocuments/VideoPlayer/Scripts/Skins/SteelExternalAll.swf',
				flashVideoFile: p.file,
				flashVideoWidth: itemWidth,
				flashVideoHeight: (itemHeight-40)
			};
		} else {
			p.flashvars = { 
				flashSkinFile: p.flashSkinFile,
				flashVideoFile: p.file,
				flashVideoWidth: itemWidth,
				flashVideoHeight: (itemHeight-40)
			};
		}
		var item = document.createElement('div');
		document.getElementById('flashcontent').appendChild(item);
		item.id = 'targetImage';
		swfobject.embedSWF('/SiteCollectionDocuments/VideoPlayer/VideoPlayer.swf', "targetImage", itemWidth, itemHeight, "9.0.0", "", p.flashvars, p.params );
		ALIGN.sizeHelp('targetImage', p);
	} else if ( p.file.indexOf('.swf') > 0 ) {
		var item = document.createElement('div');
		document.getElementById('flashcontent').appendChild(item);
		item.id = 'targetImage';
		//swfobject.embedSWF(p.file, item.id, itemWidth, itemHeight, "9.0.0", "");
		swfobject.embedSWF(p.file, item.id, itemWidth, itemHeight, "9.0.0", "", {}, p.params); // quick fix to allow passing base param to lb -CS- 11-1-10
		item.width = itemWidth;
		item.height = itemHeight;
		ALIGN.sizeHelp(item.id, p);
	} else if ( p.file.indexOf('.html') > 0 || p.file.indexOf('.aspx') > 0 ) {
		var item = document.createElement('iframe');
		item.id = 'targetImage';
		item.width = itemWidth;
		item.height = itemHeight;
		item.style.overflowX = 'hidden';
		item.style.border = 'none';
		item.frameborder = '0';
		item.src = p.file;
		document.getElementById('flashcontent').appendChild(item);
		ALIGN.sizeHelp();
	} else {
		var item = document.createElement('img');
		item.id = 'targetImage';
		item.onload = function() {
			document.getElementById('flashcontent').appendChild(this);
			ALIGN.sizeHelp();
		}
		item.src = p.file;
	}
};

/*	
 *	
 */
ALIGN.sizeHelp = function(elem, p) {
	if (window.pageYOffset) {
		ALIGN.scrollTop = window.pageYOffset;
	} else {
		ALIGN.scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	if(elem){
		var item = document.getElementById(elem);
	} else {
		var item = document.getElementById('targetImage');
	}
	var borderWidth = parseInt(item.width, 10) + 50;
	var borderHeight = parseInt(item.height, 10) + 50;
	
	var windowShadow = document.getElementById('grayBackground');
	windowShadow.style.width = (ALIGN.browserWidth + 50) + 'px';
	windowShadow.style.height = (ALIGN.browserHeight + 50) + 'px';
	windowShadow.style.top = ALIGN.scrollTop + 'px';
	
	document.getElementById('flashcontent').style.width = item.width + 'px';
	document.getElementById('flashcontent').style.height = item.height + 'px';
	
	document.getElementById('videoWindow').style.left = (ALIGN.browserWidth/2) - (borderWidth/2) - 10 + 'px';
	document.getElementById('videoWindow').style.top = (ALIGN.browserHeight/2) - (borderHeight/2) + 'px';
	document.getElementById('videoWindow').style.width = borderWidth + 'px';
	document.getElementById('videoWindow').style.height = borderHeight + 'px';
	window.onresize = ALIGN.sizeHelp;
},
ALIGN.closeHelp = function() {
	window.onresize = null;
	document.getElementsByTagName('html')[0].style.overflow = '';
	document.getElementById('grayBackground').style.visibility = 'hidden';
	ALIGN.closeElement('flashcontent', false);
	if(document.getElementsByTagName('object')[0]) {
		// unhide photo upload applet if it's on the screen
		document.getElementsByTagName('object')[0].style.visibility='visible';
	}
	if(navigator.userAgent.indexOf('MSIE 6.0') != -1 && document.getElementsByTagName('select')) {
		for(var i=0; i < document.getElementsByTagName('select').length; i++) {
			document.getElementsByTagName('select')[i].style.visibility='visible';
		}
	}
};
	
ALIGN.closeElement = function(elemID, self) {
	var elem, parent;
	if(typeof elemID == 'string') {
		elem = document.getElementById(elemID);
	} else {
		elem = elemID;
	}
	if(elem == null) {alert('Missing Element');return false;}
	parent = elem.parentNode;
	
	while(elem.firstChild) {
		elem.removeChild(elem.firstChild);
	}
	elem.innerHTML = '';
	if (self) {
		document.getElementsByTagName('body')[0].removeChild(elem);
	}
	return parent;
};



