var sp2;
var quotes;
var lastTab=1;

function switchTab(tab)
{
	if (tab!=lastTab)
	{
		document.getElementById(tab).className=("tabActive");
		document.getElementById(lastTab).className=("tab");
		sp2.showPanel("#Panel"+tab);
		lastTab=tab;
	}
}


function nextTab() {
	sp2.showPanel("#Panel"+current);
	if(current == spc){ 
		current = 0;
		return;
	} else {
	current = current +1;
	}
	switchTab(current);
}

var current = 0;

function start(){
	var spc = sp2.getContentPanelsCount(); 
	sp2.showPanel(current);
    //changes by naval
    if(current==0)
	   t=setTimeout(function(){start()},16000);
    else
       t=setTimeout(function(){start()},8000);
    //end changes by naval
       
	if(current == spc){ 
		current = 0;
		return;
	} else {
	current = current +1;
	}
	
	/*if (currentTab == spc) {
		currentTab=0;
		return;
	} else {
		currentTab = currentTab +1;
	}*/
	
	switchTab(current);
	
}


function stopPanel(){
	if(typeof(t) == 'number')clearTimeout(t);
}




function fadeInNextQuote()
{
	if (!quotes || quotes.length < 1)
		return;

	var curEle;

	if (typeof quotes.curIndex == "undefined")
		quotes.curIndex = quotes.length - 1;
	else
		curEle = quotes[quotes.curIndex];

	quotes.curIndex = (quotes.curIndex+1)%quotes.length;
	var nextEle = quotes[quotes.curIndex];

	if (curEle)
		Spry.Effect.DoFade(curEle, { from: 100, to: 0 });
	Spry.Effect.DoFade(nextEle, { to: 100, finish: function(){ setTimeout(function(){ fadeInNextQuote(); }, fadeInNextQuote.interval); } });
}

fadeInNextQuote.interval = 6000;

Spry.Utils.addLoadListener(function()
{
	// Show the sliding panels tab buttons.

	Spry.$$(".slidingTabPanelWrapper").setStyle("display: block");
	Spry.$$("1, 2, 3, 4, 5").addEventListener("mouseover", function(){ switchTab(this.id); stopPanel(); return false; }, false);
	
	Spry.$$("#next").addEventListener("click", function(){ nextTab(); stopPanel(); return false; }, false);

	// Turn the slidingPanel region into a real sliding panel widget.

	Spry.$$("#slidingPanel").addClassName("SlidingPanels").setAttribute("tabindex", "0");
	Spry.$$("#slidingPanel > div").addClassName("SlidingPanelsContentGroup");
	Spry.$$("#slidingPanel .SlidingPanelsContentGroup > div").addClassName("SlidingPanelsContent");
	sp2 = new Spry.Widget.SlidingPanels('slidingPanel');
	// Find the quoteBox and setup any quotes inside it for fading.
start();
	Spry.$$(".quoteBox").setStyle("position: relative; height: 260px;");
	quotes = Spry.$$(".quote").setStyle("position: absolute; top: 0px; left: 0px; opacity: 0; filter: alpha(opacity=0);");
	fadeInNextQuote();
});
