﻿//Tab Support Script

// Global variables
var currentTab,currentLink;

// Change if you want to use another class for highlighting
var tabHighlightClass='current'; 

function initTabs()
{
// change if you have another main navigation id for tabbed or normal element id
    var navElement='calcnav';
	
// pattern to check against to identify "back to menu" links
    var backToMenu=/#top/;

    var n,as,id,i,cid,linklength,lastlink,re;
    if(document.getElementById && document.createTextNode)
    {
	    cid=window.location.toString().match(/#(\w.+)/);
	    if (cid && cid[1])
	    {
		    cid=cid[1];
	    }
	    var n=document.getElementById(navElement);
	    n=document.getElementById(navElement)
	    var as=n.getElementsByTagName('a');
	    for (i=0;i<as.length;i++)
	    {
		    as[i].onclick=function(){showTab(this);return false}
		    id=as[i].href.match(/#(\w.+)/)[1];
		    if(!cid && i==0)
		    {
			    currentTab=id;
			    currentLink=as[i];
		    } else if(id==cid)
		    {
			    currentTab=id;
			    currentLink=as[i];
		    }
		    if(document.getElementById(id))
		    {
			    linklength=document.getElementById(id).getElementsByTagName('a').length;
			    if(linklength>0)
			    {
				    lastlink=document.getElementById(id).getElementsByTagName('a')[linklength-1]
				    if(backToMenu.test(lastlink.href))
				    {
					    lastlink.parentNode.removeChild(lastlink);
				    }
			    }
			    document.getElementById(id).style.display='none';
		    }
		    if(cid){window.location.hash='top';}
	    }		

	    if(document.getElementById(currentTab))
	    {
		    document.getElementById(currentTab).style.display='block';
	    }
	    re=new RegExp('\\b'+tabHighlightClass+'\\b');
	    if(!re.test(currentLink.className))
	    {
		    //parent li gets highlight class attribute
		    //currentLink.parentElement.className=tabHighlightClass;
		    currentLink.parentNode.className=tabHighlightClass;
	    }
    }
}  

function showTab(o)
{
    var id;
    if(currentTab)
    {
	    //hide old current div
	    if(document.getElementById(currentTab))
	    {
		    document.getElementById(currentTab).style.display='none';
	    }
	    //strip old currentTab of highlight class
	    //currentLink.parentElement.className=currentLink.parentElement.className.replace(tabHighlightClass,'');
	    currentLink.parentNode.className=currentLink.parentNode.className.replace(tabHighlightClass,'');
    }
    var id=o.href.match(/#(\w.+)/)[1];
    currentTab=id;
    currentLink=o;
    if(document.getElementById(id))
    {
	    //show new current div
	    document.getElementById(id).style.display='block';
    }
    var re=new RegExp('\\b'+tabHighlightClass+'\\b');
    if(!re.test(o.className))
    {
	    //highlight new current div tab
	    //o.parentElement.className=tabHighlightClass
	    o.parentNode.className=tabHighlightClass
    }
}

// If you need to call other scripts onload, change this call
window.onload=initTabs;







/********************/
/* Slide Show Begin */
/********************/

// Set pause to off
var pause = 0;
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 7000;
// Duration of crossfade (seconds)
var crossFadeDuration = 2;
// Specify the image files
var Pic = new Array();

// to add more images, just continue the pattern, adding to the array below
Pic[0] = 'images/new/fit_banner.jpg'
Pic[1] = 'images/new/main_banner.jpg'
Pic[2] = 'images/new/tv5_banner.jpg'
// Specify the links
var Link = new Array();
// to add more links, just continue the pattern, adding to the array below
Link[0] = 'fit.aspx'
Link[1] = 'aboutus.aspx'
Link[2] = 'tvalue.aspx'

var t;
var j = -1;
var pLength = Pic.length;
var preLoad = new Array();
for (i = 0; i < pLength; i++) {
preLoad[i] = new Image();
preLoad[i].src = Pic[i];
}

function runSlideShow() {
    if (pause == 0) {
	    j = j + 1;
	    if (j > (pLength - 1)) j = 0;
	    if (document.all) {
		    document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
		    document.images.SlideShow.filters.blendTrans.Apply();
	    }
	    document.images.SlideShow.src = preLoad[j].src;
	    if (document.all) {
		    document.images.SlideShow.filters.blendTrans.Play();
	    }
	    t = setTimeout('runSlideShow()', slideShowSpeed);
    }
}

function gotoSlideLink() {
    window.location = Link[j];  
}

function nextSlide() {
    pause = 1;
    j = j + 1;
    if (j > (pLength - 1)) j = 0;
    document.images.SlideShow.src = preLoad[j].src;
}

function prevSlide() {
    pause = 1;
    j = j - 1;
    if (j < 0) j = pLength - 1;
    document.images.SlideShow.src = preLoad[j].src;
}
/******************/
/* Slide Show End */
/******************/