/* 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 l = $('thought_landing');
	if (l != null && l.style.display != 'none') {
		new Effect.Fade('thought_landing');
		dotglu.thoughtTip = '';
	}
	var c = dotglu.thoughtTip; // current tip
	if (c == '') c = 1;

	// swap tips
	if (c != tip) {
		$('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.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;

	h += ' <a id="thought_walk_left" href="#'+ p +'" onclick="dotglu.showThoughtTip('+ p +');"><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 +');"><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();
		for (var i = 0; i < t.length; i++)
			$('thought_tip'+ (i+1)).style.zIndex = (100-i);
	}
}); //: dom:loaded
