﻿/**
* The Shadowbox Flash video player class.
*
* This file is part of Shadowbox.
*
* Shadowbox is an online media viewer application that supports all of the
* web's most popular media publishing formats. Shadowbox is written entirely
* in JavaScript and CSS and is highly customizable. Using Shadowbox, website
* authors can showcase a wide assortment of media in all major browsers without
* navigating users away from the linking page.
*
* You should have received a license with this distribution explaining the terms
* under which Shadowbox may be used. If you did not, you may obtain a copy of the
* license at http://shadowbox-js.com/LICENSE
*
* @author      Michael J. I. Jackson <michael@mjijackson.com>
* @copyright   2007-2009 Michael J. I. Jackson
* @version     SVN: $Id: shadowbox-flv.js 20M 2009-04-23 13:08:21Z (local) $
*/

(function(S) {

	var U = S.util,
        controller_height = 20; // height of JW FLV player controller

	/**
	* Constructor. This class is used to display Flash videos with the JW
	* FLV player.
	*
	* @param   Object      obj     The content object
	* @public
	*/
	S.flv = function(obj) {
		this.obj = obj;

		// FLV's are resizable
		this.resizable = true;

		// height/width default to 300 pixels
		this.height = obj.height ? parseInt(obj.height, 10) : 300;
		if (S.options.showMovieControls == true)
			this.height += controller_height;
		this.width = obj.width ? parseInt(obj.width, 10) : 300;
	}

	S.flv.prototype = {

		/**
		* Appends this movie to the document.
		*
		* @param   HTMLElement     body    The body element
		* @param   String          id      The content id
		* @param   Object          dims    The current Shadowbox dimensions
		* @return  void
		* @public
		*/
		append: function(body, id, dims) {
			this.id = id;

			// append temporary content element to replace
			var tmp = document.createElement('div');
			tmp.id = id;
			body.appendChild(tmp);

			var h = dims.resize_h, // use resized dimensions
                w = dims.resize_w,
                swf = S.path + 'libraries/mediaplayer/player.swf',
                version = S.options.flashVersion,
                express = S.path + 'libraries/swfobject/expressInstall.swf',
                flashvars = U.apply({
                	file: this.obj.content,
                	height: h,
                	width: w,
                	autostart: (S.options.autoplayMovies ? 'true' : 'false'),
                	controlbar: (S.options.showMovieControls ? 'bottom' : 'none'),
                	backcolor: '0x000000',
                	frontcolor: '0xCCCCCC',
                	lightcolor: '0x557722'
                }, S.options.flashVars),
                params = S.options.flashParams;

			swfobject.embedSWF(swf, id, w, h, version, express, flashvars, params);
		},

		/**
		* Removes this movie from the document.
		*
		* @return  void
		* @public
		*/
		remove: function() {
			// call express install callback here in case express install is
			// active and user has not selected anything
			swfobject.expressInstallCallback();
			swfobject.removeSWF(this.id);
		}

	};

})(Shadowbox);







/**
* The Shadowbox HTML player class.
*
* This file is part of Shadowbox.
*
* Shadowbox is an online media viewer application that supports all of the
* web's most popular media publishing formats. Shadowbox is written entirely
* in JavaScript and CSS and is highly customizable. Using Shadowbox, website
* authors can showcase a wide assortment of media in all major browsers without
* navigating users away from the linking page.
*
* You should have received a license with this distribution explaining the terms
* under which Shadowbox may be used. If you did not, you may obtain a copy of the
* license at http://shadowbox-js.com/LICENSE
*
* @author      Michael J. I. Jackson <michael@mjijackson.com>
* @copyright   2007-2009 Michael J. I. Jackson
* @version     SVN: $Id: shadowbox-html.js 20M 2009-04-23 13:08:21Z (local) $
*/

(function(S) {

	/**
	* Constructor. This class is used to display inline HTML.
	*
	* @param   Object      obj     The content object
	* @public
	*/
	S.html = function(obj) {
		this.obj = obj;

		// height defaults to 300, width defaults to 500
		this.height = obj.height ? parseInt(obj.height, 10) : 300;
		this.width = obj.width ? parseInt(obj.width, 10) : 500;
	}

	S.html.prototype = {

		/**
		* Appends this object to the document.
		*
		* @param   HTMLElement     body    The body element
		* @param   String          id      The content id
		* @param   Object          dims    The current Shadowbox dimensions
		* @return  void
		* @public
		*/
		append: function(body, id, dims) {
			this.id = id;

			var div = document.createElement('div');
			div.id = id;
			div.className = 'html'; // give special class to enable scrolling
			div.innerHTML = this.obj.content;

			body.appendChild(div);
		},

		/**
		* Removes this object from the document.
		*
		* @return  void
		* @public
		*/
		remove: function() {
			var el = document.getElementById(this.id);
			if (el) S.lib.remove(el);
		}

	};

})(Shadowbox);








/**
* The Shadowbox iframe player class.
*
* This file is part of Shadowbox.
*
* Shadowbox is an online media viewer application that supports all of the
* web's most popular media publishing formats. Shadowbox is written entirely
* in JavaScript and CSS and is highly customizable. Using Shadowbox, website
* authors can showcase a wide assortment of media in all major browsers without
* navigating users away from the linking page.
*
* You should have received a license with this distribution explaining the terms
* under which Shadowbox may be used. If you did not, you may obtain a copy of the
* license at http://shadowbox-js.com/LICENSE
*
* @author      Michael J. I. Jackson <michael@mjijackson.com>
* @copyright   2007-2009 Michael J. I. Jackson
* @version     SVN: $Id: shadowbox-iframe.js 20M 2009-04-23 13:08:21Z (local) $
*/

(function(S) {

	/**
	* Constructor. This class is used to display web pages in an HTML iframe.
	*
	* @param   Object      obj     The content object
	* @public
	*/
	S.iframe = function(obj) {
		this.obj = obj;

		// height/width default to full viewport height/width
		var so = document.getElementById('sb-overlay');
		this.height = obj.height ? parseInt(obj.height, 10) : so.offsetHeight;
		this.width = obj.width ? parseInt(obj.width, 10) : so.offsetWidth;
	}

	S.iframe.prototype = {

		/**
		* Appends this iframe to the document.
		*
		* @param   HTMLElement     body    The body element
		* @param   String          id      The content id
		* @param   Object          dims    The current Shadowbox dimensions
		* @return  void
		* @public
		*/
		append: function(body, id, dims) {
			this.id = id;

			var html = '<iframe id="' + id + '" name="' + id + '" height="100%" ' +
                'width="100%" frameborder="0" marginwidth="0" marginheight="0" ' +
                'scrolling="auto"';

			if (S.client.isIE) {
				// prevent brief whiteout while loading iframe source
				html += ' allowtransparency="true"';

				// prevent "secure content" warning for https on IE6
				// see http://www.zachleat.com/web/2007/04/24/adventures-in-i-frame-shims-or-how-i-learned-to-love-the-bomb/
				if (S.client.isIE6)
					html += ' src="javascript:false;document.write(\'\');"';
			}

			html += '></iframe>';

			// use innerHTML method of insertion here instead of appendChild
			// because IE renders frameborder otherwise
			body.innerHTML = html;

			/*
			var iframe = document.createElement('iframe'),
			attr = {
			id:             id,
			name:           id,
			height:         '100%',
			width:          '100%',
			frameborder:    '0',
			marginwidth:    '0',
			marginheight:   '0',
			scrolling:      'auto'
			};

            if(S.client.isIE){
			// prevent brief whiteout while loading iframe source
			attr.allowtransparency = 'true';

                if(S.client.isIE6){
			// prevent "secure content" warning for https on IE6
			// see http://www.zachleat.com/web/2007/04/24/adventures-in-i-frame-shims-or-how-i-learned-to-love-the-bomb/
			attr.src = 'javascript:false;document.write("");';
			}
			}

            for(var a in attr){
			iframe.setAttribute(a, attr[a]);
			}

            body.appendChild(iframe);
			*/
		},

		/**
		* Removes this iframe from the document.
		*
		* @return  void
		* @public
		*/
		remove: function() {
			var el = document.getElementById(this.id);
			if (el) {
				S.lib.remove(el);
				if (S.client.isGecko)
					delete window.frames[this.id]; // needed for Firefox
			}
		},

		/**
		* An optional callback function to process after this content has been
		* loaded.
		*
		* @return  void
		* @public
		*/
		onLoad: function() {
			var win = S.client.isIE
                ? document.getElementById(this.id).contentWindow
                : window.frames[this.id];
			win.location.href = this.obj.content; // set the iframe's location
		}

	};

})(Shadowbox);




/**
* The Shadowbox image player class.
*
* This file is part of Shadowbox.
*
* Shadowbox is an online media viewer application that supports all of the
* web's most popular media publishing formats. Shadowbox is written entirely
* in JavaScript and CSS and is highly customizable. Using Shadowbox, website
* authors can showcase a wide assortment of media in all major browsers without
* navigating users away from the linking page.
*
* You should have received a license with this distribution explaining the terms
* under which Shadowbox may be used. If you did not, you may obtain a copy of the
* license at http://shadowbox-js.com/LICENSE
*
* @author      Michael J. I. Jackson <michael@mjijackson.com>
* @copyright   2007-2009 Michael J. I. Jackson
* @version     SVN: $Id: shadowbox-img.js 20M 2009-04-23 13:08:21Z (local) $
*/

(function(S) {

	var U = S.util,

	/**
	* Keeps track of 4 floating values (x, y, start_x, & start_y) that are used
	* in the drag calculations.
	*
	* @var     Object
	* @private
	*/
    drag,

	/**
	* Holds the draggable element so we don't have to fetch it every time
	* the mouse moves.
	*
	* @var     HTMLElement
	* @private
	*/
    draggable,

	/**
	* The id to use for the drag layer.
	*
	* @var     String
	* @private
	*/
    drag_id = 'sb-drag-layer',

	/**
	* Resource used to preload images. It's class-level so that when a new
	* image is requested, the same resource can be reassigned, cancelling
	* the original's callback.
	*
	* @var     HTMLElement
	* @private
	*/
    pre;

	/**
	* Resets the class drag variable.
	*
	* @return  void
	* @private
	*/
	function resetDrag() {
		drag = {
			x: 0,
			y: 0,
			start_x: null,
			start_y: null
		};
	}

	/**
	* Toggles the drag function on and off.
	*
	* @param   Boolean     on      True to toggle on, false to toggle off
	* @param   Number      h       The height of the drag layer
	* @param   Number      w       The width of the drag layer
	* @return  void
	* @private
	*/
	function toggleDrag(on, h, w) {
		if (on) {
			resetDrag();
			// add transparent drag layer to prevent browser dragging of actual image
			var s = [
                'position:absolute',
                'height:' + h + 'px',
                'width:' + w + 'px',
                'cursor:' + (S.client.isGecko ? '-moz-grab' : 'move'),
                'background-color:' + (S.client.isIE ? '#fff;filter:alpha(opacity=0)' : 'transparent')
            ].join(';');
			S.lib.append(S.skin.bodyEl(), '<div id="' + drag_id + '" style="' + s + '"></div>');
			S.lib.addEvent(U.get(drag_id), 'mousedown', listenDrag);
		} else {
			var d = U.get(drag_id);
			if (d) {
				S.lib.removeEvent(d, 'mousedown', listenDrag);
				S.lib.remove(d);
			}
			draggable = null;
		}
	}

	/**
	* Sets up a drag listener on the document. Called when the mouse button is
	* pressed (mousedown).
	*
	* @param   mixed       e       The mousedown event
	* @return  void
	* @private
	*/
	function listenDrag(e) {
		// prevent browser dragging
		S.lib.preventDefault(e);

		var coords = S.lib.getPageXY(e);
		drag.start_x = coords[0];
		drag.start_y = coords[1];

		draggable = U.get(S.contentId());
		S.lib.addEvent(document, 'mousemove', positionDrag);
		S.lib.addEvent(document, 'mouseup', unlistenDrag);

		if (S.client.isGecko)
			U.get(drag_id).style.cursor = '-moz-grabbing';
	}

	/**
	* Removes the drag listener. Called when the mouse button is released
	* (mouseup).
	*
	* @return  void
	* @private
	*/
	function unlistenDrag() {
		S.lib.removeEvent(document, 'mousemove', positionDrag);
		S.lib.removeEvent(document, 'mouseup', unlistenDrag); // clean up

		if (S.client.isGecko)
			U.get(drag_id).style.cursor = '-moz-grab';
	}

	/**
	* Positions an oversized image on drag.
	*
	* @param   mixed       e       The drag event
	* @return  void
	* @private
	*/
	function positionDrag(e) {
		var c = S.content,
            d = S.dimensions,
            coords = S.lib.getPageXY(e);

		var move_x = coords[0] - drag.start_x;
		drag.start_x += move_x;
		// x boundaries
		drag.x = Math.max(Math.min(0, drag.x + move_x), d.inner_w - c.width);
		draggable.style.left = drag.x + 'px';

		var move_y = coords[1] - drag.start_y;
		drag.start_y += move_y;
		// y boundaries
		drag.y = Math.max(Math.min(0, drag.y + move_y), d.inner_h - c.height);
		draggable.style.top = drag.y + 'px';
	}

	/**
	* Constructor.
	*
	* @param   Object      obj     The content object
	* @public
	*/
	S.img = function(obj) {
		this.obj = obj;

		// images are resizable
		this.resizable = true;

		// preload the image
		this.ready = false;
		var self = this;
		pre = new Image();
		pre.onload = function() {
			// height/width defaults to image height/width
			self.height = obj.height ? parseInt(obj.height, 10) : pre.height;
			self.width = obj.width ? parseInt(obj.width, 10) : pre.width;

			// ready to go
			self.ready = true;

			// clean up to prevent memory leak in IE
			pre.onload = '';
			pre = null;
		}
		pre.src = obj.content;
	}

	S.img.prototype = {

		/**
		* Appends this image to the document.
		*
		* @param   HTMLElement     body    The body element
		* @param   String          id      The content id
		* @param   Object          d       The current Shadowbox dimensions
		* @return  void
		* @public
		*/
		append: function(body, id, d) {
			this.id = id;

			var img = document.createElement('img');
			img.id = id;
			img.src = this.obj.content;
			img.style.position = 'absolute';

			// need to use setAttribute here for IE's sake
			img.setAttribute('height', d.resize_h)
			img.setAttribute('width', d.resize_w)

			body.appendChild(img);
		},

		/**
		* Removes this image from the document.
		*
		* @return  void
		* @public
		*/
		remove: function() {
			var el = U.get(this.id);
			if (el) S.lib.remove(el);

			// disable drag layer
			toggleDrag(false);

			// prevent old image requests from loading
			if (pre) {
				pre.onload = '';
				pre = null;
			}
		},

		/**
		* An optional callback function to process after this content has been
		* loaded.
		*
		* @return  void
		* @public
		*/
		onLoad: function() {
			var d = S.dimensions;

			// listen for drag, in the case of oversized images, the "resized"
			// height/width will actually be the original image height/width
			if (d.oversized && S.options.handleOversize == 'drag')
				toggleDrag(true, d.resize_h, d.resize_w);
		},

		/**
		* Called when the window is resized.
		*
		* @return  void
		* @public
		*/
		onWindowResize: function() {
			// fix draggable positioning if enlarging viewport
			if (draggable) {
				var c = S.content,
                    d = S.dimensions,
                    t = parseInt(S.lib.getStyle(draggable, 'top')),
                    l = parseInt(S.lib.getStyle(draggable, 'left'));

				if (t + c.height < d.inner_h)
					draggable.style.top = d.inner_h - c.height + 'px';
				if (l + c.width < d.inner_w)
					draggable.style.left = d.inner_w - c.width + 'px';
			}
		}

	};

})(Shadowbox);





/**
* The Shadowbox QuickTime player class.
*
* This file is part of Shadowbox.
*
* Shadowbox is an online media viewer application that supports all of the
* web's most popular media publishing formats. Shadowbox is written entirely
* in JavaScript and CSS and is highly customizable. Using Shadowbox, website
* authors can showcase a wide assortment of media in all major browsers without
* navigating users away from the linking page.
*
* You should have received a license with this distribution explaining the terms
* under which Shadowbox may be used. If you did not, you may obtain a copy of the
* license at http://shadowbox-js.com/LICENSE
*
* @author      Michael J. I. Jackson <michael@mjijackson.com>
* @copyright   2007-2009 Michael J. I. Jackson
* @version     SVN: $Id: shadowbox-qt.js 20M 2009-04-23 13:08:21Z (local) $
*/

(function(S) {

	var controller_height = 16; // height of QuickTime controller

	/**
	* Constructor. This class is used to display QuickTime movies.
	*
	* @param   Object      obj     The content object
	* @public
	*/
	S.qt = function(obj) {
		this.obj = obj;

		// height/width default to 300 pixels
		this.height = obj.height ? parseInt(obj.height, 10) : 300;
		if (S.options.showMovieControls == true)
			this.height += controller_height;
		this.width = obj.width ? parseInt(obj.width, 10) : 300;
	}

	S.qt.prototype = {

		/**
		* Appends this movie to the document.
		*
		* @param   HTMLElement     body    The body element
		* @param   String          id      The content id
		* @param   Object          dims    The current Shadowbox dimensions
		* @return  void
		* @public
		*/
		append: function(body, id, d) {
			this.id = id;

			var opt = S.options,
            autoplay = String(opt.autoplayMovies),
            controls = String(opt.showMovieControls);

			var html = '<object',
            movie = {
            	id: id,
            	name: id,
            	height: this.height, // height includes controller
            	width: this.width,
            	kioskmode: 'true'
            };

			if (S.client.isIE) {
				movie.classid = 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B';
				movie.codebase = 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0';
			} else {
				movie.type = 'video/quicktime';
				movie.data = this.obj.content;
			}

			for (var m in movie)
				html += ' ' + m + '="' + movie[m] + '"';
			html += '>';

			var params = {
				src: this.obj.content,
				scale: 'aspect',
				controller: controls,
				autoplay: autoplay
			};

			for (var p in params)
				html += '<param name="' + p + '" value="' + params[p] + '">';
			html += '</object>';

			body.innerHTML = html;
		},

		/**
		* Removes this movie from the document.
		*
		* @return  void
		* @public
		*/
		remove: function() {
			var id = this.id;

			try {
				document[id].Stop(); // stop QT video stream
			} catch (e) { }

			var el = document.getElementById(id);
			if (el) S.lib.remove(el);
		}

	};

})(Shadowbox);




/**
* The Shadowbox SWF movie player class.
*
* This file is part of Shadowbox.
*
* Shadowbox is an online media viewer application that supports all of the
* web's most popular media publishing formats. Shadowbox is written entirely
* in JavaScript and CSS and is highly customizable. Using Shadowbox, website
* authors can showcase a wide assortment of media in all major browsers without
* navigating users away from the linking page.
*
* You should have received a license with this distribution explaining the terms
* under which Shadowbox may be used. If you did not, you may obtain a copy of the
* license at http://shadowbox-js.com/LICENSE
*
* @author      Michael J. I. Jackson <michael@mjijackson.com>
* @copyright   2007-2009 Michael J. I. Jackson
* @version     SVN: $Id: shadowbox-swf.js 20M 2009-04-23 13:08:21Z (local) $
*/

(function(S) {

	var U = S.util;

	/**
	* Constructor. This class is used to display SWF movies.
	*
	* @param   Object      obj     The content object
	* @public
	*/
	S.swf = function(obj) {
		this.obj = obj;

		// SWF's are resizable
		this.resizable = true;

		// height/width default to 300 pixels
		this.height = obj.height ? parseInt(obj.height, 10) : 300;
		this.width = obj.width ? parseInt(obj.width, 10) : 300;
	}

	S.swf.prototype = {

		/**
		* Appends this swf to the document.
		*
		* @param   HTMLElement     body    The body element
		* @param   String          id      The content id
		* @param   Object          dims    The current Shadowbox dimensions
		* @return  void
		* @public
		*/
		append: function(body, id, dims) {
			this.id = id;

			// append temporary content element to replace
			var tmp = document.createElement('div');
			tmp.id = id;
			body.appendChild(tmp);

			var h = dims.resize_h, // use resized dimensions
                w = dims.resize_w,
                swf = this.obj.content,
                version = S.options.flashVersion,
                express = S.path + 'libraries/swfobject/expressInstall.swf',
                flashvars = S.options.flashVars,
                params = S.options.flashParams;

			swfobject.embedSWF(swf, id, w, h, version, express, flashvars, params);
		},

		/**
		* Removes this swf from the document.
		*
		* @return  void
		* @public
		*/
		remove: function() {
			// call express install callback here in case express install is
			// active and user has not selected anything
			swfobject.expressInstallCallback();
			swfobject.removeSWF(this.id);
		}

	};

})(Shadowbox);





/**
* The Shadowbox Windows Media player class.
*
* This file is part of Shadowbox.
*
* Shadowbox is an online media viewer application that supports all of the
* web's most popular media publishing formats. Shadowbox is written entirely
* in JavaScript and CSS and is highly customizable. Using Shadowbox, website
* authors can showcase a wide assortment of media in all major browsers without
* navigating users away from the linking page.
*
* You should have received a license with this distribution explaining the terms
* under which Shadowbox may be used. If you did not, you may obtain a copy of the
* license at http://shadowbox-js.com/LICENSE
*
* @author      Michael J. I. Jackson <michael@mjijackson.com>
* @copyright   2007-2009 Michael J. I. Jackson
* @version     SVN: $Id: shadowbox-wmp.js 20M 2009-04-23 13:08:21Z (local) $
*/

(function(S) {

	var controller_height = (S.client.isIE ? 70 : 45); // height of WMP controller

	/**
	* Constructor. This class is used to display Windows Media Player movies.
	*
	* @param   Object      obj     The content object
	* @public
	*/
	S.wmp = function(obj) {
		this.obj = obj;

		// height/width default to 300 pixels
		this.height = obj.height ? parseInt(obj.height, 10) : 300;
		if (S.options.showMovieControls)
			this.height += controller_height;
		this.width = obj.width ? parseInt(obj.width, 10) : 300;
	}

	S.wmp.prototype = {

		/**
		* Appends this movie to the document.
		*
		* @param   HTMLElement     body    The body element
		* @param   String          id      The content id
		* @param   Object          dims    The current Shadowbox dimensions
		* @return  void
		* @public
		*/
		append: function(body, id, dims) {
			this.id = id;

			var opt = S.options,
                autoplay = opt.autoplayMovies ? 1 : 0;

			var movie = '<object id="' + id +
                '" name="' + id +
                '" height="' + this.height +
                '" width="' + this.width + '"',
                params = { autostart: opt.autoplayMovies ? 1 : 0 };

			if (S.client.isIE) {
				// movie += ' type="application/x-oleobject"';
				movie += ' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"';
				params.url = this.obj.content;
				params.uimode = opt.showMovieControls ? 'full' : 'none';
			} else {
				movie += ' type="video/x-ms-wmv"';
				movie += ' data="' + this.obj.content + '"'
				params.showcontrols = opt.showMovieControls ? 1 : 0;
			}

			movie += '>';

			for (var p in params)
				movie += '<param name="' + p + '" value="' + params[p] + '">';

			movie += '</object>'

			body.innerHTML = movie;
		},

		/**
		* Removes this movie from the document.
		*
		* @return  void
		* @public
		*/
		remove: function() {
			var id = this.id;

			if (S.client.isIE) {
				try {
					window[id].controls.stop(); // stop the movie
					window[id].URL = 'non-existent.wmv'; // force player refresh
					window[id] = function() { }; // remove from window object
				} catch (e) { }
			}

			var el = document.getElementById(id);
			if (el) {
				setTimeout(function() { // using setTimeout prevents browser crashes with WMP
					S.lib.remove(el);
				}, 10);
			}
		}

	};

})(Shadowbox);

