var Engine = {
	initDropDowns : function()
	{
		jQuery(".dropdownmenu li").each(function()
			{
				jQuery(this).hover(
					function()
					{
						jQuery(this).children("ul").show();
					}, 
					function()
					{
						jQuery(this).children("ul").hide();
					}
				);
			}
		);
	},
	initCorners : function(selector,size)
	{
		jQuery(selector).each(function(i)
			{
				jQuery(this).corner(
					{
						tl: {radius: size},
						tr: {radius: size},
						bl: {radius: size},
						br: {radius: size}
					}
				);
			}
		);
	},
	clickClear : function(selector)
	{
		jQuery(selector).each(function(i)
			{
				jQuery(this).data("default",jQuery(this).val());
				jQuery(this).bind("focus",function(e)
					{
						if(jQuery(this).val() == jQuery(this).data("default"))
						{
							jQuery(this).val("");
						}
					}
				);
				jQuery(this).bind("blur",function(e)
					{
						if(jQuery(this).val() == "")
						{
							jQuery(this).val(jQuery(this).data("default"));
						}
					}
				);
			}
		);
	},
	cartSummary : function()
	{
		var summary = jQuery("#cart-contents .cartSummaryItem").text();
		var arSummary = summary.split(" ",1);
		var value = (arSummary[0] - 0) == arSummary[0] && arSummary[0].length > 0;
		if(!value)
		{
			jQuery("#stl_cart-summary .count").text(0);
		}
		else
		{
			jQuery("#stl_cart-summary .count").text(arSummary[0]);
		}
	},
	ShowFields : function(selector)
	{
		jQuery(selector).slideDown("normal");
	},
	HideFields : function(selector)
	{
		jQuery(selector).slideUp("normal");
	},
	EnableFields : function(selector)
	{
		jQuery(selector).find("input").attr("disabled","");
		jQuery(selector).find("select").attr("disabled","");
	},
	DisableFields : function(selector)
	{
		jQuery(selector).find("input").attr("disabled",true);
		jQuery(selector).find("select").attr("disabled",true);
	},
	SameAsShipping : function()
	{
		if(jQuery("#SameAsShipping").is(":checked"))
		{
			Engine.CopyFieldValue("#ShippingAddress","#BillingAddress");
			Engine.CopyFieldValue("#ShippingCity","#BillingCity");
			Engine.CopyFieldValue("#ShippingState","#BillingState");
			Engine.CopyFieldValue("#ShippingZip","#BillingZip");
			Engine.CopyFieldValue("#ShippingCountry","#BillingCountry");
		}
		else
		{
			jQuery("#BillingAddress").val("");
			jQuery("#BillingCity").val("");
			jQuery("#BillingState").val("");
			jQuery("#BillingZip").val("");
			jQuery("#BillingCountry").val("");
		}
	},
	CopyFieldValue : function(selectorSource,selectorDestination)
	{
		jQuery(selectorDestination).val(jQuery(selectorSource).val());
	},
	initBlogRoll : function(selector)
	{
		var _url = "http://" + document.location.host + "/RSSRetrieve.aspx?ID=5315&Type=RSS20";
		
		jQuery.ajax(
			{
				type: "POST",
				url: _url,
				data: "action=1",
				success: function(msg){
					if(jQuery(msg).find("item").length < 1)
					{
						jQuery(selector).append("<div class='wa-blogroll-listing-item'><p>No blog entries were found.</p></div>");
					}
					else
					{
						jQuery(msg).find("item").each(function(i)
							{
								if(i < 3)
								{
									var _title = jQuery(this).find("title").text();
									var _date = Engine.parseRSSDate(jQuery(this).find("pubDate").text());
									var _link = jQuery(this).find("link").text();
									var _content = jQuery(this).find("description").text();
									var _truncated = _content.substring(0,100);
									var _scrubbed = "";
									_scrubbed = _truncated.replace("<p>","");
									_scrubbed = _scrubbed.replace("</p>","");
									_scrubbed = _scrubbed + "...";
									jQuery(selector).append("<div class='wa-blogroll-listing-item'><h3>" + _title + "<span class='date'>" + _date + "</span></h3><p>" + _scrubbed + "</p><p><a href='" + _link + "'>read more</a></p></div>");
								}
							}
						);
					}
				},
				error: function(msg){
					jQuery(selector).append("<div class='wa-blogroll-listing-item'><p>No blog entries were found.</p></div>");
				}
			}
		);
	},
	parseRSSDate : function(strDate)
	{
		var _arDate = strDate.split(" ");
		
		var dayName = _arDate[0];
		var dayNumber = _arDate[1];
		var monthName = _arDate[2];
		var yearNumber = _arDate[3];
		var time = _arDate[4];
		var timeType = _arDate[5];
		
		return monthName + " " + dayNumber + ", " + yearNumber;
	}
}
