/**
 * [javascript/]jsl.js
 * ==========================================================================================================
 * The Webcellence jsl jQuey plugin.
 *
 * ----------
 * CHANGE LOG
 * ----------
 * Date      By     Ver     Description
 * --------- ------ ------- -----------
 * 12/11/10  TAB    1.0.0   Initial Development
 *
 * @package javascript
 * @subpackage jsl
 * @author Todd Brandys
 * @copyright Copyright (c) 2010, Webcellence, Inc.
 * @since 1.0.0
 * @version 2.0.0
 */

(function ( $ ) {

	// ######################################################################################################
	// # PRIVATE METHODS
	// ######################################################################################################

	// FUNCTION prvInitialize( )
	// ======================================================================================================
	/**
	 * Search for the child elements that have jsl attributes, and call the invokation method on each one.
	 *
	 * @since 2.0.0
	 */
	function prvInitialize( ) {

		if ($(this).attr("jsl")) {

			prvInvoke.apply(this, [ ]);

		}
		$("*[jsl]", this).each(prvInvoke);

	}

	// FUNCTION prvInvoke( )
	// ======================================================================================================
	/**
	 * Invoke the initialization routine for the element.
	 *
	 * @since 2.0.0
	 */
	function prvInvoke( ) {

		var jsl = $(this).attr("jsl").replace(/^\s*(jsl\.)?(.+)\s*$/, "$2");
		var MATCHES = jsl.match(/^([^\(]+)(\((.*)\))?$/);
		return eval("$.fn.jsl." + MATCHES[1]).apply(this, eval("[ " + (undefined === MATCHES[3] ? '' : MATCHES[3]) + " ]"));

	}

	// ######################################################################################################
	// # PUBLIC METHODS
	// ######################################################################################################

	// FUNCTION pubInitialize( )
	// ======================================================================================================
	/**
	 * Find all the "jsl" attributes within the children of the jQuery object and run the initialization
	 * routines for them.
	 *
	 * @since 2.0.0
	 */
	function pubInitialize( ) {

		return this.each(prvInitialize);

	}

	// ######################################################################################################
	// # LINKAGE
	// ######################################################################################################
	var publicMethods = {
		"initialize"	:	pubInitialize
	};

	$.fn.jsl = function ( ) {

		switch (true) {

			// Called on DOM or jQuery objects.  Run the initialization function.
			//
			case 0 === arguments.length || "object" === typeof arguments[0]:
				pubInitialize.apply(this, arguments);
				break;

			case "string" === typeof arguments[0] && publicMethods[arguments[0]]:
				publicMethods[arguments[0]].apply(this, arguments.slice(1));
				break;

			default:
				$.error("Method " + arguments[0] + " is not defined for jQuery.jsl");

		}

	}

})(jQuery);

// The following statement sets up the automatic initialization by way of the jQuery ready event.
//
$(document).ready(
	function ( ) {

		$(document.body).jsl();
		$(document).bind(
			"contextmenu",
			function ( e ) {

				alert(
					"The text and images contained in the Sol Potion website are copyrighted materials.\n" +
					"The context menu has been disabled to prevent this information from being copied.\n\n" +
					"Thank you for observing copyright law."
				);
				return false;

			}

		);

	}
);

/**
 * [javascript/]feature.js
 * ==========================================================================================================
 * The Webcellence feature jQuey plugin.
 *
 * ----------
 * CHANGE LOG
 * ----------
 * Date      By     Ver     Description
 * --------- ------ ------- -----------
 * 12/12/10  TAB    1.0.0   Initial Development
 *
 * @package javascript
 * @subpackage film
 * @author Todd Brandys
 * @copyright Copyright (c) 2010, Webcellence, Inc.
 * @since 1.0.0
 * @version 3.0.0
 */

(function ( $ ) {

	var defaults = {
		"direction"		:	"Left",
		"frameTimeout"	:	5000,
		"timeoutId"		:	undefined
	}

	// ######################################################################################################
	// # PRIVATE METHODS
	// ######################################################################################################

	function prvFrameClearTimeout( options ) {

		window.clearTimeout(options.timeoutId);
		options.timeoutId = undefined;

	}

	function prvFrameRotateLeft( self, options ) {

		if (undefined !== options.timeoutId) {

			prvFrameClearTimeout(options);

		}
		var roll = $("#sp-page-filmRoll");
		var scroll = 0;

		var intervalId = window.setInterval(
			function ( ) {

				if (scroll > 7) {

					window.clearInterval(intervalId);
					roll.append($("a:eq(0)", roll).detach());
					self.scrollLeft(0);

				} else {

					self.scrollLeft(++scroll * 14);

				}

			},
			50
		);

	}

	function prvFrameRotateRight( self, options ) {

		if (undefined !== options.timeoutId) {

			prvFrameClearTimeout(options);

		}
		var roll = $("#sp-page-filmRoll");
		var scroll = 8;
		roll.prepend($("a:last", roll).detach());
		self.scrollLeft(scroll * 14);

		var intervalId = window.setInterval(
			function ( ) {

				if (scroll < 0) {

					window.clearInterval(intervalId);

				} else {

					self.scrollLeft(--scroll * 14);

				}

			},
			50
		);

	}

	function prvFrameSetTimeout( self, options ) {

		options.timeoutId = window.setTimeout(
			function ( ) {

				prvFrameTimeout(self, options);

			},
			options.frameTimeout
		);

	}

	function prvFrameTimeout( self, options ) {

		options.timeoutId = undefined;
		if ("right" !== options.direction.toLowerCase) {

			prvFrameRotateLeft(self, options);

		} else {

			prvFrameRotateRight(self, options);

		}
		prvFrameSetTimeout(self, options);

	}

	// ######################################################################################################
	// # PUBLIC METHODS
	// ######################################################################################################

	// FUNCTION pubInitialize( )
	// ======================================================================================================
	/**
	 * Find all the <img> elements that are for selecting the different panes of content.  Then add an
	 * event handler for the click event.
	 *
	 * @since 3.0.0
	 */
	function pubInitialize( ) {

		var options = { };
		var self = $(this);
		$.extend(options, defaults);
		if (arguments.length) {

			$.extend(options, arguments[0]);

		}
		prvFrameSetTimeout(self, options);
		$("#sp-page-filmLeft").click(
			function ( e ) {

				prvFrameRotateLeft(self, options);
				prvFrameSetTimeout(self, options);

			}
		);
		$("#sp-page-filmRight").click(
			function ( e ) {

				prvFrameRotateRight(self, options);
				prvFrameSetTimeout(self, options);

			}
		);

	}

	// ######################################################################################################
	// # LINKAGE
	// ######################################################################################################
	var publicMethods = {
		"initialize"	:	pubInitialize
	};

	$.fn.jsl.film = function ( ) {

		switch (true) {

			// Called on DOM or jQuery objects.  Run the initialization function.
			//
			case 0 === arguments.length || "object" === typeof arguments[0]:
				pubInitialize.apply(this, arguments);
				break;

			case "string" === typeof arguments[0] && publicMethods[arguments[0]]:
				publicMethods[arguments[0]].apply(this, arguments.slice(1));
				break;

			default:
				$.error("Method " + arguments[0] + " is not defined for jQuery.jsl");

		}

	}

})(jQuery);

/**
 * [javascript/]option.js
 * ==========================================================================================================
 * The Webcellence product option jQuey plugin.
 *
 * ----------
 * CHANGE LOG
 * ----------
 * Date      By     Ver     Description
 * --------- ------ ------- -----------
 * 10/04/10  TAB    1.0.0   Initial Development
 *
 * @package javascript
 * @subpackage option
 * @author Todd Brandys
 * @copyright Copyright (c) 2010, Webcellence, Inc.
 * @since 1.0.0
 * @version 3.0.0
 */

(function ( $ ) {

	var defaults = {
	};

	// ######################################################################################################
	// # PRIVATE METHODS
	// ######################################################################################################

	// ######################################################################################################
	// # PUBLIC METHODS
	// ######################################################################################################

	function prvOnChange( e ) {

		var optionsTotal = 0.0;
		$("div.options select[jsl='options'] option:selected").each(
			function ( index ) {

				var MATCHES = $(this).attr("price").match(/(-?)\D*(\d+\.?\d*)/);
				if (null !== MATCHES) {

					optionsTotal += Number(MATCHES[1] + MATCHES[2]);

				}

			}
		);

		$("span[original]").each(
			function ( index ) {

				var MATCHES = $(this).attr("original").replace(/,/, '').match(/(.?)(\d*\.\d*)(.?)/);
				var price = Number(MATCHES[2]) + optionsTotal;
				$(this).empty();
				var value = MATCHES[1] + price.toFixed(2) + MATCHES[3];
				$(this).append(value.replace(/(\d+)(\d{3})\./, '$1,$2.'));

			}
		);

	}

	// FUNCTION pubInitialize( )
	// ======================================================================================================
	/**
	 * Find all the <img> elements that are for selecting the different panes of content.  Then add an
	 * event handler for the click event.
	 *
	 * @since 3.0.0
	 */
	function pubInitialize( ) {

		$(this).change(prvOnChange);
		prvOnChange.apply(this, undefined);

	}

	// ######################################################################################################
	// # LINKAGE
	// ######################################################################################################
	var publicMethods = {
		"initialize"	:	pubInitialize
	};

	$.fn.jsl.options = function ( ) {

		switch (true) {

			// Called on DOM or jQuery objects.  Run the initialization function.
			//
			case 0 === arguments.length || "object" === typeof arguments[0]:
				pubInitialize.apply(this, arguments);
				break;

			case "string" === typeof arguments[0] && publicMethods[arguments[0]]:
				publicMethods[arguments[0]].apply(this, arguments.slice(1));
				break;

			default:
				$.error("Method " + arguments[0] + " is not defined for jQuery.jsl");

		}

	}

})(jQuery);

/**
 * [javascript/]title.js
 * ==========================================================================================================
 * The Webcellence product title jQuey plugin.
 *
 * ----------
 * CHANGE LOG
 * ----------
 * Date      By     Ver     Description
 * --------- ------ ------- -----------
 * 10/04/10  TAB    1.0.0   Initial Development
 *
 * @package javascript
 * @subpackage title
 * @author Todd Brandys
 * @copyright Copyright (c) 2010, Webcellence, Inc.
 * @since 1.0.0
 * @version 3.0.0
 */

(function ( $ ) {

	var defaults = {
	};

	// ######################################################################################################
	// # PRIVATE METHODS
	// ######################################################################################################

	// ######################################################################################################
	// # PUBLIC METHODS
	// ######################################################################################################

	// FUNCTION pubInitialize( )
	// ======================================================================================================
	/**
	 * Find all the <img> elements that are for selecting the different panes of content.  Then add an
	 * event handler for the click event.
	 *
	 * @since 3.0.0
	 */
	function pubInitialize( ) {

		var self = this;
		if (58 < $(this).outerHeight()) {

			switch ($(this).attr("id")) {

				case "sp-page-contentTitle":
					$(this).attr("id", "sp-page-contentTitleReduce");
					window.setTimeout(function ( ) { pubInitialize.apply(self); }, 200);
					break;

				case "sp-page-contentTitleReduce":
					$(this).attr("id", "sp-page-contentTitleReduce2");
					break;

			}

		}

	}

	// ######################################################################################################
	// # LINKAGE
	// ######################################################################################################
	var publicMethods = {
		"initialize"	:	pubInitialize
	};

	$.fn.jsl.title = function ( ) {

		switch (true) {

			// Called on DOM or jQuery objects.  Run the initialization function.
			//
			case 0 === arguments.length || "object" === typeof arguments[0]:
				pubInitialize.apply(this, arguments);
				break;

			case "string" === typeof arguments[0] && publicMethods[arguments[0]]:
				publicMethods[arguments[0]].apply(this, arguments.slice(1));
				break;

			default:
				$.error("Method " + arguments[0] + " is not defined for jQuery.jsl");

		}

	}

})(jQuery);


