 $(document).ready(function(){
//		alert('JQUERY working');



	//General Tab
	$(".tab-box .tab-contents").not(".tab-box .tab1-contents").hide();
	$(".tab-box .tabs a.tab1").click(function(){
		$(this).addClass("selected").parent().siblings().children(".tab").removeClass("selected");
		$(this).parents(".tabs").siblings(".tab-contents").hide();
		$(this).parents(".tabs").siblings(".tab1-contents").show();
	})
	$(".tab-box .tabs a.tab2").click(function(){
		$(this).addClass("selected").parent().siblings().children(".tab").removeClass("selected");
		$(this).parents(".tabs").siblings(".tab-contents").hide();
		$(this).parents(".tabs").siblings(".tab2-contents").show();
	})
	$(".tab-box .tabs a.tab3").click(function(){
		$(this).addClass("selected").parent().siblings().children(".tab").removeClass("selected");
		$(this).parents(".tabs").siblings(".tab-contents").hide();
		$(this).parents(".tabs").siblings(".tab3-contents").show();
	})
	$(".tab-box .tabs a.tab4").click(function(){
		$(this).addClass("selected").parent().siblings().children(".tab").removeClass("selected");
		$(this).parents(".tabs").siblings(".tab-contents").hide();
		$(this).parents(".tabs").siblings(".tab4-contents").show();
	})
	$(".tab-box .tabs a.tab5").click(function(){
		$(this).addClass("selected").parent().siblings().children(".tab").removeClass("selected");
		$(this).parents(".tabs").siblings(".tab-contents").hide();
		$(this).parents(".tabs").siblings(".tab5-contents").show();
	})



});   // JQuery END.

//Show overlay and popup window
function getGenericOverlayObject() {
	return new Overlay(document.body,{
		id: 'overlay',
		color: '#fff',
		duration: 0,
		opacity: 0.5,
		onClick: function() {
			if (this.parent) this.parent.close();
			this.close();
		},
		onShow: function() {
			//make ajax call while the overlay is happening...?
			//var Request = new Request()....
		}
	});
}

function OverlayWindow(id, info){
	this.window_div = document.getElementById(id);
	this.overlay = getGenericOverlayObject();
	this.overlay.parent = this;
	this.parent = false;
	this.show = function(noOverlay) {
		if (this.window_div) {
			if (!noOverlay) this.overlay.open();
			this.window_div.style.display = "block";
			if (this.window_div.parentNode && this.window_div.parentNode.style.display != "block") {
				this.window_div.parentNode.style.display = "block";
			}
		}
	}
	this.close = function(noOverlay) {
		if (this.window_div) {
			this.window_div.style.display = "none";
			if (!noOverlay) {
				if (this.window_div.parentNode && this.window_div.parentNode.style.display != "none") {
					this.window_div.parentNode.style.display = "none";
				}
				this.overlay.close();
			}
		}
	}
	this.initializeDiv = function(info) {
		if (!info.width) info.width = 800;
		if (!info.height) info.height = 480;
		if (this.window_div && this.window_div.innerHTML.indexOf("overlay-area-close.png") < 0) {
			var thisHeader = false;
			var thisBody = false;
			var thisFooter = false;
			for (var n=this.window_div.childNodes.length-1; n>=0; n--) {
				switch (this.window_div.childNodes[n].className) {
					case "overlay_area_header":
						thisHeader = this.window_div.childNodes[n];
						break;
					case "overlay_area_bodycontent":
						thisBody = this.window_div.childNodes[n];
						break;
					case "overlay_area_footer":
						thisFooter = this.window_div.childNodes[n];
						break;
				}
				this.window_div.removeChild(this.window_div.childNodes[n]);
			}
			this.window_div.style.width = (info.width) + "px";
			this.window_div.style.height = (info.height) + "px";
			var divID = String(this.window_div.id);
			//build the top
			var newTop = document.createElement("div");
			newTop.className = "overlay_area_top";
			var tDiv = document.createElement("div");
			tDiv.className = "overlay_area_tl";
			tDiv.appendChild(document.createTextNode(" "));
			newTop.appendChild(tDiv);
			var tDiv = document.createElement("div");
			tDiv.className = "overlay_area_t";
			tDiv.style.width = (info.width - 57) + "px";
			tDiv.appendChild(document.createTextNode(" "));
			newTop.appendChild(tDiv);
			var tDiv = document.createElement("div");
			tDiv.className = "overlay_area_tr";
			var tA = document.createElement("a");
			tA.setAttribute("href", "#");
			tA.setAttribute("onmouseup", info.objectname + ".close();");
			tA.appendChild(document.createTextNode(" "));
			tDiv.appendChild(tA);
			newTop.appendChild(tDiv);
			this.window_div.appendChild(newTop);
			//build the body
			var newMid = document.createElement("div");
			newMid.className = "overlay_area_mid";
			var tDiv = document.createElement("div");
			tDiv.className = "overlay_area_l";
			tDiv.style.height = (info.height - 54) + "px";
			tDiv.appendChild(document.createTextNode(" "));
			newMid.appendChild(tDiv);
			var tDiv = document.createElement("div");
			tDiv.className = "overlay_area_contents";
			tDiv.style.width = (info.width - 27) + "px";
			tDiv.style.height = (info.height - 54) + "px";
			//add header
			if (thisHeader || info.header) {
				if (!thisHeader) {
					var thisHeader = document.createElement("div");
					thisHeader.className = "overlay_area_header";
					thisHeader.appendChild(document.createTextNode(info.header));
				}
				tDiv.appendChild(thisHeader);
			}
			//get the footer, but don't append it yet
			if (thisFooter || info.footer || (info.ids && info.ids.length)) {
				if (!thisFooter) {
					var thisFooter = document.createElement("div");
					thisFooter.className = "overlay_area_footer";
					if (info.ids && info.ids.length) {
						var tUL = document.createElement("ul");
						for (var n=0; n<info.ids.length; n++) {
							var tClass = info.ids[n];
							var selClass = ( (info.ids[n] == divID) ? "overlay_footer_sel" : "");
							var liClass = ( (info.ids[n] == divID) ? "overlay_footer_li_sel" : "");
							var tLI = document.createElement("li");
							if (liClass) tLI.className = liClass;
							var tA = document.createElement("a");
							tA.setAttribute("href", "#");
							tA.setAttribute("onmouseup", info.objectname + ".show('" + info.ids[n] + "');");
							tA.className = info.ids[n] + ( (selClass) ? " " + selClass : "");
							tA.appendChild(document.createTextNode(" "));
							tLI.appendChild(tA);
							tUL.appendChild(tLI);
						}
						thisFooter.appendChild(tUL);
					}
					else {
						thisFooter.appendChild(document.createTextNode(info.footer));
					}
				}
			}
			//add body
			var newBody = document.createElement("div");
			newBody.className = "overlay_area_body";
			tDiv.style.width = (info.width - 27) + "px";
			var bodyHeight = (info.height - 89);
			if (thisHeader) bodyHeight -= 36;
			if (thisFooter) bodyHeight -= 44;
			var arrowPadding = ((parseInt((info.height - 54) / 2) - 16) - ( (thisFooter) ? 44 : 0 ));
			//tDiv.style.height = (bodyHeight) + "px";
			if (info.ids && info.ids.length) {
				var arrowDiv = document.createElement("div");
				arrowDiv.className = "overlay_area_leftarrow";
				arrowDiv.style.paddingTop = arrowPadding + "px";
				arrowDiv.style.paddingBottom = arrowPadding + "px";
				var tA = document.createElement("a");
				tA.setAttribute("href", "#");
				tA.setAttribute("onmouseup", info.objectname + ".prev();");
				tA.appendChild(document.createTextNode(" "));
				arrowDiv.appendChild(tA);
				newBody.appendChild(arrowDiv);
			}
			if (!thisBody) {
				thisBody = document.createElement("div");
				thisBody.className = "overlay_area_bodycontent";
				thisBody.appendChild(document.createTextNode("No Contents Defined"));
			}
			newBody.appendChild(thisBody);
			if (info.ids && info.ids.length) {
				var arrowDiv = document.createElement("div");
				arrowDiv.className = "overlay_area_rightarrow";
				arrowDiv.style.paddingTop = arrowPadding + "px";
				arrowDiv.style.paddingBottom = arrowPadding + "px";
				var tA = document.createElement("a");
				tA.setAttribute("href", "#");
				tA.setAttribute("onmouseup", info.objectname + ".next();");
				tA.appendChild(document.createTextNode(" "));
				arrowDiv.appendChild(tA);
				newBody.appendChild(arrowDiv);
			}
			tDiv.appendChild(newBody);
			//add the footer to the mid
			if (thisFooter) {
				tDiv.appendChild(thisFooter);
			}
			newMid.appendChild(tDiv);
			var tDiv = document.createElement("div");
			tDiv.className = "overlay_area_r";
			tDiv.style.height = (info.height - 54) + "px";
			tDiv.appendChild(document.createTextNode(" "));
			newMid.appendChild(tDiv);
			this.window_div.appendChild(newMid);
			//build the bottom
			var newBot = document.createElement("div");
			newBot.className = "overlay_area_bot";
			var tDiv = document.createElement("div");
			tDiv.className = "overlay_area_bl";
			var tText = document.createTextNode(" ");
			tDiv.appendChild(document.createTextNode(" "));
			newBot.appendChild(tDiv);
			var tDiv = document.createElement("div");
			tDiv.className = "overlay_area_b";
			tDiv.appendChild(document.createTextNode(" "));
			tDiv.style.width = (info.width - 47) + "px";
			newBot.appendChild(tDiv);
			var tDiv = document.createElement("div");
			tDiv.className = "overlay_area_br";
			tDiv.appendChild(document.createTextNode(" "));
			newBot.appendChild(tDiv);
			this.window_div.appendChild(newBot);
			var tParent = this.window_div.parentNode;
			var tGParent = tParent.parentNode;
			if (!tGParent.tagName || tGParent.tagName.toLowerCase() != "body") {
				tGParent.removeChild(tParent);
				document.body.appendChild(tParent);
			}
		}
	}
	this.initializeDiv(info);
}
function OverlayWindowSet(info) {
	if (!info.height) info.height = 480;
	if (!info.width) info.width = 800;
	this.objectname = info.objectname;
	this.height = info.height;
	this.width = info.width;
	this.presentwindow = "";
	this.showing = false;
	this.windows = new Object();
	this.ids = info.ids;
	this.overlay = getGenericOverlayObject();
	this.overlay.parent = this;
	//methods
	this.initialize = function(info) {
		for (var n=0; n<this.ids.length; n++) {
			var tDiv = document.getElementById(this.ids[n]);
			if (tDiv) {
				this.windows[this.ids[n]] = new OverlayWindow(this.ids[n], info);
			}
		}
	}
	this.show = function(id) {
		if (!id && this.ids.length) id = this.ids[0];
		if (id && this.windows[id]) {
			if (!this.is_showing) this.overlay.open();
			if (this.presentwindow && this.windows[this.presentwindow]) {
				this.windows[this.presentwindow].close(true);
			}
			this.windows[id].show(true);
			this.presentwindow = id;
			this.showing = true;
		}
	}
	this.next = function() {
		for (var n=0; n<this.ids.length; n++) {
			if (this.ids[n] == this.presentwindow) {
				n++;
				break;
			}
		}
		if (n == this.ids.length) n = 0;
		this.show(this.ids[n]);
	}
	this.prev = function() {
		for (var n=0; n<this.ids.length; n++) {
			if (this.ids[n] == this.presentwindow) {
				n--;
				break;
			}
		}
		if (n == -1) n = this.ids.length-1;
		this.show(this.ids[n]);
	}
	this.close = function() {
		for (var n=0; n<this.ids.length; n++) {
			if (this.windows[this.ids[n]]) {
				this.windows[this.ids[n]].close(true);
				if (this.windows[this.ids[n]].window_div && this.windows[this.ids[n]].window_div.parentNode && this.windows[this.ids[n]].window_div.parentNode.style.display != "none") {
					this.windows[this.ids[n]].window_div.parentNode.style.display = "none";
				}
			}
		}
		this.overlay.close();
		this.showing = false;
	}
	this.initialize(info);
}



//mootools - Overlay
var Overlay = new Class({
	
	Implements: [Options,Events],
	
	options:  {
		id: 'overlay',
		color: '#fff',
		duration: 500,
		opacity: 0.5,
		zIndex: 5000/*,
		onClick: $empty,
		onClose: $empty,
		onHide: $empty,
		onOpen: $empty,
		onShow: $empty
		*/
	},
	
	initialize: function(container,options) {
		this.setOptions(options);
		this.container = document.id(container);
		this.overlay = new Element('div',{
			id: this.options.id,
			opacity: 0,
			styles: {
				position: 'absolute',
				background: this.options.color,
				left: 0,
				top: 0,
				'z-index': this.options.zIndex
			},
			events: {
				click: function() {
					this.fireEvent('click');
				}.bind(this)
			}
		}).inject(this.container);
		this.tween = new Fx.Tween(this.overlay,{ 
			duration: this.options.duration,
			link: 'cancel',
			property: 'opacity',
			onStart: function() {
				var size = this.container.getScrollSize();
				this.overlay.setStyles({
					width: size.x,
					height: size.y
				});
			}.bind(this),
			onComplete: function() {
				this.fireEvent(this.overlay.get('opacity') == this.options.opacity ? 'show' : 'hide');
			}.bind(this)
		});
	},
	open: function() {
		this.fireEvent('open');
		this.tween.start(this.options.opacity);
	},
	close: function() {
		this.fireEvent('close');
		this.tween.start(0);
	}
});

