var VIPSignup = {
	init: function() {
		var lis = $('#vip-signup').getElementsByTagName('strong');
		for (var i = 0; i < lis.length; i++) {
			var strong = lis[i];
			if (strong.className == 'vip-signup-strong') {
				var html = strong.innerHTML;
				var id = strong.parentNode.id.replace('show-', '');
				strong.innerHTML = '<a id="a-' + id + '" href="javascript:void(0);" class="vipsignup-hover">' + html + '</a>';
				var a = $('#a-' + id);
				Event.add(a, 'mouseover', VIPSignup.hover);
			}
		}
		Community.init();
		Newsletter.init();
		Kudos.init();
		Quiz.init();
		VIPSignup.show('newsletter');
	},
	show: function(s) {
		var lis = $('#vip-signup').getElementsByTagName('li');
		for (var i = 0; i < lis.length; i++) lis[i].className = '';
		$('#show-' + s).className = 'selected';
		
		if (s == 'community') Community.show();
		else Community.hide();
		if (s == 'newsletter') Newsletter.show();
		else Newsletter.hide();
		if (s == 'kudos') Kudos.show();
		else Kudos.hide();
		if (s == 'comps') Comps.show();
		else Comps.hide();
	},
	hover: function(e) {
		var id = Event.target(e).id.replace('a-', '');
		VIPSignup.show(id);
	},
	GLB: {
		timer: null
	}
};


var Kudos = {
	init: function() {
		var div = $('#extra-kudos');
		div.innerHTML = '<div id="extra-kudos-div"><img src="http://i.'+SITE_DOMAIN+'/images/vipsignup_kudos_overlay1.png" width="404" height="178" class="pngfix"></div>';
	},
	show: function() {
		Kudos.GLB.stopped = false;
		Kudos.anim();
	},
	hide: function() {
		Kudos.GLB.stopped = true;
	},
	anim: function() {
		Kudos.GLB.counter += 1;
		$('#extra-kudos-div').style.backgroundPosition = ( 0 - Kudos.GLB.counter ) + 'px 0';
		if (Kudos.GLB.stopped == false) VIPSignup.GLB.timer = setTimeout(Kudos.anim, 100);
	},
	GLB: {
		counter: 0,
		stopped: false
	}
};

var Newsletter = {
	init: function() {
		var div = $('#extra-newsletter');
		div.innerHTML = '<div id="extra-newsletter-div"><img src="http://i.'+SITE_DOMAIN+'/images/vipsignup_kudos_overlay.png" width="404" height="178" class="pngfix"></div>';
	},
	show: function() {
		Newsletter.GLB.stopped = false;
		Newsletter.anim();
	},
	hide: function() {
		Newsletter.GLB.stopped = true;
	},
	anim: function() {
		Newsletter.GLB.counter += 1;
		$('#extra-newsletter-div').style.backgroundPosition = ( 0 - Newsletter.GLB.counter ) + 'px 0';
		if (Newsletter.GLB.stopped == false) VIPSignup.GLB.timer = setTimeout(Newsletter.anim, 100);
	},
	GLB: {
		counter: 0,
		stopped: false
	}
};

var Comps = {
	show: function() {
		Comps.GLB.stopped = false;
		Comps.anim();
	},
	hide: function() {
		Comps.GLB.stopped = true;
	},
	anim: function() {
		Comps.GLB.counter += 1;
		$('#extra-comps').style.backgroundPosition = ( 0 - Comps.GLB.counter ) + 'px 0';
		if (Comps.GLB.stopped == false) VIPSignup.GLB.timer = setTimeout(Comps.anim, 100);
	},
	GLB: {
		counter: 0,
		stopped: false
	}
};

var Quiz = {
	init: function() {
		var html = $('#quiz-td').innerHTML;
		$('#quiz-td').innerHTML = '<b>' + html + '<span>' + html + '</span></b>';
	}
};

var Community = {
	init: function() {
		var activity = $('#extra-community');
		var html = '<div id="community-list-inner"></div>';
		if (Browser.browser == 'Explorer' && Browser.version <= 6) {}
		else html += '<span class="fade fade-l"></span><span class="fade fade-r"></span>';
		activity.innerHTML = html; //'<span class="fade fade-l"></span><span class="fade fade-r"></span>';
		var activityInner = $('#community-list-inner');
		
		// setup the 8 divs
		for (var i = 1; i <= 8; i++) {
			var div = Dom.add(activityInner, 'div', {id: 'div-' + i, nodeClass: 'community-list-outer'}, 'inner_end');
			var y = ( ( i % 8 ) * 22 ) + 1;
			div.style.top = y + 'px';
		}
		var radial = Math.floor( ( GLBCommunityActivity.length - 2 ) / 12 );
		for (var i = 0; i < GLBCommunityActivity.length - 2; i++) {
			var y = ( i % radial ) + 1;
			var thisitem = Dom.add($('#div-' + y), 'span', {id: 'item-' + i, nodeClass: 'item'}, 'inner_end');
			var rand = Math.ceil( Math.random() * 50 ) + 2;
			var html = '';
			for (var z = 0; z < rand; z++) html += '&nbsp;';
			thisitem.innerHTML = html + GLBCommunityActivity[i];
		}
	},
	show: function() {
		// get the width
		for (var i = 1; i <= 8; i++) {
			var div = $('#div-' + i);
			var width = Dom.pos(div, 'width');
			if (Community.GLB.width < width) Community.GLB.width = width;
		}
		Community.GLB.stopped = false;
		Community.anim();
	},
	hide: function() {
		Community.GLB.stopped = true;
	},
	anim: function() {
		Community.GLB.counter += 1;
		if (Community.GLB.counter > Community.GLB.width) Community.GLB.counter = 0 - Dom.pos($('#extra-community'), 'width');
		$('#community-list-inner').style.left = 0 - Community.GLB.counter + 'px';
		if (Community.GLB.stopped == false) VIPSignup.GLB.timer = setTimeout(Community.anim, 10);
	},
	GLB: {
		counter: 0,
		width: 0,
		stopped: false
	}
};

