/*****************************************************************
CUSTOM VERSION OF FILE FOR 3RD PARTY DISTRIBUTION - DO NOT USE ON PALM.COM!!!

File:lightbox.js
Description: File contains basic code elements for pdp and media
library lightboxs

Requires: 
	YUI (implemented with YUI 2.7)
	http://developer.yahoo.com/yui/

Modules:
	Lightbox initialization, browser window alignment, scrim init,
	generic bubble up/down event handler
	
Revisions: 
	Rev 1: 3/31/2009 - Created basic handler - KTH
	Rev 2: 4/11/2009 - Created thumbnail horiz. scrolling  - KTH
	Rev 3: 4/30/2009 - Added support for media library lightbox and scrim fades
	Rev 4: 5/19/2009 - Added support for accessible/captioned video player - Michael Jordan of Modernista!

Author: Palm IT Web Team

Notes: Suggest compression of all js files!
******************************************************************/

YAHOO.namespace('YAHOO.PALMLIGHTBOX');

//global lightbox handling code		
YAHOO.PALMLIGHTBOX.handler = function () {
	//PRIVATE VARIABLES and METHODS:
	this.objScrollTimer;
	var tempThumbCount=0;
	var tempLightboxConfig = ""; //=gallery, thumbnail, video, wtb(where to buy)


			
	//Event Handler for all the media(photos, screenshots, video) elements
	var gridEvtHandler = function(e) {
		YAHOO.util.Event.stopEvent(e);
		tg=YAHOO.util.Event.getTarget(e);
		while (tg.id != "features-grid") { //walk the event bubble 'down'
			if (tg.className.indexOf("open-") != -1) {
				if(window.navigator.userAgent.indexOf("webOS")>-1 
					|| window.navigator.userAgent.indexOf("iPhone")>-1  
					|| window.navigator.userAgent.indexOf("Android")>-1) { //if webOS or iPhone
					window.location.href="lightbox-extract.html#"+tg.rel;
				} else {
					showMediaLightbox(tg.rel);
				}
				break;
			} else {
				tg = tg.parentNode;
			}
		}
	};


	//Generic event handler with bubble-up functionality
	var buttonEvtHandler = function(e) {
		tg=YAHOO.util.Event.getTarget(e);
		while (tg.id != "features-buttons") { //walk the event bubble 'down'
			if (tg.className.indexOf("open-") != -1) {
				YAHOO.util.Event.stopEvent(e); //halt event unless link
				if(window.navigator.userAgent.indexOf("webOS")>-1 
					|| window.navigator.userAgent.indexOf("iPhone")>-1  
					|| window.navigator.userAgent.indexOf("Android")>-1) { //if webOS or iPhone
					window.location.href="lightbox-extract.html#"+tg.rel;
				} else {
					window.location.href=tg.href;
					showMediaLightbox(tg.rel);
				}
				break;
			} else {
				tg = tg.parentNode;
			}
		}
	};



	//Generic event handler with bubble-up functionality
	var lightboxEvtHandler = function(e) {

		//tg = e.target || e.srcElement;
		tg=YAHOO.util.Event.getTarget(e);
		//search through possible evt until the lightbox container object is hit
		while (tg.id != "lightbox-container") { //walk the event bubble 'down'
			//Lightbox Close Button
			if(tg.id == "lightbox-close") {
				YAHOO.util.Event.stopEvent(e);
				hide();
				return;
			}
			if(tg.id == "lightbox-nav-arrow-right") {
				YAHOO.util.Event.stopEvent(e);
				thumbSlide.move("right");
				return;
			}
			if(tg.id == "lightbox-nav-arrow-left") {
				YAHOO.util.Event.stopEvent(e);
				thumbSlide.move("left");
				return;
			}

			tempHREF = tg.href;
			//thumbnail click
			if(tg.className=="media-thumbnail"){
				YAHOO.util.Event.stopEvent(e);
				insertMediaContent(tempHREF, tg.title);
				return;							
			}
			tg = tg.parentNode;
		}
	};
	
	
	
	var insertMediaContent = function(targetHREF, targetTitle) {
		
		if(targetHREF.indexOf(".png") >=0 || targetHREF.indexOf(".jpg") >=0 || targetHREF.indexOf(".gif") >=0 || targetHREF.indexOf(".jpeg") >=0) {
			var mediaContentFadeOut = new YAHOO.util.Anim('lightbox-showcase-phone-display', { opacity: {from: 1, to: 0 } }, .3, YAHOO.util.Easing.easeOut);
			mediaContentFadeOut.onComplete.subscribe(function(){
				$('lightbox-showcase-phone-display').innerHTML = "";
				$('lightbox-showcase-phone-display').innerHTML = buildIMGtag(targetHREF, false, targetTitle);
				var mediaContentFadeIn = new YAHOO.util.Anim('lightbox-showcase-phone-display', { opacity: {from: 0, to:1 } }, .7, YAHOO.util.Easing.easeOut);
				mediaContentFadeIn.animate();
				
				});
			mediaContentFadeOut.animate();
			
		} 
		
		if(targetHREF.indexOf(".mov")>0
			|| targetHREF.indexOf('.smil') > 0) {
			if(tempLightboxConfig != "video") {
				YAHOO.util.Dom.setStyle('lightbox-showcase-phone-display' , 'top' , "35px" );
			}
			$('lightbox-showcase-phone-display').innerHTML = "";
			window.setTimeout( 	function(){
									buildFlashMovie('lightbox-showcase-phone-display', targetHREF);
								}, 200);
		}
		$('lightbox-showcase-phone-display').focus();
	}
	
	
	var buildFlashMovie= function(targetID,targetHREF) {
		//TODO: ADD FLASH DETECT AND serve link instead - add class A mobile media support too.
		var playerVersion = swfobject.getFlashPlayerVersion();
		//var output = "You have Flash player " + playerVersion.major + "." + playerVersion.minor + "." + playerVersion.release + " installed";
		if(playerVersion.major >= 9) {
			$(targetID).innerHTML = '<div id="swfObjectTarget"></div>'; //this is inserted because swfobject REPLACES this div

			var flashvars = {
				userID : "undefined", 
				s1 : targetHREF.replace(/\?&/,"&"), 
				s2 : "playing",	
				s3 : "", 
				s4 : ""
			};
			
			var params = {
				loop: "false",
				menu: "false",
				quality: "high",
				salign: "t",
				scale: "noscale",
				wmode: "window",
				bgcolor: "#e6e6e6",
				base: "",
				seamlesstabbing: "true",
				allowfullscreen: "true",
				allowscriptaccess: "sameDomain"
			};

			var attributes = {  
				id: "main_flash",
				name: "main_flash",
				style: "",
				tabindex: "500"
			};
			
			var playerPath = "/assets/flash/video/videoPlaya_640_400.swf";
			
			//if(targetHREF.indexOf("&captionsSource=") > 0){
				playerPath = "/us/company/advertising/pre/assets/flash/video/accVideoPlaya_640_400.swf";
				flashvars.skin = "/us/company/advertising/pre/assets/flash/video/PalmSkinOverAll.swf";
			//}
			
			
			swfobject.embedSWF(playerPath, "swfObjectTarget", "768", "432", "9.0.115","/us/company/advertising/pre/assets/flash/expressInstall.swf", flashvars, params, attributes);
		} else {
			$(targetID).innerHTML = '<div id="swfAltTarget" style="top:200px; left:155px; position:absolute; width:300px;"></div>'; //this is inserted because swfobject REPLACES this div
			//TODO: check for Quicktime capability and embed as necessary
			$("swfAltTarget").innerHTML = 'We\'re sorry but we can\'t find a Flash player<br /> for this content. <a href="http://www.adobe.com/products/flashplayer/" target="_new" style="color:#F0731E;">Click here to download the latest Adobe Flash player</a> or <a href="'+targetHREF+'" style="color:#F0731E;">click here to download file directly.</a>'; //place link to file here - registered mimetype will be necessary
		}
		return;
	}

	
	
	//properly builds IMG tag (returning HTML) and includes png handler if necessary, etc.
	//will also preload image for better UI performance - not implemented (TODO:)
	var buildIMGtag = function(imgURL, preload, altText) {
		var tmpHTML = "";
		if(imgURL.indexOf(".png")) { /*break this into function*/
			if (YAHOO.env.ua.ie == 6) {
				tmpHTML = '<img src="/assets/images/global/transPngFix.gif" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, ';
				tmpHTML += 'sizingMethod=image, src=\'' + imgURL + '\');" ';
				tmpHTML += (altText) ? 'alt="'+altText+'" ' : 'alt="" ';
				tmpHTML += '/>';
			}
			else {
				tmpHTML = '<img src="' + imgURL + '" ';
				tmpHTML += (altText) ? 'alt="'+altText+'" ' : 'alt="" ';
				tmpHTML += '/>';
			}
			return(tmpHTML);
		} //end png loader

		if(imgURL.indexOf(".jpg") || imgURL.indexOf(".gif") || imgURL.indexOf(".jpeg")) {
			tmpHTML = '<img src="' + imgURL + '" ';
			tmpHTML += (altText) ? 'alt="'+altText+'" ' : 'alt="" ';
			tmpHTML += '/>';
			return(tmpHTML);
		} //end png loader
		
		
	}
	
	
	
	//setup and show the scrim
	var setScrim = function(showScrim){
		if(showScrim) {
			$('scrim-layer').style.width = "100%"; 
			$('scrim-layer').style.height=YAHOO.util.Dom.getDocumentHeight()+"px";
			$('scrim-layer').style.display="block";
			var scrimFade = new YAHOO.util.Anim('scrim-layer', { opacity: {from: 0, to: .50 } }, .45, YAHOO.util.Easing.easeOut);
			scrimFade.animate();

			//insert iframe shim if the browser is IE(iframe-shim iframe only found within IE browsers - lightbox-js.html include file)
			if (YAHOO.env.ua.ie) {
				if(YAHOO.util.Dom.inDocument('iframe-shim')){
					$('iframe-shim').style.width = "100%"; 
					$('iframe-shim').style.height=YAHOO.util.Dom.getDocumentHeight()+"px";
					$('iframe-shim').style.display="block";
				}
			}
		} else {
			var scrimFade = new YAHOO.util.Anim('scrim-layer', { opacity: {from: .50, to: 0 } }, .45, YAHOO.util.Easing.easeOut);
			scrimFade.onComplete.subscribe(function(){$('scrim-layer').style.display="none";});
			scrimFade.animate();
			if(YAHOO.util.Dom.inDocument('iframe-shim')){
				$('iframe-shim').style.display="none";
			}
		}
	};
	
	
				
	//show lightbox functionality
	var showMediaLightbox = function(tURL) {
		setScrim(true);
		setLightboxContainer('container-overlay');
		getJSONandRenderThumbnails(tURL);
	};
	
	//hide lightbox
	var hide = function() {
		$('lightbox-showcase-phone-display').innerHTML = " ";
		$('media-link-container').innerHTML = " ";
		$('container-overlay').style.visibility="hidden";
		setScrim(false);
		$('container-overlay').style.display="none";
		//reset class
		$('lightbox-frame-top').className = "";
		if (YAHOO.env.ua.ie == 6) {
			$('lightbox-frame-top').style.filter = "";
			//$('lightbox-base').style.filter = "";
			
		}
		$('lightbox-showcase').className = "";
		//$('lightbox-base').className = "";
		window.location.href = window.location.href.split("#")[0];

	};			
	
	
	
	/**********************************************************************************/
	/**BEGIN lightbox positioning methods                                            **/
	/**********************************************************************************/
	//properly position the lightbox
	var lightboxTarget = 'container-overlay' ;
	var setLightboxPosition = function(isResize) {
		var testRegion = YAHOO.util.Dom.getRegion(lightboxTarget);//'lightbox-container');
		var lightboxWidth = testRegion.right - testRegion.left;
		var lightboxHeight = testRegion.bottom - testRegion.top;
		var tempTop = 0 ;
		var tempLeft = 0;
		var viewportHeight = YAHOO.util.Dom.getViewportHeight()
		if(isResize) {
			if (viewportHeight > lightboxHeight) { //if the lightbox does not fit on page, we will not set the top position
				tempTop = YAHOO.util.Dom.getDocumentScrollTop() + ((viewportHeight/2) - (lightboxHeight/2));
				tempLeft = ((YAHOO.util.Dom.getViewportWidth()/2 ) - (lightboxWidth/2));
				var topAnim = new YAHOO.util.Anim(lightboxTarget, { top: { from: testRegion.top, to: tempTop }, left:{from:testRegion.left, to:tempLeft} }, .3, YAHOO.util.Easing.easeOut);
				topAnim.animate();

			} 
		} else {
			$(lightboxTarget).style.top = YAHOO.util.Dom.getDocumentScrollTop() + ((viewportHeight/2) - (lightboxHeight/2)) + "px";
			$(lightboxTarget).style.left=((YAHOO.util.Dom.getViewportWidth()/2 ) - (lightboxWidth/2))+"px";					
		}
	};
	
	
	//position and display lightbox
	var setLightboxContainer = function(targetID){
		if(YAHOO.util.Dom.inDocument(targetID)){
			lightboxTarget =targetID;
			$(targetID).style.display="block";
			setLightboxPosition(false);
			$(targetID).style.visibility="visible";
		}
		return;
	};
	

	//locate lightbox when browser resizes (called from resize evt)				
	var resizeHandler = function(e) {
		if($('scrim-layer').style.display=="block"){
			//setScrim(true);
			setLightboxPosition(true);
		}
	};
	
	//handle lightbox position on scroll - fork timed method to smooth the bumpy ride
	var scrollHandler = function() {
		if ($(lightboxTarget).style.visibility == "visible") {
			window.clearInterval(this.objScrollTimer);
			this.objScrollTimer = window.setInterval(scrollTimedMethod,300)
		}				
	};	
	
	//called from interval timer (scrollHandler)
	var scrollTimedMethod = function () {
		window.clearInterval(this.objScrollTimer);
		setLightboxPosition(true);
	};
	/**********************************************************************************/
	/**END lightbox positioning methods                                              **/
	/**********************************************************************************/
		
		
		
		/***********************************************************
		**left and right scrolling object
		**use: thumbSlide.init(<direction>);
		**example:
		************************************************************/
		var thumbSlide = function () {
			var isRunning = false;
			var thumbTotalCount = 0;
			var thumbVisibleSpacing = 0;
			var thumbVisibleCount = 0;
			var currentLeftPosition = 0; //tracks left position
			var tempThumbScrollTiming = .9;
			
			var scrollThumbs = function(direction) {
				var tempLastPosition = currentLeftPosition;
				var totalSpacing = thumbTotalCount * thumbVisibleSpacing;
				var segmentSpacing = thumbVisibleCount * thumbVisibleSpacing;
				if(direction=="left") {
					if(currentLeftPosition < 0) {
						currentLeftPosition = currentLeftPosition + segmentSpacing; //remember to add against negative number
						var leftAnim = new YAHOO.util.Anim('media-link-scroll', { left: { from: tempLastPosition, to: currentLeftPosition } }, tempThumbScrollTiming, YAHOO.util.Easing.easeOut);
						leftAnim.onComplete.subscribe(function(){setNavArrows(currentLeftPosition,segmentSpacing,totalSpacing);});
						leftAnim.animate();
					} else {
						setNavArrows(currentLeftPosition,segmentSpacing,totalSpacing);
					}
				}
				if(direction=="right") {
					if((currentLeftPosition-segmentSpacing)>(totalSpacing*-1) ) {
						currentLeftPosition = currentLeftPosition - segmentSpacing;
						var rightAnim = new YAHOO.util.Anim('media-link-scroll', { left: { from: tempLastPosition, to: currentLeftPosition } }, tempThumbScrollTiming, YAHOO.util.Easing.easeOut);
						rightAnim.onComplete.subscribe(function(){setNavArrows(currentLeftPosition,segmentSpacing,totalSpacing);});
						rightAnim.animate();
						
					}
				}
				isRunning = false;
			}
			//shows or dims the left and right arrows
			var setNavArrows = function(curPos, segSpacing, totSpacing) {
				if(thumbTotalCount <= thumbVisibleCount) {
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-right' , 'opacity' , 0 ) ;
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-right' , 'cursor' , "inherit" ) ;
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-left' , 'opacity' , 0 ) ;
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-left' , 'cursor' , "inherit" ) ;
					return;
				}
				tempNextSegPos = (segSpacing *-1)+curPos;
				if(tempNextSegPos <= (totSpacing*-1)) {
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-right' , 'opacity' , .2 ) ;
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-right' , 'cursor' , "inherit" ) ;
				}else{
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-right' , 'opacity' , 1.0 ) ;
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-right' , 'cursor' , "pointer" ) ;
				}
				//handle the left arrow
				if(curPos == 0 ) {
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-left' , 'opacity' , .2 ) ;
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-left' , 'cursor' , "inherit" ) ;
				}else{
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-left' , 'opacity' , 1 ) ;
					YAHOO.util.Dom.setStyle('lightbox-nav-arrow-left' , 'cursor' , "pointer" ) ;
				}
				return;
			}
			return { //PUBLIC methods
				move: function(direction) {
					if(isRunning == false || direction == "left" || direction == "right") {
						isRunning = true;
						scrollThumbs(direction);
					} else {
						return;	
					}
					
				},
				setupScroll: function(thumbCount,thumbSpacing,thumbVisible, thumbScrollTiming) { //initialize everything!
					isRunning = false;
					thumbTotalCount = 0;
					thumbVisibleSpacing = 0;
					thumbVisibleCount = 0;
					currentLeftPosition = 0; //tracks left position
					tempThumbScrollTiming = .9;
					thumbTotalCount = thumbCount;
					thumbVisibleSpacing = thumbSpacing;
					thumbVisibleCount = thumbVisible;
					tempThumbScrollTiming = thumbScrollTiming;
					//setup the Navigation arrows
					setNavArrows(0, (thumbVisibleSpacing*thumbVisibleCount), (thumbVisibleSpacing*thumbTotalCount));
				}
			};
		}();
	/*********************************************************************
	**end scrolling object
	*********************************************************************/

	/**********************************************************************
	BEGIN ********lightbox thumbnail JSON loader methods**********
	**********************************************************************/
	var getJSONandRenderThumbnails = function(JSONURL){
		sUrl = JSONURL; 
		var getThumbnails = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, null); //start connection manager and get JSON data - need to create dynamic URL generation
	};
	
	var responseSuccess = function(o) {
		tempTMZ = o.responseText ;
		//if the responseText is invalid, we'll overwrite
		if (!YAHOO.lang.JSON.isValid(tempTMZ)) {
			//find comment pattern and remove - not sure why our json data has comment string and why the Yahoo parser can't handle
			//lets revisit this dog and pony show
			var tempTMZstart = o.responseText.indexOf("/*");
			var tempTMZend = o.responseText.indexOf("*/")
			if (tempTMZend > 0 && tempTMZstart > 0) {
				var tempTMZ = o.responseText.substring(0, tempTMZstart);
				tempTMZ += o.responseText.substring(tempTMZend + 2, o.responseText.length);
			}
		}
		parseJSON(tempTMZ) ; //lets get busy with making parsing JSON and making html
	};
	
	var responseFailure = function(o) {
		//TODO: HANDLE XHR FAILURE PROPERLY
		hide();
	};
	
	var callback = {
	  success:responseSuccess,
	  failure:responseFailure,
	  argument:"",
	  cache:false
	};
	
	//convert the JSON data into raw HTML and insert within the media-link-container	
	var parseJSON = function (JSONdata) {
		var parsedJSONdata = YAHOO.lang.JSON.parse(JSONdata); //TODO wrap with try and handle parse failure

		//set class based on the device or if its a generic lightbox such as video or gallery
		tempLightboxConfig =parsedJSONdata.lightboxConfig.targetDevice; //this global is used as a switch several functions
		
		$('lightbox-base').className = "lightbox-base " +tempLightboxConfig+"-lightbox-base";
		$('lightbox-container').className = "lightbox-container " +tempLightboxConfig+"-lightbox-container";
		
		$('lightbox-frame-top').className = tempLightboxConfig+"-top";
		$('lightbox-showcase').className = tempLightboxConfig+"-showcase";
		//$('lightbox-showcase').style.background="url('"+parsedJSONdata.lightboxConfig.lightboxShowcaseBG+"') no-repeat transparent')";
		if (YAHOO.env.ua.ie == 6) {
			$('lightbox-base').style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='image', src='"+parsedJSONdata.lightboxConfig.lightboxBase+"')";
			$('lightbox-frame-top').style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='image', src='"+parsedJSONdata.lightboxConfig.lightboxTop+"')";
		}
		$('lightbox-showcase-phone-display').style.top = ""; //reset inline style to default css to run	
	
		var tempThumbnailSpacing = parsedJSONdata.lightboxConfig.thumbnailSpacing;
		var tempThumbScrollTiming = parsedJSONdata.lightboxConfig.tempThumbScrollTiming;
		
		//build the thumbnails
		var tempHTML = '<div id="media-link-scroll" style="left:0px;">';
		tempThumbCount = parsedJSONdata.content.length ;
		tempThumbVisibleCount = parsedJSONdata.lightboxConfig.thumbnailVisibleCount;
		
		
		//setup slider object
		thumbSlide.setupScroll(tempThumbCount,tempThumbnailSpacing,tempThumbVisibleCount, tempThumbScrollTiming);//sets the private variable for the slider action
				
		//loop elements and output html
		for ( var JSONcontents in parsedJSONdata.content ) {
			
			var src = parsedJSONdata.content[JSONcontents].src;
			
			if(src.indexOf('.mov') > 0
				|| src.indexOf('.smil') > 0) {
				if(parsedJSONdata.content[JSONcontents].rotation == "true") { //movie player object
					src += '?&s5=true';
				} else {
					src += '?&s5=false';
				}
				if(parsedJSONdata.content[JSONcontents].captions) { //movie player object
					src += '&captionsSource='+parsedJSONdata.content[JSONcontents].captions;
				}
			}
			
			if(JSONcontents==0) {
				var tempInitInsert = src;
				var tempInitTitle = parsedJSONdata.content[JSONcontents].title;
				window.setTimeout(function(){insertMediaContent(tempInitInsert, tempInitTitle);}, 500);
			}
			
			tempHTML += '<div style="left:'+(tempThumbnailSpacing*JSONcontents)+'px;width:125px;">';
			tempHTML += '<a href="' + src + '" title="' + parsedJSONdata.content[JSONcontents].title;
			tempHTML += '" class="media-thumbnail" tabindex="'+ (504+JSONcontents) +'">' + buildIMGtag(parsedJSONdata.content[JSONcontents].thumb, false, parsedJSONdata.content[JSONcontents].title) + '</a>';				
			tempHTML += '</div>';
		}
		tempHTML += '</div>\n';  //don't forget the little duck at the end
		
		//insert HTML into page container
		$('media-link-container').innerHTML = tempHTML;
		
		setLightboxPosition(true);
	};
	/**********************************************************************/
	//END ********lightbox thumbnail JSON loader methods**********
	/**********************************************************************/
		
	//YAHOO.PALMLIGHTBOX.handler PUBLIC METHODS:
	return  {
		init: function(){
			//setup events (script designed for loading bottom of screen)
			if(YAHOO.util.Dom.inDocument('features-grid')){
				if($('features-grid').className.indexOf('extlink') == -1) {
					YAHOO.util.Event.addListener('features-grid', 'click', gridEvtHandler);
				}
			}
			if(YAHOO.util.Dom.inDocument('features-buttons')){
				if($('features-buttons').className.indexOf('extlink') == -1) {
					YAHOO.util.Event.addListener('features-buttons', 'click', buttonEvtHandler);
				}
			}		
			//since we are rolling up several lightboxes, we'll need to make sure and handle these evt differently.
			if(YAHOO.util.Dom.inDocument('lightbox-container')){
				YAHOO.util.Event.addListener('lightbox-container', 'click', lightboxEvtHandler);
			}		
			YAHOO.util.Event.addListener(window, 'resize', resizeHandler);
			YAHOO.util.Event.addListener(window, 'scroll', scrollHandler);
		},
		loadLightbox: function(lightboxName) {
				var tempLocationHREF = window.location.href;
				var tempRootHref = tempLocationHREF.split("index.html");
				if(lightboxName.length > 0 ) {
					if(lightboxName == "mediaLib"){
						showMediaLibraryLightbox("");
					}
					if(lightboxName == "video") { //open-meet
						var vds=YAHOO.util.Dom.getElementsByClassName( 'open-meet' , 'a' , 'features-buttons') ;
						if(vds.length>0){
							if(window.navigator.userAgent.indexOf("webOS")>-1 || window.navigator.userAgent.indexOf("iPhone")>-1  || window.navigator.userAgent.indexOf("Android")>-1) { //if webOS or iPhone
								window.location.replace(tempRootHref[0]+"lightbox-extract.html#"+vds[0].rel);
							} else {
								showMediaLightbox(vds[0].rel);
							}
						}
					}
					if(lightboxName == "gallery") { //open-gallery
						var vds=YAHOO.util.Dom.getElementsByClassName( 'open-gallery' , 'a' , 'features-buttons') ;
						if(vds.length>0){
							if(window.navigator.userAgent.indexOf("webOS")>-1 || window.navigator.userAgent.indexOf("iPhone")>-1  || window.navigator.userAgent.indexOf("Android")>-1) { //if webOS or iPhone
								window.location.replace(tempRootHref[0]+"lightbox-extract.html#"+vds[0].rel);
							} else {
								showMediaLightbox(vds[0].rel);
							}
						}
					}
				}
		}
		
	};
}(); //autoload

YAHOO.PALMLIGHTBOX.handler.init();


/**********************************************************************/
/**********end lightbox JavaScript*********/				
/**********************************************************************/
    	