/*
*               __    _ __              __  __           _    _______
*              / /   (_) /_  ________  / /_/ /_____     | |  / /__  /
*             / /   / / __ \/ ___/ _ \/ __/ __/ __ \    | | / / /_ <
*            / /___/ / /_/ / /  /  __/ /_/ /_/ /_/ /    | |/ /___/ /
*           /_____/_/_.___/_/   \___/\__/\__/\____/     |___//____/
*
*           2FluidCreative (AB) - 20/10/08
*/

PS={ // Purchase Subscription

	init:function() {
		$$('.nscript').each(function(ns) {
			ns.remove(); // remove additional Form fields for non-js browsers
		});
		// Show nice buttons instead
		$('subscriptionLengths').removeClassName('hidden');
		// Show price field
		$('currentPrice').removeClassName('hidden');
		// Show description firld
		$('currentDescription').removeClassName('hidden');

		// Add hidden field to store subscription length
		var hidden   = document.createElement('input');
		hidden.type  = "hidden";
		hidden.name  = "length";
		hidden.id    = "length";
		hidden.value = 3;
		$('newSubscription').appendChild(hidden);

		PS.addMonthEvents();

		/* Has password already? */
		$('hasPassword').observe('change', function() {
			if($('hasPassword').checked) $('password').focus();
		});
		$('password').observe('focus', function() {
			$('hasPassword').checked = true;
		});
		$('password').observe('blur', function() {
			if($F('password').blank()) {
				$('hasPassword').checked = false;
				$('hasNoPassword').checked = true;
			}
		});
	},

	addMonthEvents:function() {
		$$('#subscriptionLengths a').each(function(lengthLink) {
			lengthLink.observe('click', function(e) {
				Event.stop(e);
				// Make all inactive
				$$('#subscriptionLengths li.active').each(function(li) {
					li.removeClassName('active');
				});

				$(this.parentNode).addClassName('active'); // make selected active
				$('length').value = this.href.split("#")[1].split("-")[1];
				$$('#currentPrice p')[0].innerHTML = "Current Price: &pound;"+this.rel;

				$$('#currentDescription p')[0].innerHTML = this.title;
			}.bindAsEventListener(lengthLink));
		});
	},

	end:function() {
		$$('table.bannercontainer *, table.bannercontainer').each(function(el) {
			el.style.background = "transparent";
			el.style.fontFamily = '"Trebuchet MS ",Tahoma,Arial,sans-serif';
			el.style.fontSize   = "12px";
			el.style.color      = "#464A4B";
		});
	}
}

Event.onDOMReady(function() {
	if($('newSubscriptionAdd') != null && $F('newSubscriptionAdd') == 1) PS.init();
	if($$('table.bannercontainer').length != 0) PS.end();
});