$(document).ready(function(){

	setTimeout('WT_tag_search()', 500)

});


function WT_tag_search()
{

if (typeof WT_productName == "undefined")
	WT_productName = ""

					//each item in this array is an array which describes a particular thing we want to track
					//	selector,	pg title,	product name,	link location,	link name,	alternate,	click depth,  tracking file
					//	selector,	WT.ti,	 	WT.pn_sku,		WT.z_ll,		WT.z_ln,	WT.si_n,	WT.si_x,  	  DCS.dcsuri
var WT_tag_search = new Array(
	//product pages styles, pack sizes, colors, whatever
	new Array("#product_pack ul li a", "ProductDetailTracking", WT_productName, "Products", "PackSizes", null, 1, "/ProductDetailtracking.html"),
	new Array("#product_style ul li a", "ProductDetailTracking", WT_productName, "Products", "Prints", null, 1, "/ProductDetailtracking.html"),
	new Array(".fmwipes #product_pack ul li a", "ProductDetailTracking", WT_productName, "Products", "TubColor", "SCO_prdBtn_tubColor", 1, "/ProductDetailtracking.html"),
	new Array(".fmwipes #product_style ul li a", "ProductDetailTracking", WT_productName, "Products", "PackSizes", "SCO_prdBtn_tubColor", 1, "/ProductDetailtracking.html"),
	
	/*
	new Array(".productBtns li.tub a", "ProductDetailTracking", WT_productName, "Products", "PackSizes", "SCO_prdBtn_tubColor", 1, "/ProductDetailtracking.html"),
	new Array(".productBtns li.refill a", "ProductDetailTracking", WT_productName, "Products", "PackSizes", "SCO_prdBtn_refill", 1, "/ProductDetailtracking.html"),
	new Array(".productBtns li.size a", "ProductDetailTracking", WT_productName, "Products", "PackSizes", "SCO_prdBtn_size", 1, "/ProductDetailtracking.html"),
	new Array(".productBtns li.style a", "ProductDetailTracking", WT_productName, "Products", "PackSizes", "SCO_prdBtn_style", 1, "/ProductDetailtracking.html"),
	*/
	
	//product page stuff
	new Array("a.likelike", "ProductDetailTracking", WT_productName, "Products", "Like", "SCO_prd_like", 1, "/ProductDetailtracking.html"),
	new Array(".moreActions .ask", "ProductDetailTracking", WT_productName, "Products", "Ask", "SCO_prd_ask", 1, "/ProductDetailtracking.html"),
	new Array("#stframe a", "ProductDetailTracking", WT_productName, "Products", "Share", "SCO_prd_share", 1, "/ProductDetailtracking.html"),
	new Array("#productReviewForm .btnSubmit", "ProductDetailTracking", WT_productName, "Products", "Write", "SCO_prd_write", 1, "/ProductDetailtracking.html"),
	new Array(".whereToBuy a", "ProductDetailTracking", WT_productName, "Products", "Buy", "SCO_buy", 1, "/ProductDetailtracking.html"),
	
	//coupons
	new Array(".savingsCoupon .coupon1", "CouponTracking", "", "ScottSavings", "SelectCoupon", "SCO_Coupon1", 1, "/CouponTracking.html"),
	new Array(".savingsCoupon .coupon2", "CouponTracking", "", "ScottSavings", "SelectCoupon", "SCO_Coupon2", 1, "/CouponTracking.html"),
	new Array("#couponSubmitForm .btnSubmit", "CouponTracking", "", "ScottSavings", "SelectCoupon", WT_productName, 2, "/CouponTracking.html"),
	
	/*
	new Array(".selectcoupon", "CouponTracking", "", "ScottSavings", "Coupon", "Coupon", 2, "/CouponTracking.html"),
	new Array(".signuptodaycoupon", "CouponTracking", "", "ScottSavings", "Coupon_Signup", "SCO_signup", 1, "/CouponTracking.html"),
	new Array("#couponSubmitForm .btnSubmit", "CouponTracking", "", "ScottSavings", "Coupon_Signup", WT_productName, 3, "/CouponTracking.html"),
	*/
	
	//comments
	new Array(".WT_postComment:visible", "TopicTracking", WT_productName, "Community", "PostComment", "SCO_PostComment", 1, "/TopicTracking.html"),
	new Array(".WT_viewComment:visible", "TopicTracking", WT_productName, "Community", "ViewComment", "SCO_ViewComment", 1, "/TopicTracking.html"),
	
	//start topic step 1 and 2
	new Array(".startnewTopics a, #topNavStartTopic a", "CommunityTracking", "", "Community", "StartTopic", "SCO_StartTopic", 1, "/CommunityTracking.html"),
	new Array(".topicFormSubmit .btnSubmit", "CommunityTracking", WT_productName, "Community", "StartTopic", "SCO_StartTopic", 2, "/CommunityTracking.html"),
	
	//member sign up step 1, 2, and 3
	new Array(".joinTheCommunity, .joinThecommunity, #menuLoginSignup a, .content-small .join a, .pollForm .formButtons .btnVote", "CommunityTracking", "", "Community", "SignUp", "SCO_MemberSignUp", 1, "/CommunityTracking.html"),
	new Array(".createAccount .formButtons .btnSubmit", "CommunityTracking", "", "Community", "SignUp", "SCO_MemberSignup", 2, "/CommunityTracking.html"),
	new Array(".profile .btnSubmit", "CommunityTracking", "", "", "", "SCO_MemberSignUp", 3, "/CommunityTracking.html"),
	
	//share an app idea
	new Array(".appsShare .btnSubmit", "AppTracking", "", "", "", "SCO_ShareApp", 2, "/AppTracking.html"),
	
	//view tip comments
	new Array(".WT_tipComment:visible", "TipTracking", WT_productName, "Tips", "PostComment", "SCO_PostComment", 1, "/TopicTracking.html"),
	
	//submit a tip step one and two
	new Array(".submitTip a, #topNavSubmitTip a", "TipTracking", "", "Community", "SubmitTip", "SCO_SubmitTip", 1, "/CommunityTracking.html"),
	new Array(".tipFormSubmit .btnSubmit", "TipTracking", "", "Community", "SubmitTip", "SCO_SubmitTip", 2, "/TipTracking.html"),
	
	//ask a question step one and two
	new Array(".askQ a, #topNavAskQ a", "CommunityTracking", "", "Community", "AskQuestion", "SCO_AskQuestion", 1, "/CommunityTracking.html"),
	new Array(".questionFormSubmit .btnSubmit", "CommunityTracking", "", "Community", "AskQuestion", "SCO_AskQuestion", 2, "/TipTracking.html"),
	
	//right-rail stuff
	new Array("#featuredWidget a, .featuredWidget a, .module .product a", "RightRailTracking", "", "RightRail", "", "RightRail", 1, "/RightRailTracking.html"),
	new Array(".right .coupon a", "RightRailTracking", "", "RightRail", "SensibleSavings", "RightRailCoupon", 1, "/RightRailTracking.html"),
	new Array(".right .join a", "RightRailTracking", "", "RightRail", "JoinCommunity", "RightRailJoin", 1, "/RightRailTracking.html")
);

	for(row=0; row < WT_tag_search.length; row++) //run this for each row of the array, it's easier this way
	{
		//special cases
		thisTag = WT_tag_search[row];
		if (thisTag[1] == "moist_wipes_details" && thisTag[3] == "PackSizes")
			thisTag[3] = "TubColor";
		else if (thisTag[1] == "moist_wipes_details" && thisTag[3] == "Prints")
			thisTag[3] = "TubRefills";
		//
		
		if ($(thisTag[0]).length > 0)
		{
			WT_tag_exec(thisTag[0], thisTag[1], thisTag[2], thisTag[3], thisTag[4], thisTag[5], thisTag[6], thisTag[7]);
		}
	}

}


function WT_tag_exec(WT_objectList, WT_title, WT_productName, WT_z_ll, WT_tag_ln, alt_tag, WT_depth, DCS_uri)
{	
	var counter = 1;
	
	$(WT_objectList).each(function() {
		
		$(this).unbind("mousedown")
		$(this).mousedown(function() {
			
				//special cases
				if (WT_objectList == "#couponSubmitForm .btnSubmit") //for coupon
				{
					var WT_email = $("#email").attr("value");
					var WT_emailOpt = $("#couponSubmitForm input:radio:checked").val();
				}
				else
				{
					WT_email = "";
					WT_emailOpt = "";
				}
				if (WT_title == "Community" && WT_tag_ln == "ViewComment")
				{
					WT_productName = escape($(this).parent().parent().find("h3").find(":first").html().trim())
				}
				if (WT_title == "RightRailTracking" && WT_tag_ln == "")
				{
					WT_tag_ln = escape($(this).parent().parent().find("h4").html().replace(/ /gi, ""))
				}
				//

				
			if (alt_tag && ($(WT_objectList).length == 1 || WT_title == "Community"))
				WT_alt = alt_tag;
			else if (alt_tag && $(WT_objectList).length > 1)
				WT_alt = alt_tag + counter++;
			else
				WT_alt = $(this).find(":first").attr("alt").replace(/ /gi, "")
			
			mainTag = 'WT.pn_sku';
			
			if (WT_title == "Community")
				mainTag = 'WT.z_topn';
			
			if (WT_title == "TipTracking")
				mainTag = 'WT.z_topn';
			
			if (WT_objectList == "#couponSubmitForm .btnSubmit")
				dcsMultiTrack('DCS.dcsuri', DCS_uri, 'WT.ti', WT_title, 'WT.dl', '40', 'DCS.dcsvid', WT_email, 'WT.z_EmailOpt', WT_EmailOpt, 'WT.si_n', WT_alt, 'WT.si_x', WT_depth, 'WT.si_cs', '1');
			else
				dcsMultiTrack('DCS.dcsuri', DCS_uri, 'WT.ti', WT_title, 'WT.dl', '40', mainTag, WT_productName, 'WT.z_ll', WT_z_ll, 'WT.z_ln', WT_tag_ln, 'WT.si_n', WT_alt, 'WT.si_x', WT_depth, 'WT.si_cs', '1');
			
		})
	})
}


