/* HomeGoods ~ JAVASCRIPT Thought Starters

	Author: Joel Nagy | dotglu
	Last Modified: April 10th, 2009 12:12:12 PM EST

	Dependency: prototype 1.7 and scriptaculous 1.8 
*/

// NAMESPACE
if (dotglu == null) // check for existence of namespace
var dotglu = {};

dotglu.thoughtTipCount = 1; // tip count for current tab
dotglu.thoughtTip = 1; // current tip

dotglu.showThoughtTip = function (tip) {
	var c = dotglu.thoughtTip; // current tip
	// swap tips
	$('thought_tip'+ c).style.zIndex = 10000;
	$('thought_tip'+ tip).style.zIndex = (1000-dotglu.thoughtTipCount);
	$('thought_tip'+ tip).style.display = 'block';
	new Effect.Fade('thought_tip'+ c);
	dotglu.thoughtTip = tip;
	dotglu.updateTipWalk();
	dotglu.trackPage(s, "HOM", c);
}

dotglu.trackPage = function(s, strChain, tip) {
	var t = dotglu.getTab();
	var strName;
	switch(t)
	{
	case 'One':
		strName = "EverydayPickMeUps";
		break;
	case 'Two':
		strName = "GiftGiving";
		break;
	case 'Three':
		strName = "FuncFashion";
		break;
	case 'Four':
		strName = "Entertaining";
		break;
	case 'Five':
		strName = "Decorating";
		break;		
	/* default: 
		strName = "EverydayPickMeUps"; */
	}	
	s.pageName= strChain + "_" + strName + tip;
	var s_code=s.t();
	if(s_code)document.write(s_code);
}

dotglu.getTab = function() {
	var a = "tjxhomegoods"; 
	
	var x = window.location.search;
	var y = [];
	var z = [];
	
	if (x.length > 0) {
		y = x.split("="); 
		if (y.length > 0) {
			z = y[1].split("#");
		}
	}
	else z[0] = 'One';	
	return z[0];
}

dotglu.allThoughtTips = function () {
	
}

dotglu.updateTipWalk = function () {
	var h = '', i = dotglu.thoughtTip, l = dotglu.thoughtTipCount;
	var p = dotglu.thoughtTip-1 >= 1? dotglu.thoughtTip-1: l, n = dotglu.thoughtTip+1 <= l? dotglu.thoughtTip+1: 1;
	
	// begin omniture stuff
	// change to 'tjxhomegoods' for production; 'tjxdev' for dev't
	var a = "tjxdev"; 
	var t = dotglu.getTab();
	
	// set link names
	var link_name = "";
	var left_name = "";
	var right_name = "";
	
	switch(t)
	{
	case 'One':
		link_name = "ts_pickmeup_";
		break;
	case 'Two':
		link_name = "ts_giftgiving_";
		break;
	case 'Three':
		link_name = "ts_funcfashion_";
		break;
	case 'Four':
		link_name = "ts_entertaining_";
		break;
	case 'Five':
		link_name = "ts_decorating_";
		break;		
	default:
		link_name = "ts_pickmeup_";
	}	
	left_name = link_name + p;
	right_name = link_name + n;

	// end omniture stuff
	
	h += ' <a id="thought_walk_left" href="#'+ p +'" onclick="dotglu.showThoughtTip('+ p +');var s=s_gi(\''+ a +'\');s.tl(this,\'o\',\''+ left_name +'\');"><span>&lt;</span></a> ';
	h += ' <div id="thought_tip_current">'+ i +'</div> <div>of '+ l +'</div>';
	h += ' <a id="thought_walk_right" class="a" href="#'+ n +'" onclick="dotglu.showThoughtTip('+ n +');var s=s_gi(\''+ a +'\');s.tl(this,\'o\',\''+ right_name +'\');"><span>&gt;</span></a> ';
	
	$('thought_walk').update(h);
}

document.observe('dom:loaded', function() {
	// Tab Prep
	// find current tab, count tips and set up next|prev
	var tip = window.location.hash;
	
	// update tip count
	var T = $('thought_tabs');
	var t = T.getElementsBySelector('div.thought_tip');
	if (t.length > 0) {
		dotglu.thoughtTipCount = t.length;
		if (tip != '')
			dotglu.showThoughtTip(parseInt(tip.slice(1)));
		else {
			dotglu.updateTipWalk();
			dotglu.trackPage(s, "HOM", 1);
		}
		for (var i = 0; i < t.length; i++)
			$('thought_tip'+ (i+1)).style.zIndex = (100-i);
	}

}); //: dom:loaded
