/* SWFFix 0.3 http://swffix.googlecode.com/ Copyright 2007 Stearns, Williams, and van der Sluis, with the MIT License. */
// We should update to the newest SWFObject/SWFFix
var SWFFix=function(){var _1=[main];var _2=[];var _3=null;var _4=null;var _5=false;var _6=false;var _7=false;var _8=false;var ua=function(){var _a=typeof document.getElementById!="undefined"&&typeof document.getElementsByTagName!="undefined"&&typeof document.createElement!="undefined";var u=navigator.userAgent.toLowerCase();var _c=/win/.test(u);var _d=/mac/.test(u);var _e=/opera/.test(u);var _f=_e?parseFloat(u.replace(/^.*opera ?\/?(\d+(\.\d+)?).*$/,"$1")):0;var ie=!_e&&/msie/.test(u);var _11=ie?parseFloat(u.replace(/^.*msie (\d+\.\d+).*$/,"$1")):0;var _12=/webkit/.test(u);var _13=_12?parseFloat(u.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):0;var _14=[0,0,0];if(navigator.plugins&&typeof navigator.plugins["Shockwave Flash"]=="object"){var d=navigator.plugins["Shockwave Flash"].description;if(typeof d!="undefined"){d=d.replace(/^.*\s+(\S+\s+\S+$)/,"$1");_14[0]=parseInt(d.replace(/^(.*)\..*$/,"$1"),10);_14[1]=parseInt(d.replace(/^.*\.(.*)\s.*$/,"$1"),10);_14[2]=/r/.test(d)?parseInt(d.replace(/^.*r(.*)$/,"$1"),10):0;}}else{if(window.ActiveXObject){var _16=false;try{var a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_14=[6,0,21];a.AllowScriptAccess="always";}catch(e){if(_14[0]==6){_16=true;}}if(!_16){try{a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}}if(!_16&&typeof a=="object"){var d=a.GetVariable("$version");if(typeof d!="undefined"){d=d.split(" ")[1].split(",");_14=[parseInt(d[0],10),parseInt(d[1],10),parseInt(d[2],10)];}}}}return {w3cdom:_a,win:_c,mac:_d,opera:_e,operaVersion:_f,ie:ie,ieVersion:_11,webkit:_12,webkitVersion:_13,playerVersion:_14};}();var _1a=function(){if(!ua.w3cdom){return;}if(ua.ie&&ua.win){document.write("<script id=__ie_ondomload defer=true src=//:></script>");document.getElementById("__ie_ondomload").onreadystatechange=function(){if(this.readyState=="complete"){this.parentNode.removeChild(this);callDomLoadFunctions();}};}if(ua.webkit){_3=setInterval(function(){if(/loaded|complete/.test(document.readyState)){callDomLoadFunctions();}},10);}if(typeof document.addEventListener!="undefined"){document.addEventListener("DOMContentLoaded",callDomLoadFunctions,null);}addLoadEvent(callDomLoadFunctions);}();function callDomLoadFunctions(){if(_5){return;}_5=true;if(_3){clearInterval(_3);_3=null;}var dl=_1.length;for(var i=0;i<dl;i++){_1[i]();}}function addDomLoadEvent(fn){_1[_1.length]=fn;}function addLoadEvent(fn){if(typeof window.addEventListener!="undefined"){window.addEventListener("load",fn,false);}else{if(typeof document.addEventListener!="undefined"){document.addEventListener("load",fn,false);}else{if(typeof window.attachEvent!="undefined"){window.attachEvent("onload",fn);}else{if(typeof window.onload=="function"){var _1f=window.onload;window.onload=function(){_1f();fn();};}else{window.onload=fn;}}}}}function main(){var rl=_2.length;for(var i=0;i<rl;i++){var id=_2[i].id;var obj=document.getElementById(id);if(hasPlayerVersion(_2[i].swfVersion)){if(ua.webkit&&ua.webkitVersion<312){fixParams(obj);}else{if(!_6&&ua.win&&ua.ie&&ua.ieVersion>=6){_6=true;if(document.readyState=="complete"){fixIEActiveContent();}else{window.attachEvent("onload",fixIEActiveContent);}window.attachEvent("onbeforeunload",fixOutOfMemoryError);window.attachEvent("onunload",fixObjectLeaks);}else{if(!_7&&ua.opera&&ua.operaVersion>=9){_7=true;addLoadEvent(fixActiveContent);}}}}else{if(hasPlayerVersion([1,0,0])){if(!_8&&_2[i].expressInstall&&(ua.win||ua.mac)&&hasPlayerVersion([6,0,65])){displayExpressInstallDialog(_2[i]);}else{displayAltContent(obj);}}}createCSS("#"+id,"visibility:visible");}}function fixParams(obj){var _25=obj.getElementsByTagName("object")[0];if(typeof _25!="undefined"){var e=document.createElement("embed");var a=_25.attributes;var al=a.length;for(var i=0;i<al;i++){if(a[i].nodeName.toLowerCase()=="data"){e.setAttribute("src",a[i].nodeValue);}else{e.setAttribute(a[i].nodeName,a[i].nodeValue);}}var c=_25.childNodes;var cl=c.length;for(var i=0;i<cl;i++){if(c[i].nodeType==1&&c[i].nodeName.toLowerCase()=="param"){e.setAttribute(c[i].getAttribute("name"),c[i].getAttribute("value"));}}obj.parentNode.replaceChild(e,obj);}}function fixIEActiveContent(){var o=document.getElementsByTagName("object");var ol=o.length;for(var i=0;i<ol;i++){var c=o[i].childNodes;var cl=c.length;var _32="";for(var j=0;j<cl;j++){if(c[j].nodeType==1&&c[j].nodeName.toLowerCase()=="param"){_32+=c[j].outerHTML;}}o[i].outerHTML=o[i].outerHTML.split(">")[0]+">"+_32+o[i].innerHTML+"</object>";}}function fixOutOfMemoryError(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};}function fixObjectLeaks(){var o=document.getElementsByTagName("object");var ol=o.length;for(var i=0;i<ol;i++){o[i].style.display="none";for(var x in o[i]){if(typeof o[i][x]=="function"){o[i][x]=function(){};}}}}function fixActiveContent(){var o=document.getElementsByTagName("object");var ol=o.length;for(var i=0;i<ol;i++){if(o[i].getAttribute("type")=="application/x-shockwave-flash"){var c=o[i].cloneNode(true);o[i].parentNode.replaceChild(c,o[i]);}}}function displayExpressInstallDialog(_3c){_8=true;var obj=document.getElementById(_3c.id);_4=_3c.altContent?document.getElementById(_3c.altContent):abstractAltContent(obj);var w=_3c.width?_3c.width:obj.getAttribute("width");if(parseInt(w,10)<310){w="310";}var h=_3c.height?_3c.height:obj.getAttribute("height");if(parseInt(h,10)<137){h="137";}var pt=ua.ie&&ua.win?"ActiveX":"PlugIn";var dt=document.title=document.title.slice(0,47)+" - Flash Player Installation";var fv="MMredirectURL="+window.location+"&MMplayerType="+pt+"&MMdoctitle="+dt;var el=obj;if(ua.win&&ua.ie&&obj.readyState!=4){el=document.createElement("div");obj.parentNode.insertBefore(el,obj);obj.style.display="none";window.attachEvent("onload",function(){obj.parentNode.removeChild(obj);});}createSWF({data:_3c.expressInstall,id:"SWFFixEID",width:w,height:h},{flashvars:fv},el);}function displayAltContent(obj){obj.parentNode.replaceChild(abstractAltContent(obj),obj);}function abstractAltContent(obj){var ac=document.createElement("div");if(ua.win&&ua.ie){ac.innerHTML=obj.innerHTML;}else{var _47=obj.getElementsByTagName("object")[0];if(typeof _47!="undefined"){var c=_47.childNodes;var cl=c.length;for(var i=0;i<cl;i++){if(!(c[i].nodeType==1&&c[i].nodeName.toLowerCase()=="param")&&!(c[i].nodeType==8)){ac.appendChild(c[i].cloneNode(true));}}}}return ac;}function createSWF(_4b,_4c,el){if(ua.ie&&ua.win){var att="";for(i in _4b){if(i=="data"){_4c.movie=_4b[i];}else{if(i!="classid"){att+=" "+i+"=\""+_4b[i]+"\"";}}}var par="";for(i in _4c){par+="<param name=\""+i+"\" value=\""+_4c[i]+"\" />";}el.outerHTML="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\""+att+">"+par+"</object>";}else{if(ua.webkit&&ua.webkitVersion<312){var o=document.createElement("embed");o.setAttribute("type","application/x-shockwave-flash");for(i in _4b){if(i=="data"){o.setAttribute("src",_4b[i]);}else{if(i!="classid"){o.setAttribute(i,_4b[i]);}}}for(i in _4c){if(i!="movie"){o.setAttribute(i,_4c[i]);}}el.parentNode.replaceChild(o,el);}else{var o=document.createElement("object");o.setAttribute("type","application/x-shockwave-flash");for(i in _4b){if(i!="classid"){o.setAttribute(i,_4b[i]);}}for(i in _4c){if(i!="movie"){createObjParam(o,i,_4c[i]);}}el.parentNode.replaceChild(o,el);}}}function createObjParam(el,_53,_54){var p=document.createElement("param");p.setAttribute("name",_53);p.setAttribute("value",_54);el.appendChild(p);}function hasPlayerVersion(rv){return (ua.playerVersion[0]>rv[0]||(ua.playerVersion[0]==rv[0]&&ua.playerVersion[1]>rv[1])||(ua.playerVersion[0]==rv[0]&&ua.playerVersion[1]==rv[1]&&ua.playerVersion[2]>=rv[2]))?true:false;}function createCSS(sel,_58){if(ua.ie&&ua.mac){return;}var h=document.getElementsByTagName("head")[0];var s=document.createElement("style");s.setAttribute("type","text/css");s.setAttribute("media","screen");if(!(ua.ie&&ua.win)){s.appendChild(document.createTextNode(sel+" {"+_58+"}"));}h.appendChild(s);if(ua.ie&&ua.win&&document.styleSheets&&document.styleSheets.length>0){var ls=document.styleSheets[document.styleSheets.length-1];if(typeof ls.addRule=="object"){ls.addRule(sel,_58);}}}return {registerObject:function(_5c,_5d,_5e){if(!ua.w3cdom||!_5c){return;}var _5f={};_5f.id=_5c;createCSS("#"+_5c,"visibility:hidden");if(_5d){var v=_5d.split(".");_5f.swfVersion=[parseInt(v[0],10),parseInt(v[1],10),parseInt(v[2],10)];}else{_5f.swfVersion=[0,0,0];}_5f.expressInstall=_5e?_5e:false;_2[_2.length]=_5f;},embedSWF:function(_61,_62,_63,_64,_65,_66,_67,_68,_69){if(!ua.w3cdom||!_61||!_62||!_63||!_64||!_65){return;}if(hasPlayerVersion(_65.split("."))){createCSS("#"+_62,"visibility:hidden");var att=(typeof _69=="object")?_69:{};att.data=_61;att.width=_63;att.height=_64;var par=(typeof _68=="object")?_68:{};if(typeof _67=="object"){for(var i in _67){if(typeof par.flashvars!="undefined"){par.flashvars+="&"+i+"="+_67[i];}else{par.flashvars=i+"="+_67[i];}}}addDomLoadEvent(function(){createSWF(att,par,document.getElementById(_62));createCSS("#"+_62,"visibility:visible");});}else{if(_66&&!_8&&(ua.win||ua.mac)&&hasPlayerVersion([6,0,65])){createCSS("#"+_62,"visibility:hidden");addDomLoadEvent(function(){var _6d={};_6d.id=_6d.altContent=_62;_6d.width=_63;_6d.height=_64;_6d.expressInstall=_66;displayExpressInstallDialog(_6d);createCSS("#"+_62,"visibility:visible");});}}},getFlashPlayerVersion:function(){return {major:ua.playerVersion[0],minor:ua.playerVersion[1],release:ua.playerVersion[2]};},hasFlashPlayerVersion:function(_6e){return hasPlayerVersion(_6e.split("."));},expressInstallCallback:function(){if(_8&&document.getElementById("SWFFixEID")&&_4){var obj=document.getElementById("SWFFixEID");obj.parentNode.replaceChild(_4,obj);_4=null;_8=false;}}};}();

/* BrowserDetect: http://www.quirksmode.org/js/detect.html */
var BrowserDetect={
	init:function() { this.browser = this.searchString(this.dataBrowser) || "Unknown Browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "Unknown Version"; this.OS = this.searchString(this.dataOS) || "Unknown OS"; },
	searchString:function(data) { for (var i=0;i<data.length;i++)	{ var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) {return data[i].identity;} } else if (dataProp) { return data[i].identity; } } },
	searchVersion:function(dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) {return;} return parseFloat(dataString.substring(index+this.versionSearchString.length+1)); },
	dataBrowser:[
		{ string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" },
		{ string: navigator.vendor, subString: "Apple", identity: "Safari" },
		{ prop: window.opera, identity: "Opera" },
		{ string: navigator.vendor, subString: "iCab", identity: "iCab" },
		{ string: navigator.vendor, subString: "KDE", identity: "Konqueror" },
		{ string: navigator.userAgent, subString: "Firefox", identity: "Firefox" },
		{ string: navigator.vendor, subString: "Camino", identity: "Camino" },
		{ string: navigator.userAgent, subString: "Netscape", identity: "Netscape" }, // newer Netscapes (6+)
		{ string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE" },
		{ string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" },
		{ string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla" } // older Netscapes (4-)
	],
	dataOS:[{ string: navigator.platform, subString: "Win", identity: "Windows" }, { string: navigator.platform, subString: "Mac", identity: "Mac" }, { string: navigator.platform, subString: "Linux", identity: "Linux" } ]
}; BrowserDetect.init();

/* make sure the lytebox script is available */
var script  = document.createElement('script');
script.src  = 'lytebox.js';
script.type = 'text/javascript';
document.getElementsByTagName('head').item(0).appendChild(script);

/* XML parsing code */
var xmlDoc;
var fgInnerHtml = '';
function loadXML() {
	// code for IE
	if (window.ActiveXObject) {
	  	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  	xmlDoc.async=false;
	  	xmlDoc.load(PicLensLite.feedXML_);
		getmessage();
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument) {
	  	xmlDoc=document.implementation.createDocument("","",null);
	  	xmlDoc.load(PicLensLite.feedXML_);
		xmlDoc.onload=getmessage;
	}
	else {
	  alert('Your browser cannot handle this script');
	}
}

function getmessage() {
	var x = xmlDoc.getElementsByTagName('*');
	fgInnerHtml = PicLensLite.flash_fg_.innerHTML +
		'<link rel="stylesheet" href="http://lite.piclens.com/lytebox/lytebox.css" type="text/css" media="screen" />' +
		'<div id="lightbox_images" align="center" style="padding-top:10px; color:#FFFFFF; font-size:12px; color:#999999;">';
	var firstImage = true;
	for (i = 0; i < x.length; i++) {
		if (x[i].nodeName == "media:content") {
			var strURL = x[i].getAttribute("url");
			//alert(x[i].childNodes[0].nodeValue);
			if (strURL.indexOf(".flv") == -1) {
				if (firstImage) {
					fgInnerHtml = fgInnerHtml + 
					'( Alternatively, click <a href="'+x[i].getAttribute("url")+'" rel="lyteshow[lite]">' +
					'here</a> for a basic slideshow )';
					firstImage = false;
				} else {
					fgInnerHtml = fgInnerHtml + 
					'<a href="'+x[i].getAttribute("url")+'" rel="lyteshow[lite]"></a>';
				}
			}
		}
	}
	PicLensLite.flash_fg_.innerHTML = fgInnerHtml;
	myLytebox.updateLyteboxItems();
}

// PicLens Lite 1.0
//
// We should also prefetch the smaller logo images to improve the responsiveness of the initial download
// Ideally, we can also clean this JS file up, but that is lower priority. (Correctness before Performance) :^)
var PicLensLite = {

	// The PicLensLite public API contains one function: either call PicLensLite.start(), or pass in an object literal with named arguments, e.g., PicLensLite.start({feedUrl:'http://myWebsite.com/myFeed.xml'});
	start : function(namedArgs) {
		
		// if piclens already exists... launch the client
		if (window.piclens) {
			//window.piclens.start;
			//alert("Piclens Exists");
			//window.piclens.launch();
		}
		
		
		// clear the fields as if they have been set before...
		this.homepageLabel_ = "";
		this.feedXML_ = "";

		// clear this so that we will have to reinstantiate the flash object
		this.flash_bg_ = false;
		
		// the feed to load	
		var targetFeedUrl = "";
		var feedData;
	
		// the named arguments we support
		if (typeof namedArgs != "undefined") {
			if (typeof namedArgs.homePageLabel != "undefined") {
				this.homepageLabel_ = namedArgs.homePageLabel;
			}
			if (typeof namedArgs.feedUrl != "undefined") {
				targetFeedUrl = namedArgs.feedUrl;
			} 
			if (namedArgs.feedData) { // pass in the feed XML directly through Javascript
				feedData = namedArgs.feedData;
			}
		}
		
		if (feedData) {
			this.feedXML_ = feedData;
			this.showFlashUI();
		} else if (targetFeedUrl == "") {
			if (!this.feeds_) { // build list of XML feeds
				this.indexFeeds();
			}
			if (this.feeds_.length != 0) { // view the first feed, if available
				var feed = this.feeds_[0];
				this.startWithUrl(feed.url);
			}
		} else {
			this.startWithUrl(targetFeedUrl); // open the specified URL
		}
	},

	// PRIVATE API BELOW...
	MARGIN_W         : 80, // for the lightbox
	MARGIN_H         : 60,
	MARGIN_W_THIN    : 60,
	MARGIN_H_THIN    : 20,
	MARGIN_W_THIN_2  : 120,
	MARGIN_H_THIN_2  : 40,
	PLL_URL          : "http://lite.piclens.com/",
	FL_URL           : "http://lite.piclens.com/current/PicLensLite.swf",
	FL_URL_DEBUG_WEB : "http://staging.lite.piclens.com/current/PicLensLite.swf",
	FL_URL_DEBUG_FS  : "../bin/PicLensLite.swf",
	FL_GIF             : "http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif",
	GET_FL             : "http://www.adobe.com/go/getflashplayer",
	PL2				   : "PLLFlash2",
	
	piclensIsRunning_  : false,	
	feeds_             : null,
	xmlLoader_         : null,
	fadeTimer_         : null,
	homepageLabel_     : "",	
	feedXML_           : "",
	
	isSafari           : navigator.userAgent.indexOf('Safari') != -1,
	isIE			   : navigator.userAgent.indexOf('Firefox') != -1,
	isFirefox		   : navigator.userAgent.indexOf('MSIE') != -1,
	isIE6 : function() {
		try {
			if (typeof document.body.style.maxHeight === "undefined") { // IE 6
				return true;
			} else {
				return false;
			}
		} catch (e) {
			return false;
		}
	},
	startWithUrl : function(feedUrl) {
		this.feedXML_ = feedUrl;
		if (this.xmlLoader_) { // cancel any pending load
			this.xmlLoader_.abort();
			this.xmlLoader_ = null;
		}

		// start loading XML
		var self = this; this.xmlLoader_ = this.createXHR(feedUrl, function() { self.onLoadStatusChanged(); });

		this.showFlashUI();
	},
	addKeyHandlers : function() {
		var self = this;
		document.onkeydown = function(e){
	        if (e == null) { // ie
	          keycode = event.keyCode;
	        } else { // mozilla
	          keycode = e.which;
	        }

	        if (keycode == 27){ // ESC to close
				self.closeFlashUI();
	        } else {
	        	// forward to Flash
	        	self.keyPressed(keycode);
	        }
	        return false;
		}

		// this is the handler for forwarding mouse scroll info to the flash component
		this.forwardMouseScroll_ = function(e) {self.scrollWheelMoved(e); return false;}; 

		// remove mouse scroll
		if (window.addEventListener) {
			window.addEventListener("DOMMouseScroll", this.forwardMouseScroll_, false);
		}
		// do stuff for IE/Opera/etc..
		if (document.attachEvent) {
			document.attachEvent("onmousewheel", this.forwardMouseScroll_);
		}
		// other browsers?
		// TODO: perhaps we should only do ONE of these, but not ALLL....
		window.onmousewheel = document.onmousewheel = this.forwardMouseScroll_;
	},
	sendTextToFlash : function(str) {
		if (this.piclensIsRunning_) {
			this.getFlash2().fl_sendTextToFlash(str);
		}
	},
	keyPressed : function(code) {
		// safari gets here... seems like it doesn't do ExternalInterface?
		// it does on Windows/Safari3, at least...
		if (!this.piclensIsRunning_) { return; }
		
		if (this.isSafari) { // does this work??
			this.getFlash().fl_keyPressed(code);
		} else {
			this.getFlash2().fl_keyPressed(code); // others need this one
		}
	},
	sendMouseMovementToFlash : function(delta) {
		if (!this.piclensIsRunning_) { return; }
		if (this.isSafari) { // WOW this works!
			this.getFlash().fl_mouseMoved(delta);
		} else {
			this.getFlash2().fl_mouseMoved(delta);
		}
	},
	scrollWheelMoved : function(event) {
		// event.wheelDelta
		// Safari/Windows (MouseWheel Up is +120; Down is -120)
		var delta = 0;
		if (!event) {
			event = window.event;
		}
		if (event.wheelDelta) { // IE/Opera
			delta = event.wheelDelta/120;
			if (window.opera) {
				delta = -delta;
			}
		} else if (event.detail) { // Firefox/Moz
			// on mac, don't divide by 3...
			if (Math.abs(event.detail) < 3) {
				delta = -event.detail;
			} else {
				delta = -event.detail/3;
			}
		}
		if (delta) {
			// don't send abs values < 1; otherwise, you can only scroll next
			this.sendMouseMovementToFlash(delta);		
		}
		if (event.preventDefault) {
			event.preventDefault();
		}
		event.returnValue = false;
	},
	getCurrentURL : function() {
		return location.href;
	},
	getHomePageName : function() {
		return this.homepageLabel_;
	},
	indexFeeds : function() {
		var linkTags = document.getElementsByTagName("link");
		this.feeds_ = [];
		for (var i = 0; i != linkTags.length; ++i) {
			var link = linkTags[i], type = link.getAttribute("type");
			if (type == "application/rss+xml" || type == "text/xml") {
				this.feeds_.push({
					title: link.getAttribute("title"),
					url: link.getAttribute("href")
				});
			}
		}
	},
	createXHR : function(url, callback) {
		var req;
		if (window.XMLHttpRequest) { // native XHR
	        req = new XMLHttpRequest();
	    }
		else if (window.ActiveXObject) { // IE/ActiveX
			try {
			    req = new ActiveXObject("Microsoft.XMLHTTP"); // IE 6 goes into this branch too
		    } catch(exc) {
		        req = new ActiveXObject("MSXML2.XMLHTTP.3.0");
		    }
	    }
	    
		if (req) {
	 		req.onreadystatechange = callback;

			if (BrowserDetect.browser == "Explorer" || 
				BrowserDetect.browser == "Opera" || 
				BrowserDetect.browser == "Safari") { // I know this is bad... but it works.
				var sep = (-1 < url.indexOf("?")) ? "&" : "?";
				var randurl = url + sep + "_pll=" + encodeURIComponent((new Date()).getTime()); // IE workaround to avoid caching...
		    	req.open("GET", randurl, true); // bAsync = true, can't test with IE7 on local filesystem (Access Denied)
				req.setRequestHeader("Cache-Control", "no-cache"); 
			} else {
		    	req.open("GET", url, true); // bAsync = true, can't test with IE7 on local filesystem (Access Denied)
			}

			req.send("");
		}
		return req;
	},
	onLoadStatusChanged : function() {		
		// extract feed data
		var xhr = this.xmlLoader_;
		if (!xhr) return;
		
		// check for success or failure
		if (xhr.readyState == 4) {
			// alert("State: " + xhr.readyState);
			var dom = xhr.responseXML;
			var text = xhr.responseText;
			
			if (xhr.status == 200 || xhr.status == 0) { // xhr.status == 0 implies the local file system
				// set the XML of the feed so we can access it from Flash
				this.feedXML_ = text;
			} else {
				// alert('PicLens Lite could not find the RSS feed.');
			}
			this.xmlLoader_ = null;
		} else {
			//alert("State: " + xhr.readyState);
			// opera only ever gets to state 3???
			// also doesn't seem to support external interface... we should embed it via flash vars then!
			//this.feedXML_ = xhr.responseText;
		}
		
	},
	showFlashUI : function() {
		this.piclensIsRunning_ = true;
		this.addKeyHandlers();

		if (!this.flash_bg_) {

			// configure background layer
			var bg = document.createElement('div'), self = this;

			// the window size
			var winSize = this.getWindowSize();

			bg.style.width = winSize.w;
			if (this.isIE6()) {
				bg.style.position = 'absolute';
				bg.style.height = document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px';
			} else {
				bg.style.position = 'fixed';
				bg.style.height = winSize.h;
			}
			
			bg.style.left = 0;
			bg.style.right = 0;
			bg.style.top = 0;
			bg.style.bottom = '0';
			bg.style.backgroundColor = '#000';

			bg.style.opacity = '0.5';
			bg.style.filter = 'alpha(opacity=50)'; // IE7

			bg.style.zIndex = 1000;
			bg.onclick = function() { self.closeFlashUI(); };
		
			// configure box appearance
			var fg = document.createElement('div');
			fg.style.backgroundColor = '#000';
			if (this.isIE6()) {
				fg.style.position = 'absolute';
				fg.style.width = (winSize.w - this.MARGIN_W_THIN_2) + 'px';
				fg.style.height = (winSize.h - this.MARGIN_H_THIN_2) + 'px';
			} else {
				fg.style.position = 'fixed';
			}

			if (!this.isSafari) {
				// use a smaller margin if the window size is <= 1280
				//if (winSize.w <= 1280) {
					fg.style.left = fg.style.right = this.MARGIN_W_THIN + 'px';
					fg.style.top = fg.style.bottom = this.MARGIN_H_THIN + 'px';
				//} else {
				//	fg.style.left = fg.style.right = this.MARGIN_W + 'px';
				//	fg.style.top = fg.style.bottom = this.MARGIN_H + 'px';
				//}
			}
			fg.style.border = '2px solid #555';
			fg.style.zIndex = 1001;
			fg.id = "flashdiv";
			
			// @deprecated: instead of using FlashVars, allow Flash to call JavaScript
			var myVars = "";

			// store references to inserted divs
			this.flash_bg_ = bg;
			this.flash_fg_ = fg;
						
			// insert into document
			var osx = BrowserDetect.OS == "Mac";
			var ffx = BrowserDetect.browser == "Firefox";
			if ((osx&&ffx)) {
				// nothing
			} else {
				document.body.appendChild(bg);
			}
			document.body.appendChild(fg);

			// inject player
			var w, h;
			if (this.isSafari) {
				w = '1';
				h = '1';
			} if (this.isIE6()) {
				w = winSize.w - this.MARGIN_W_THIN_2;
				h = winSize.h - this.MARGIN_H_THIN_2;
			} else {
				w = '100%';
				h = '100%';
			}
			
			var objParams = "";
			if (!this.isIE6()) {
				objParams = ' width="'+w+'" height="'+h+'" play="true" bgcolor="#000000" id="'+this.PL2+'" name="'+this.PL2+'" ';
			} else {
				objParams = ' width="0" height="0" play="true" visible="false" bgcolor="#000000" id="'+this.PL2+'" name="'+this.PL2+'" ';
			}
			
			if (SWFFix.hasFlashPlayerVersion("9.0.28")) {
				fg.innerHTML = 
				'<object id="PLLFlash" name="PLLFlash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+w+'" height="'+h+'">' + 
					'<param name="movie" value="' + this.getFlashURL() + '" />' + 
					'<param name="quality" value="high"/> ' +
					'<param name="bgcolor" value="#000000"/> ' +
					'<param name="allowScriptAccess" value="always"/> ' +
					'<param name="FlashVars" value="' + myVars + '"/> ' +
					'<param name="allowFullScreen" value="true"/> ' +
					'<param name="wmode" value="window"/> ' +
					'<param name="scale" value="noscale"/> ' +
					'<object type="application/x-shockwave-flash" data="' + this.getFlashURL() + '" quality="high" ' +
						objParams + 
						'loop="false" ' +
						'quality="high" ' +
						'FlashVars="' + myVars + '" ' +
						'allowFullScreen="true" scale="noscale" wmode="window" ' +
						'allowScriptAccess="always">' +
						'<div>' + 
							'<h1>This Slideshow Requires Adobe Flash</h1>' + 
							'<p><a href="'+this.GET_FL+'"><img src="'+this.FL_GIF+'" alt="Get Flash" /></a></p>' +
						'</div>' + 
					'</object>' + 
				'</object>';
			} else { // get Flash!
				var v = SWFFix.getFlashPlayerVersion();
				fg.innerHTML = '<div align="center" style="padding-top:60px; padding-bottom:10px; color:#999999;">' +
				'Your browser currently has Adobe Flash v' + v.major + '.' + v.minor + '.' + v.release + '<br /><br />' +
				'Either <span style="color:#66CCFF">PicLens</span> or Adobe Flash Player v. 9.0.28 or greater is required to view this slideshow.<br /><br />' +
				'<table border="0" align="center" cellpadding="5" cellspacing="0">' +
				  '<tr>' +
					'<td align="center" valign="middle"><a href="http://www.piclens.com/welcome/fullscreen-welcome.php"><img src="http://lite.piclens.com/images/GetPicLens.jpg" alt="Get PicLens" border="0" /></a><br /><br /><span style="font-size:12px; padding-top:4px">*Available for Firefox and Safari</span></td>' +
					'<td width="125" align="left" valign="middle"><span style="font-size:12px">Get PicLens, a free browser add-on for full-screen slideshows throughout the web. </span></td>' +
					'<td align="center" valign="middle"><span style="font-size:40px; font-weight:bold">or</span></td>' +
					'<td align="center" valign="middle"><span style="font-size:12px">Get Adobe Flash Player<br />' +
					  '</span>' +
					  '<table width="100%" border="0" cellspacing="0" cellpadding="2">' +
						'<tr>' +
						  '<td><a href="http://www.adobe.com/go/getflashplayer"><img src="http://lite.piclens.com/images/flash_icon.jpg" alt="Flash Logo" border="0" /></a></td>' +
						  '<td><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" width="112" height="33" border="0" /></a></td>' +
						'</tr>' +
					  '</table>' +
					'</td>' +
				  '</tr>' +
				'</table>' +
				'</div>';
				if (this.isIE || this.isFirefox) {
					loadXML();
				} else {
					fg.innerHTML = fg.innerHTML +
					'<br /><br /><br /><div align="center" style="color:#666666; font-size:9px">&copy; 2007 Cooliris, Inc. All trademarks are property of their respective holders.</div>';
				}
			}

			
			// resize widget to fit window
			if (this.isSafari) {
				this.resizeUI();
			}

			// make visible
			this.flash_bg_.style.display = 'block';
			this.flash_fg_.style.display = 'block';
		} else {
			document.body.appendChild(this.flash_bg_);
			document.body.appendChild(this.flash_fg_);
			this.flash_bg_.style.display = 'block';
			this.flash_fg_.style.display = 'block';
		}
		if (!this.resizeWatched && this.isSafari) {
			var self = this;
			window.addEventListener('resize', function() { self.resizeUI(); }, false);
			this.resizeWatched = true;
		}
	},
	closeFlashUI : function() {
		this.piclensIsRunning_ = false;
		var self = this;
		
		// remove the handlers...
		document.onkeydown = "";
		window.onmousewheel = document.onmousewheel = "";
		if (window.removeEventListener) {
			window.removeEventListener("DOMMouseScroll", this.forwardMouseScroll_, false);
		}
		this.flash_bg_.style.display = 'none';
		this.flash_fg_.style.display = 'none';
		document.body.removeChild(this.flash_bg_);
		document.body.removeChild(this.flash_fg_);
	},
	getWindowSize : function() { // inner size
		var w = 0, h = 0;
		if (typeof(window.innerWidth) == 'number') {
			// not IE
			w = window.innerWidth;
			h = window.innerHeight;
		} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			// IE 6+ in 'standards compliant mode'
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
			// IE 4 compatible
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
		return {w:w, h:h}
	},
	resizeUI : function() { // resize event handler
		// compute layout; use a thinner margin if the window size is <= 1280
		var winSize = this.getWindowSize();
		var w = 780;
		var h = 580;
		if (winSize.w <= 1280) {
			w = Math.ceil(winSize.w - 2*this.MARGIN_W_THIN);
			h = Math.ceil(winSize.h - 2*this.MARGIN_H_THIN);
		} else { // big window
			w = Math.ceil(Math.max(winSize.w * 0.8, winSize.w - this.MARGIN_W));
			h = Math.ceil(Math.max(winSize.h * 0.8, winSize.h - this.MARGIN_H));
		}
		var x = Math.ceil((winSize.w - w) / 2.0);
		var y = Math.ceil((winSize.h - h) / 2.0);

		
		// apply layout
		var fg = this.flash_fg_;
		var flashObj = this.getFlash();
		fg.style.left = x + 'px';
		fg.style.top = y + 'px';
		fg.style.width = w + 'px';
		fg.style.height = h + 'px';
		flashObj.style.width = w + 'px';
		flashObj.style.height = h + 'px';
		flashObj.width = w;
		flashObj.height = h;
	},
	getFeedFromJS : function() { // Flash polls this to get the feed...
		return this.feedXML_;
	},
	getFlashURL : function() {
		var fs = typeof DEBUG_PICLENS_FS != "undefined";
		if (typeof DEBUG_PICLENS_WEB == "undefined" && !fs) { // production
			return this.FL_URL;
		} else if (!fs) { // debug
			return this.FL_URL_DEBUG_WEB;
		} else {
			return this.FL_URL_DEBUG_FS;
		}
	},
	focusOnFlash : function () { // place focus on the Flash item; only works in some browsers
		this.getFlash2().focus();
	},
	getFlash : function() {
		return document.getElementById("PLLFlash");
	},
	// works for Javascript/Flash Bridge
	// also works for OSX Firefox's Focus
	getFlash2 : function() { 
		return document.getElementById(this.PL2);
	},
	hasPLClient : function() {
		if (window.piclens) {
			return true;
		} else {
			return false;
		}
	}
}
