/*
	SlideShowPro/LyteBox
	W. Hardy Interactive, Inc.
*/

var SSPLytebox = {
	_isIE: function() {
		return (navigator.appName.indexOf('Microsoft') != -1);
	},
	
	_getFlash: function(id) {
		if(document[id]) { return document[id]; }
		else if(window[id]) { return window[id]; }
		else return null;
	},
	
	_isFlashOK: function(f) {
		return (f && f.PercentLoaded() == 100);
	},
	
	_playOnClose: function(id) {
		var lb = window.myLytebox;
		if(lb && !lb._end) {
			lb._end = lb.end;
			lb.end = function(c) {
				lb._end(c);
				lb.end = lb._end;
				lb._end = null;
				SSPLytebox.play(id);
			};
		}
	},
	
	pause: function(id) {
		var f = SSPLytebox._getFlash(id);
		if(SSPLytebox._isFlashOK(f)) {
			try { f.toggleDisplayMode('Manual'); } catch(e) {}
		}
	},
	
	play: function(id) {
		var f = SSPLytebox._getFlash(id);
		if(SSPLytebox._isFlashOK(f)) {
			try { f.toggleDisplayMode('Auto'); } catch(e) {}
		}
	},
	
	popupLink: function(id, anchorid, playonclose) {
		if(window.myLytebox) {
			// IE fix
			if(SSPLytebox._isIE()) {
				myLytebox.hideFlash = false;
			}
			
			if(playonclose) {
				SSPLytebox._playOnClose(id);
			}
			
			var a = document.getElementById(anchorid);
			if(a) {
				SSPLytebox.pause(id);
				myLytebox.start(a);
			}
		}
	},
	
	popupURL: function(id, url, caption, playonclose) {
		if(window.myLytebox) {
			// IE fix
			if(SSPLytebox._isIE()) {
				myLytebox.hideFlash = false;
			}
			
			if(playonclose) {
				SSPLytebox._playOnClose(id);
			}
			
			var a = document.createElement('a');
			a.setAttribute('rel', 'lytebox');
			a.setAttribute('href', url);
			a.setAttribute('title', caption);
			SSPLytebox.pause(id);
			myLytebox.start(a);
		}
	}
};

