﻿// JScript File
function LoadAllTabs()
{
$$('div[GSWidget^=TabControl]').each(function(s){new GSTabControl(s);});
}


function GSTabControl(el)
{
this.tabs = [];
this.activeTab;

var tabContainer = this;
// create the array of items that are to exist in the FE
el.getElementsBySelector('img[GSwidgetItem=Tab]').each(function(s){tabContainer.tabs.push(new GSTab(s, tabContainer));}); 

this.DeactivateAll = function()
{
tabContainer.tabs.each(function(s){s.DeactivateTab();});
} 

var params = el.readAttribute('GSwidgetParams').evalJSON();

this.SwitchTabs = function(index)
{
tabContainer.tabs[index].ActivateTab();
}

try
{
this.tabs[params.ActiveTabIndex || 0].ActivateTab();
}
catch(e)
{
//debugger
this.tabs[0].ActivateTab();
}
}

function GSTab(el, parentControl)
{
this.controlElement = el;
this.contentDiv = $(el.readAttribute('GSTabTarget'));
this.isSelected = false;
this.id = parentControl.tabs.length;
this.parentControl = parentControl;
var tabControl= this;
this.ActivateTab = function()
{
tabControl.parentControl.DeactivateAll();
if(!tabControl.isSelected)
{tabControl.controlElement.src = tabControl.controlElement.src.sub('u.png', '.png');tabControl.controlElement.src = tabControl.controlElement.src.sub('u.gif', '.gif');}
tabControl.contentDiv.show();
tabControl.isSelected = true;
tabControl.parentControl.activeTab = tabControl;
}
this.DeactivateTab = function()
{
if(tabControl.isSelected)
{tabControl.controlElement.src = tabControl.controlElement.src.sub('.png', 'u.png') ;tabControl.controlElement.src = tabControl.controlElement.src.sub('.gif', 'u.gif') ;}
tabControl.contentDiv.hide();
tabControl.isSelected = false;
}
this.MouseToCursor = function()
{
tabControl.controlElement.style.cursor = 'pointer';
}

this.controlElement.observe('click', this.ActivateTab);
this.controlElement.observe('mouseover', this.MouseToCursor);


}