// index.js

var tabSet = null;

function selectTab(set, index) {
	if (tabSet != null || !tabSet.isInitialized()) {
		tabSet.selectTab(set, index);
	}
}

function postInit() {
	tabSet = new TabSet();
	tabSet.init();
	embedFlash();
}

function embedFlash() {
	var flashplayer = new FlashPlayer();
	if (flashplayer.isInstalled()) {
		var flashVersion = flashplayer.getMajorVersion();
		if (flashVersion >= MIN_FLASH_VERSION) {
			// settings support by SWFObject 2.2 but not used are commented out -

			//var swfURL               = null;	// URL of SWF to be played
			var swfURL               = '/fpc-animation.swf';	// URL of SWF to be played

			var id                   = 'swfPlaceholder';		// specifies the id of the element to be replaced with Flash object code
			var width                = '528';					// flash object width
			var height               = '162';					// flash object height
			var version              = '8'						// minimum supported flash player version (major or major.minor.release format)
			var expressInstallSwfURL = '/includes/swf/expressinstall.swf';		
			var flashvars            = false;					// flashvars are specified in params below
			var params = { };
			//params.play            = '';
			params.menu              = 'false';
			//params.loop            = '';
			params.quality           = 'best';
			params.scale             = 'exactfit';
			//params.salign          = '';
			params.wmode             = 'transparent';			// transparent may preclude full screen on older flash players
			//params.bgcolor         = '';
			//params.base            = '';
			params.swliveconnect     = 'false';
			//params.flashvars         = '';
			//params.devicefont      = '';
			params.allowscriptaccess = 'sameDomain';
			//params.seamlesstabbing = '';
			params.allowfullscreen   = 'false';
			//params.allownetworking = '';
			var attributes = { };
			attributes.id            = 'flashPreview';
			//attributes.name          = '';
			attributes.styleclass    = 'movie';
			//attributes.align       = '';
			var callbackFn           = null;
			swfobject.embedSWF(swfURL, id, width, height, version, expressInstallSwfURL, flashvars, params, attributes, callbackFn);
		}
	}
}

function TabSet() {

	this.activeSet = 1;
	this.activeTab = 1;
	this.r1s1 = null;
	this.r1s2 = null;
	this.r2s1 = null;
	this.r2s2 = null;
	this.tabs = new Array();
	this.isInitialized = false;

	function init() {
		if (this.r1s1 == null) this.r1s1 = document.getElementById("row1set1");
		if (this.r1s2 == null) this.r1s2 = document.getElementById("row1set2");
		if (this.r2s1 == null) this.r2s1 = document.getElementById("row2set1");
		if (this.r2s2 == null) this.r2s2 = document.getElementById("row2set2");
		this.tabs[1] = new Array();
		this.tabs[1][1] = new Tab(1,1);
		this.tabs[1][2] = new Tab(1,2);
		this.tabs[1][3] = new Tab(1,3);
		this.tabs[2] = new Array();
		this.tabs[2][1] = new Tab(2,1);
		this.tabs[2][2] = new Tab(2,2);
		this.tabs[2][3] = new Tab(2,3);
		this.activeSet = 1;
		this.activeTab = 1;
		this.isInitialized = true;
	}
	this.init = init;

	function selectTab(set, index) {
		this.tabs[this.activeSet][this.activeTab].deselect();
		if (this.activeSet != set) {
			if (set == 1) {
				this.r1s1.style.visibility = "hidden";
				this.r2s1.style.visibility = "visible";
				this.r1s2.style.visibility = "visible";
				this.r2s2.style.visibility = "hidden";
			} else {
				this.r1s1.style.visibility = "visible";
				this.r2s1.style.visibility = "hidden";
				this.r1s2.style.visibility = "hidden";
				this.r2s2.style.visibility = "visible";
			}
			this.activeSet = set;
		}
		this.activeTab = index;
		this.tabs[this.activeSet][this.activeTab].select();
	}
	this.selectTab = selectTab;

}

function Tab(setNumber, indexNumber) {

	this.set = setNumber;
	this.index = indexNumber;
	this.clipDiv = null;
	this.tabEnd1 = null;
	this.tabEnd2 = null;
	this.subTab = null;
	this.content = null;

	function select() {
		this.init();
		this.clipDiv.className = "clip-at";
		this.tabEnd1.src = "/images/rowTabend-1-at.png";
		this.tabEnd2.src = "/images/rowTabend-2-at.png"; 
		this.subTab.src = "/images/rowSubTab-" + this.set + "-" + this.index + "-at.png";
		this.subTab.parentNode.className = "rowSubTab-at";
		this.content.style.display = "block";
	}
	this.select = select;

	function deselect() {
		this.init();
		this.clipDiv.className = "clip-off";
		this.tabEnd1.src = "/images/rowTabend-1-off.png";
		this.tabEnd2.src = "/images/rowTabend-2-off.png"; 
		this.subTab.src = "/images/rowSubTab-" + this.set + "-" + this.index + "-off.png";
		this.subTab.parentNode.className = "rowSubTab-off";
		this.content.style.display = "none";
	}
	this.deselect = deselect;

	function init() {
		var prefix = "s" + this.set + "t" + this.index;
		if (this.clipDiv == null) this.clipDiv = document.getElementById(prefix + "clipDiv");
		if (this.tabEnd1 == null) this.tabEnd1 = document.getElementById(prefix + "tabEnd1");
		if (this.tabEnd2 == null) this.tabEnd2 = document.getElementById(prefix + "tabEnd2");
		if (this.subTab == null) this.subTab = document.getElementById(prefix + "subTab");
		if (this.content == null) this.content = document.getElementById(prefix + "content");
	}
	this.init = init;

}

