
function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		do
		{
			if (obj.getAttribute('id') == 'npricing' || obj.getAttribute('id') == 'ppage')
				break;
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}while (obj = obj.offsetParent);
	}
	return {x:curleft,y:curtop};
}

setOpacity = function(node, percentOpaque)
{
	if (node === false)
		return;
		
	if (percentOpaque == 100)
	{
		node.style.opacity = '';
		try /* This TRY block is a fix for GChrome, as it doesn't support style.removeAttribute */
		{
			node.style.removeAttribute('filter'); /* IE FIX - Internet Explorer will stop antialiasing when filter attribute is defined :-| */			
		}
		catch (e)
		{
		}
		return;
	}
	
	var _vopac = percentOpaque/100;
	if (_vopac < 0.01)
	{
		_vopac = '0';
	}
	else
	{
		if (_vopac < 0.1)
			_vopac = '0.0'+percentOpaque;
	}

	node.style.opacity=_vopac;
	node.style.filter = "alpha(opacity=" + percentOpaque + ")"; 
}

anim = function(maxDuration, options)
{
	this.getOption = function(name, def)
	{
		def = typeof(def) != 'undefined' ? def : false;
		return typeof(options[name])!='undefined' ? options[name] : def;
	}
 
	this.options = typeof(options)!='undefined' ? options : {};
	this.options.maxDuration = maxDuration;
	this.options.animspeed = this.getOption('animspeed', 3);	
	
	this.step = 0;
	this.animating = false;
	
	this.animCallback = function(step) {};	
	this.finishedCallback = function(forward) {};
	
	this.forward = function()
	{
		if (this.animating === false)
		{
			this.step = Math.min(this.options.maxDuration, Math.max(this.step, 0));
			this.animating = 1;	
			this.animate();
		}
		else
			this.animating = 1;
	}
	
	this.backward = function()
	{
		if (this.animating === false)
		{		
			this.step = Math.max(0, Math.min(this.step, this.options.maxDuration));
			this.animating = -1;	
			this.animate();
		}
		else
			this.animating = -1;
	}
	
	this.lastStep = -1;
	this.animate = function()
	{
		if (this.options.animreverse)
			var _val = Math.max(1,(this.options.maxDuration-this.step)/this.options.animspeed);
		else
			var _val = Math.max(1,(this.step/this.options.animspeed))
	
		if (this.animating == 1)
			this.step += _val;
		else
			this.step -= _val;	
	
		var cbv = Math.ceil(this.step);
		cbv = Math.max(0, cbv);
		cbv = Math.min(this.options.maxDuration, cbv);				
		
		if (this.lastStep != cbv)
		{
			this.lastStep = cbv;
			this.animCallback(cbv);
		}
	
		if (this.step > this.options.maxDuration || this.step<0)
		{
			this.animating = false;	
			this.finishedCallback(this.step > this.options.maxDuration);
		}
		else
		{
			var that = this;
			window.setTimeout(function() {that.animate();}, 20);
		}	
	}
}


var myTabs = function()
{
	this.onTabShow = function(num, completed) {};
	this.onTabHide = function(num, completed) {};
	
	var anims = [];
	var tabs = [];
	var that = this;

	this.getTitle = function(tabNum)
	{
		if ($type(this.tcache) == false)
			this.tcache = [];
		
		var t = '';
		if ($type(this.tcache[tabNum]) == false)
		{
			t = tabs[tabNum].getAttribute('title');
			if ( $type(t) == false || t=='')
				t = String(tabs[tabNum].getElement('a').get('text')).toLowerCase();
			
			if (t.indexOf(' ') > 0)
				t = t.substr(0, t.indexOf(' '));

			this.tcache[tabNum] = t;
		}
		else
			t = this.tcache[tabNum];

		return t;
	}
	
	this.init = function(opts)
	{
		tabs = $(document.body).getElements("ul.tabs li");

		if ($type(opts) == false )
			opts = {};
		if (opts.keep_size_placeholder)
		{
			var sizey = 0;
			for (var i=1; i<=tabs.length; i++)
			{
				var screen = $(document.body).getElement("#pl-screen"+i);
				with (screen)
				{
					style.visibilty = 'hidden';
					style.display = 'block';
					sizey = Math.max(sizey, getSize().y);
					style.visibilty = '';
					style.display = 'none';
				}
			}
			$(document.body).getElement(opts.keep_size_placeholder).style.height = sizey+"px";
		}


		// create animation objects
		for (var i=0; i<tabs.length; i++)
		{
			anim[i] = new anim(100, []);
		}

		$each(tabs, function(t, num)
		{
			anim[num].target = $(document.body).getElement("#pl-screen"+(num+1));
			anim[num].animCallback = function(step)
			{
				setOpacity(this.target, step);
			}
			anim[num].finishedCallback = function(forward)
			{
				if (!forward)
				{
					this.target.style.display = 'none';
				}

				if (forward)
					that.onTabShow(num, true);
				else
					that.onTabHide(num, true);
			}

			t.onclick = function()
			{
				window.location = "#"+that.getTitle(num);
			}
		});
		
		var last_h = -1;
		var monitor_names = [];
		for (var i=0; i<tabs.length; i++)
			monitor_names.push(this.getTitle(i));
		function monitor_hash()
		{
			var h = window.location.hash;
			if (h.indexOf('#') > -1)
				h = h.substr(h.indexOf('#')+1);

			var _h = 0;
			for (var i=0; i<monitor_names.length; i++)
			{
				if (monitor_names[i] == h)
				{
					_h = i;
					break
				}
			}

			if (last_h != _h)
			{
				last_h = _h;
				clickTab(_h, tabs);
				try
				{
					// remove any infopanel when switching screens
					$(document.body).getElement("#panel").style.display = 'none';		
					helpanim.xclick = true;
					helpanim.backward();
				}
				catch (e)
				{}
			}
			window.setTimeout(function () {monitor_hash();}, 200);
		}
		monitor_hash();
	}
	
	var last_active = -1;
	function clickTab(num, tabs)
	{
		anim[num].forward();
		$(document.body).getElement("#pl-screen"+(num+1)).style.display = 'block';
		if (last_active != -1 && last_active!=num)
		{
			that.onTabHide(last_active, false);
			anim[last_active].backward();
		}
		last_active = num;
		that.onTabShow(last_active, false);
	
		$each (tabs, function (t, num_) {
			t.className = (num_ != num) ? '' : 'selected';
		});
	}
}

function myQmark()
{
	this.init = function()
	{
		var helpanim = new anim(100, []);
		var helppanel = $(document.body).getElement("#panel .pa-text");
		var helpheader = $(document.body).getElement("#panel .header-content");
		helpanim.animCallback = function(step)
		{
			setOpacity(helppanel, step);
			setOpacity(helpheader, step);
		}
		helpanim.finishedCallback = function(forward)
		{

		}

		$(document.body).getElement("#panel #x").onclick = function()
		{
			helpanim.xclick = true;
			helpanim.backward();
		}

		var qms = $$('.qmark');
		$each (qms, function (q) {

			q.onclick = function() {
			helpanim.xclick = false;
			var panel = $(document.body).getElement("#panel");
			panel.style.left = findPos(q).x+30+"px";
			panel.style.top = findPos(q).y+30+"px";

			$(document.body).getElement("#panel").style.display = 'block';
			if (q.getAttribute('display')=='left')
				panel.style.left = findPos(q).x-panel.offsetWidth+30+"px";

			helpanim.finishedCallback = function(forward)
			{
				if (!forward && helpanim.xclick)
				{
					$(document.body).getElement("#panel").style.display = 'none';
					return;
				}
			
				if (!forward)
				{
					var nn = q.getElement('div').cloneNode(true);
			
					panel.getElement(".pa-text").set('html', '');
					panel.getElement(".pa-text").appendChild(nn);
					//var help_for = (q.parentNode.childNodes[0].nodeValue);
					var help_for = q.getAttribute('heading');
					panel.getElement(".pa-header .header-content").set('text', help_for);
				
					helpanim.forward();
				}
			}
			helpanim.backward();
		}

		});
	}
}


function myFaq()
{
	this.onFaqClick = function(num) {};
	
	var faq_selected = false;
	var that = this;
	
	this.init = function(opts)
	{
		this.opts = opts;	
		
		var node = opts.node + " li";
		$each ($$(node), function handler(el, num) { 

			el.onclick = function(e)
			{
				if (faq_selected !== false)
				{
					faq_selected.style.display = 'none';
					faq_selected.parentNode.className = '';
				}

				var __fs = faq_selected;
				faq_selected = el.getElement('span');
				if (__fs != faq_selected)
				{
					faq_selected.style.display = 'block';
					faq_selected.parentNode.className = 'active';
				}
				else
					faq_selected = false;

				faqClick(num+1);
			}

			el.getElement('span').onclick = function(e)
			{
				if (!e)
					var e = window.event
				e.cancelBubble = true;
				if (e.stopPropagation) e.stopPropagation();
			}

		});

	}

	function faqClick(num)
	{
		that.onFaqClick(num);		
	}	
}

