//<![CDATA[

	/// <reference path="jquery-1.3.2-vsdoc.js" />
	///inetpub/wwwroot/jquery/
	// Closure
	(function($)
	{
		$.fn.slideMenu = function(options)
		{
			var opts = $.extend({}, $.fn.slideMenu.defaults, options);
			
			return this.each(function()
			{
				var $this = $(this);
				var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
				var timer = 0;
				
				

				$this.children(":not(li.Current, li#rss)").each(function()
				{
					var $this = $(this);
					var $child = $this.children("a");

					timer = (timer * o.multiplier + o.time);
					$child.animate({ paddingTop: o.padUp }, timer).animate({ paddingTop: o.padDown }, o.time);

					$this.hover(function()
					{
						$child.addClass("Hover").stop().animate({ paddingTop: o.padUp }, o.time);
					},
					function()
					{
						$child.stop().animate({ paddingTop: o.padDown }, o.time, function() { $(this).removeClass("Hover"); });
					});
				}).siblings("li#rss").each(function()
				{
					var $this = $(this);
					var $child = $this.children("a");

					timer = (timer * o.multiplier + o.time);
					
					// For some reason this fails with Fx 2 when loading.  The (identical) hover works fine.
					try
					{
						$child.animate({ backgroundPosition: "(" + o.backgroundOff + "px " + o.backgroundUp + "px)" }, timer).animate({ backgroundPosition: "(" + o.backgroundOff + "px " + o.backgroundDown + "px)" }, o.time);
					}
					catch (e) { }

					$this.hover(function()
					{
						$child.css({ backgroundPosition: o.backgroundOn + "px " + o.backgroundDown + "px" }).stop().animate({ backgroundPosition: "(" + o.backgroundOn + "px " + o.backgroundUp + "px)" }, o.time);
					},
					function()
					{
						$child.stop().animate({ backgroundPosition: "(" + o.backgroundOn + "px " + o.backgroundDown + "px)" }, o.time, function() { $(this).css({ backgroundPosition: o.backgroundOff + "px " + o.backgroundDown + "px" }); });
					});
				});
			});
		};
		/*var markup = $this.html();
		// call our format function
		markup = $.fn.hilight.format(markup);
		$this.html(markup);
		});
		};

		//
		// private function for debugging
		//
		function debug($obj) {
		if (window.console && window.console.log)
		window.console.log('hilight selection count: ' + $obj.size());
		};
		//
		// define and expose our format function
		//
		$.fn.hilight.format = function(txt) {
		return '<strong>' + txt + '</strong>';
		};*/

		$.fn.slideMenu.defaults = 
		{
			padUp: 7,
			padDown: 15,
			backgroundOff: 9,
			backgroundOn: -29,
			backgroundDown: 13,
			backgroundUp: 4,
			time: 150,
			multiplier: 0.83
		};
	})(jQuery);

/*$.fn.extend({
  jLoader:function(config, fileNames) {
			
    var config = $.extend({}, $.jLoader.defaults, config);

    config.imgContainer = this.attr("id");    

    (config.simpleFileNames == true) ? simpleLoad(config) : complexLoad(config, fileNames) ;

    return this;
  }
});*/

	(function($)
	{
		$(document).ready(function()
		{
			// Override WP Thickbox image locations with absolute paths.
			tb_pathToImage = "/wordpress/wp-includes/js/thickbox/loadingAnimation.gif";
			tb_closeImage = "/wordpress/wp-includes/js/thickbox/tb-close.png";
			imgLoader.src = tb_pathToImage;
			
			// Inconsistent subpixel alignment (kinda) fix
			if (!$.browser.mozilla)
			{ 
				$(".Header").css("margin-left", "-1px").children(".Menu").css({ backgroundPosition: "2px 0", width: "772px" });
			}
			
			$(".Menu").slideMenu();
			
			$(".Menu .SearchInput").each(function()
			{
				var searchTxt = $(this).val();
				
				if (searchTxt == "")
				{
					$(this).val("Search").addClass("Blank");
				}
				else if (searchTxt == "Search")
				{
					$(this).addClass("Blank");
				}
			}),
			
			$("a[href^='#'][href!='#']").click(function()
			{
				$("html, body").animate({ scrollTop: $($(this).attr("href")).addFade().offset().top - 100 }, 200);
			}),
			
			$(".SearchForm").submit(function()
			{
				var searchTxt = $(this).children(".SearchInput, .TextInput").val();
				return !(searchTxt == "Search" || searchTxt == "");
			}),	
			
			$(".Menu .SearchInput").focus(function()
			{
				if (this.value == "Search")
				{
					this.value = "";
				}
				else
				{
					selectAll(this);
				}
				
				$(this).removeClass("Blank");
			}),
			
			$(".Menu .SearchInput").blur(function()
			{
				if (this.value == "" || this.value == "Search")
				{
					this.value = "Search";
					$(this).addClass("Blank");
				}
			}),
			
			$(".TextInput:text").focus(function()
			{
				selectAll(this);
			}),
			
			/*$("table.Record").each(function()
			{
				$(this).find("tr:not(.RecordComment):even td").addClass("Even");
			}),*/
			
			$(".PullQuote").each(function()
			{
				var $this = $(this);
				this.fullHeight = $this.height();
				$this.children(".TheQuote").show();
				$this.children(".TheText").hide();
				this.quoteHeight = $this.height();
			}),
			
			$(".PullQuote").click(function()
			{
				var $this = $(this);
				
				if ($this.children(".TheQuote:visible").length > 0)
				{
					$this.fullHeight = this.fullHeight;
					
					$this.height(this.quoteHeight);
					$this.children(".TheQuote").fadeOut(400, function() { $this.animate( { height: $this.fullHeight + "px" }, 700, function() { $this.children(".TheText").fadeIn(300); }) });
				}
			}),
			
			$(".RecordComment div").each(function()
			{
				this.fullHeight = $(this).height();
				$(this).addClass("RecordToggle").append("<div class=\"RecordMore\"></div>");
			}),

			$(".RecordComment .RecordToggle").toggle(function()
			{
				$(this).animate( { height: this.fullHeight + "px" }, 300).children(".RecordMore").hide(100);
			}, 
			function()
			{
				$(this).animate( { height: "1.6em" }, 300).children(".RecordMore").show(400);
			}),
			
			// WP eCommerce variations replacer 
			$(".wpsc_variation_forms").each(function()
			{
				var $this = $(this);
				var vSelect = $this.children("select")[0];
				var vOp;
				
				var $vContainer = $this.append("<div class=\"WpscVariationContainer\"></div>").children(".WpscVariationContainer");
				$vContainer[0].variationNum = $(vSelect).attr("name").replace(/.*\[(.*)\]/, "$1");
				$vContainer[0].variationId = $(vSelect).attr("id");
				
				for (var op = 0; op < vSelect.options.length; op++)
				{
					vOp = $vContainer.append("<span>" + vSelect.options[op].text + "</span>").children("span")[op];
					vOp.vValue = vSelect.options[op].value;
				}
				
				$this.append("<input type=\"hidden\" id=\"" + $vContainer[0].variationId + "\" name=\"" + $(vSelect).attr("name") + "\" />");
				$this.append("<div class=\"WpscVariationError\">Please select a size first.</div>");
				$this.children("br, label, select").remove();
				// unbind doesn't seem to work here
				$this.parents("form").attr("onsubmit", "");
			}),
			
			$(".WpscVariationContainer span").click(function()
			{
				var $this = $(this);
				var $vContainer = $this.parent();
				
				$vContainer[0].vSelected = $this[0].vValue;
				$vContainer.children().removeClass("Selected");
				$this.addClass("Selected");
				$("#" + $vContainer[0].variationId).val($vContainer[0].vSelected);
				change_variation($this.parents("form").children("[name=\"prodid\"]").val(), Array($vContainer[0].variationNum), false);
			}),
			
			$(".WpscVariationContainer").parents("form").submit(function()
			{
				var vContainer = $(".WpscVariationContainer")[0];
				
				if (typeof(vContainer.vSelected) == "undefined")
				{
					$(".WpscVariationError").slideDown("slow");
				}
				else
				{
					$(".WpscVariationError").slideUp();
					//clearTimeout(vContainer.timer);
					submitform(this);
					//vContainer.timer = setTimeout(function() { $("#fancy_notification").fadeOut(); }, 5000);
				}
				return false;
			}),
			
			// WP eCommerce checkout details copier
			// Assume order is billing details, shipping details, (gateway), buy
			$(".wpsc_checkout_table").each(function()
			{
				var $sections = $(this).find("td[colspan=\"2\"]");
				var $billing;
				var $shipping;
				var $firstShipping;
				var $buy;
				var shippingIdx;
				var match;
				var fields = Array();
				var shippingHeadIdx;
				
				// Get the trs
				$billing = $sections.eq(0).parent();
				$shippingHead = $shipping = $sections.eq(1).parent();
				$buy = $sections.eq(2).parent();
				
				shippingHeadIdx = $shippingHead[0].rowIndex + 2;
				
				// Create lookup array (assume field names are unique, ignore * at end)
				for (var billingIdx = 0; ($billing = $billing.next())[0] != $shippingHead[0]; billingIdx++)
				{
					for (var billingText = $billing.children().eq(0).text().replace(/(.*?)\*?\t*$/, "$1").toLowerCase(), $shipping = $shippingHead, shippingIdx = 0; ($shipping = $shipping.next())[0] != $buy[0] && !(match = billingText == $shipping.children().eq(0).text().replace(/(.*?)\*?\t*$/, "$1").toLowerCase()); shippingIdx++);					
					if (match) fields[billingIdx + 1] = shippingIdx + shippingHeadIdx;
				}
				
				$shippingHead.after("<tr><td colspan=\"2\"><input type=\"checkbox\" id=\"sameDetails\" name=\"sameDetails\" value=\"0\" /> <label for=\"sameDetails\">Same as billing details</label></td></tr>");
				
				// Why does change not work with IE?	
				$("#sameDetails").data("fields", fields).click(function()
				{
					var $this = $(this);
					var source;
					var dest;
					var $rows = $(".wpsc_checkout_table tr");
					
					if ($this.is(":checked"))
					{
						for (var source = 0; source < $this.data("fields").length; source++)
						{
							if ((dest = $this.data("fields")[source]) != undefined)
							{
								$($rows[dest]).find(":text, textarea").val($($rows[source]).find(":text, textarea").val());
							}
						}
					}
				});
			}),
			
			$("#fancy_notificationimage").attr("src", "/wordpress/wp-content/themes/jump/images/dark-loader.gif"),
						
			$.fn.extend(
			{
				addFade: function()
				{
					return this.each(function() { doBGFade(this, [255, 246, 191], [255, 255, 255], "transparent", 50, 10, 2); });
				}
			});
		});
			
		// Fade code from http://www.codylindley.com/blogstuff/js/jquery/
		function easeInOut(minValue,maxValue,totalSteps,actualStep,powr)
		{
			var delta = maxValue - minValue;
			var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
			return Math.ceil(stepp);
		}

		function doBGFade(elem,startRGB,endRGB,finalColor,steps,intervals,powr) 
		{
			if (elem.bgFadeInt) window.clearInterval(elem.bgFadeInt);
			var actStep = 0;
			elem.bgFadeInt = window.setInterval(
				function() {
					elem.style.backgroundColor = "rgb("+
						easeInOut(startRGB[0],endRGB[0],steps,actStep,powr)+","+
						easeInOut(startRGB[1],endRGB[1],steps,actStep,powr)+","+
						easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)+")";
					actStep++;
					if (actStep > steps) {
					elem.style.backgroundColor = finalColor;
					window.clearInterval(elem.bgFadeInt);
					}
				}
				,intervals)
		}
		
		function selectAll(ctl)
		{
			ctl.focus();
			ctl.select();
		}
	})(jQuery);

	/**
	 * jquery.backgroundPosition
	 * @author Alexander Farkas
	 * v. 1.02
	 */
	(function($) {
		$.extend($.fx.step,{
			backgroundPosition: function(fx) {
				if (fx.state === 0 && typeof fx.end == 'string') {
					var start = $.curCSS(fx.elem,'backgroundPosition');
					
					// IE fix
					if (start == undefined)
					{
						start = $.curCSS(fx.elem, 'backgroundPositionX') + ' ' + $.curCSS(fx.elem, 'backgroundPositionY');
					}
					
					start = toArray(start);
					fx.start = [start[0],start[2]];
					var end = toArray(fx.end);
					fx.end = [end[0],end[2]];
					fx.unit = [end[1],end[3]];
				}
				var nowPosX = [];
				nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
				nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
				fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
	            
			   function toArray(strg){
				   strg = strg.replace(/left|top/g,'0px');
				   strg = strg.replace(/right|bottom/g,'100%');
				   strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
				   var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
				   return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
			   }
			}
		});
	})(jQuery);
//]]>