CLoading.Toggle = function() {
}

TDooley = {};

TDooley.MenuMoving = false;
TDooley.SelectedColor = "";

TDooley.OnInit = function() {
	$("#SearchInput").bind("focus", function(e) {
		if($(this).attr("value") == "SEARCH") {
			$(this).attr("value", "");
		}
	}).bind("blur", function(e) { 
		if($(this).attr("value") == "") {
			$(this).attr("value", "SEARCH");
		}
	}).bind("keydown", function(e) {
		if(e.keyCode == 13) TDooley.Search();
	});

	$("#SearchGo").bind("click", TDooley.Search);

	$("#BannersPrevious").bind("click", TBanners.Previous);
	$("#BannersNext").bind("click", TBanners.Next);

	$("#ProductsLink").dropmenu();

	$("a[rel^=Lightbox]").lightBox();

	/*var PicCount = 100;

	$(".ViewProductColors a").each(function() {
		var ImageElement = $(this).find("img");

		if(ImageElement) {
			$(".ViewProductImage").append("<img alt=\"" + $(ImageElement).attr("title") + "\" id=\"pic" + PicCount + "\" src=\"" + $(this).attr("href") + "\" style=\"position: absolute; visibility: hidden;\" title=\"" + $(ImageElement).attr("title") + "\" rel=\"" + PicCount + "\">");

			$(ImageElement).removeAttr("onclick").unbind("click");

			$(ImageElement).attr("onclick", "javascript:change_prod(" + PicCount + ");");
			$(this).attr("href", "javascript:change_prod(" + PicCount + ");");
		}

		PicCount++;
	});

	$(".ViewProductColors a > img").bind("click", function() {
		$(".ViewProductImage img").css("visibility", "none");

		change_prod($(this).attr("rel"));
	});*/

	TDooley.WatchProductHeaders();
}

TDooley.WatchProductHeaders = function() {
	$(".ViewProductColors img").bind("click", function() {
		TDooley.SelectedColor = $(this).attr("title");
	});

	$(".ViewProductBody a").each(function() {
		var Href = $(this).attr("href");

		if(stripos(Href, "contact-us.php") !== false) {
			var ProdType = document.title;
			var ProdName = $("#prod_name").html();
			var Type = "";
			var Color = TDooley.SelectedColor;

			if(Color == "" && stripos(document.title, "megaphones") !== false)			Color = "Black";
			else if(Color == "" && stripos(document.title, "lids") !== false)			Color = "";
			else if(Color == "" && stripos(document.title, "shot") !== false)			Color = "Blue";
                        else if(Color == "" && stripos(document.title, "mood") !== false)			Color = "Royal Blue";
			else if(Color == "" && stripos(document.title, "polystyrene") !== false)	Color = "";
			else if(Color == "" && stripos(document.title, "unbreakable") !== false)	Color = "";
			else if(Color == "" && stripos(document.title, "styrofoam") !== false)		Color = "";
			else if(Color == "" && stripos(document.title, "offset") !== false)			Color = "White";
			else if(Color == "")														Color = "Yellow";


			if(ProdName == null) ProdName = $(".ViewProductBody h1").html();

			ProdName = strip_tags(ProdName);

			ProdName = explode("-", ProdName);
			if(count(ProdName) <= 1) ProdName = ProdName[0] + " " + Color;
			else {
				ProdName = ProdName[0] + Color + " -" + ProdName[1];
			}

			if(stripos($(this).find("img").attr("src"), "new-quote") !== false)			Type = "New Quote";
			if(stripos($(this).find("img").attr("src"), "order-sample") !== false)		Type = "Order Sample";
			if(stripos($(this).find("img").attr("src"), "shipping-estimate") !== false) Type = "Shipping Estimate";

			//ProdType + " - " + 

			$(this).attr("href", "/contact-us.php?Subject=" + encodeURIComponent(ProdName) + "&Type=" + Type);
		}
	});

	setTimeout(TDooley.WatchProductHeaders, 100);
}

TDooley.Search = function() {
	window.location.href = "/search/" + encodeURIComponent($("#SearchInput").attr("value"));
}

$(TDooley.OnInit);

