/*
 * Thoams Williams - AMO
 */

var current_tab = 0;
var panes = new Array();

(function($) {
	var amoTabbedViewer = window.amoTabbedViewer = function($) {
		return {
			load : function() {
				var count = 0;
				var rand = Math.floor(Math.random() * 4);
						var url = window.location.href;
				if(url.indexOf("tab=") != -1) {
					url = url.substring(url.indexOf("tab="));
					rand = parseInt(url.charAt(4));
				}
				$.get("/content.jsp?pageName=tabbedhomepage", function(data) {
					$(".amo-pane", data).each(function() {
						panes[count] = $(this).html();
						if (count == rand)
							$("#amo-tabbed-viewer-window-pane")[0].innerHTML = $(this).html();
						count++;
					});
					if(rand == 0) {
						$("#amo-tabbed-viewer-content0").css("z-index", "3");
						$("#amo-tabbed-viewer-content1").css("z-index", "2");
						$("#amo-tabbed-viewer-content2").css("z-index", "1");
						$("#amo-tabbed-viewer-content3").css("z-index", "0");
					} else if(rand == 1) {
						$("#amo-tabbed-viewer-content0").css("z-index", "2");
						$("#amo-tabbed-viewer-content1").css("z-index", "3");
						$("#amo-tabbed-viewer-content2").css("z-index", "1");
						$("#amo-tabbed-viewer-content3").css("z-index", "0");
					} else if(rand == 2) {
						$("#amo-tabbed-viewer-content0").css("z-index", "1");
						$("#amo-tabbed-viewer-content1").css("z-index", "2");
						$("#amo-tabbed-viewer-content2").css("z-index", "3");
						$("#amo-tabbed-viewer-content3").css("z-index", "0");
					} else {
						$("#amo-tabbed-viewer-content0").css("z-index", "0");
						$("#amo-tabbed-viewer-content1").css("z-index", "1");
						$("#amo-tabbed-viewer-content2").css("z-index", "2");
						$("#amo-tabbed-viewer-content3").css("z-index", "3");
					} 
				});
			}
		};
	}($);
})($)

function firstTabClick() {
	$("#amo-tabbed-viewer-content0").css("z-index", "3");
	$("#amo-tabbed-viewer-content1").css("z-index", "2");
	$("#amo-tabbed-viewer-content2").css("z-index", "1");
	$("#amo-tabbed-viewer-content3").css("z-index", "0");
	$("#amo-tabbed-viewer-window-pane")[0].innerHTML = panes[0];
}

function secondTabClick() {
	$("#amo-tabbed-viewer-content0").css("z-index", "2");
	$("#amo-tabbed-viewer-content1").css("z-index", "3");
	$("#amo-tabbed-viewer-content2").css("z-index", "1");
	$("#amo-tabbed-viewer-content3").css("z-index", "0");
	$("#amo-tabbed-viewer-window-pane")[0].innerHTML = panes[1];
}
function thirdTabClick() {
	$("#amo-tabbed-viewer-content0").css("z-index", "1");
	$("#amo-tabbed-viewer-content1").css("z-index", "2");
	$("#amo-tabbed-viewer-content2").css("z-index", "3");
	$("#amo-tabbed-viewer-content3").css("z-index", "0");
	$("#amo-tabbed-viewer-window-pane")[0].innerHTML = panes[2];
}
function fourthTabClick() {
	$("#amo-tabbed-viewer-content0").css("z-index", "0");
	$("#amo-tabbed-viewer-content1").css("z-index", "1");
	$("#amo-tabbed-viewer-content2").css("z-index", "2");
	$("#amo-tabbed-viewer-content3").css("z-index", "3");
	$("#amo-tabbed-viewer-window-pane")[0].innerHTML = panes[3];
}


amoTabbedViewer.load();

