
var timer = new Array(null, null, null,null);
var theScroll = new Array();
var content = new Array();

var currentIndex = 0;
var timerInterval = 15;
var timerDelay = 800;

var arraypos = 0;
var no_end = 0;

var autoDelay1 = 60*1000;
var autoDelay2 = 60*1000;

var autoTimer = null;

function add_content(text){
	if(arraypos < content.length){
	}
	else{
		content.push(text);
		arraypos++;
	}
	
}

function write_content(a1, a2, a3, a4, a5){

	if(a1) timerInterval = a1;
	if(a2) timerDelay = a2;

	no_end = ( a3 ? 1 : 0 );

	if(a4) autoDelay1 = a4*1000;
	if(a5) autoDelay2 = a5*1000;

	var k = 0;

	var str = '';


	 str += '<TABLE ALIGN="left" BORDER="0" CELLSPACING=0 CELLPADDING=0 WIDTH="216" HEIGHT="479"><tr><td>';
	 str += '';
	 str += '<div style="width:20px; width:216px; margin:0; position: relative; display:inline;">';
	 str += '<TABLE ALIGN="left" BORDER="0" CELLSPACING=0 CELLPADDING=0 HEIGHT="20" WIDTH="216" style="postion: relative;"><TR ALIGN="middle" VALIGN="middle"><TD><a href="javascript:ScrollArrow(\'left\',\'scroller\',\'item_1\',1);" ><img src="/images/navleft.jpg" style="border:0" height="21" alt="left scroll arrow" /></a></TD><TD>';
	 str += '<TABLE ID="nav-1" ALIGN="center" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="10" WIDTH="10" style="border:solid 0px #ffb900;; background-color:#ffb900"><TR><TD></TD></TR></TABLE></TD><TD>';
	 str += '<TABLE ID="nav-2" ALIGN="center" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="10" WIDTH="10" style="border:solid 0px #ffb900;; background-color:#ffb900"><TR><TD></TD></TR></TABLE></TD><TD>';
	 str += '<TABLE ID="nav-3" ALIGN="center" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="10" WIDTH="10" style="border:solid 0px #ffb900;; background-color:#ffb900"><TR><TD></TD></TR></TABLE></TD><TD>';
	 str += '<TABLE ID="nav-4" ALIGN="center" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="10" WIDTH="10" style="border:solid 2px #ffb900;"><TR><TD></TD></TR></TABLE></TD><TD>';
	 str += '<TABLE ID="nav-5" ALIGN="center" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="10" WIDTH="10" style="border:solid 2px #ffb900;"><TR><TD></TD></TR></TABLE></TD><TD>';
	 str += '<TABLE ID="nav-6" ALIGN="center" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="10" WIDTH="10" style="border:solid 2px #ffb900;"><TR><TD></TD></TR></TABLE></TD><TD>';
	 str += '<TABLE ID="nav-7" ALIGN="center" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="10" WIDTH="10" style="border:solid 2px #ffb900;"><TR><TD></TD></TR></TABLE></TD><TD>';
	 str += '<TABLE ID="nav-8" ALIGN="center" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="10" WIDTH="10" style="border:solid 2px #ffb900;"><TR><TD></TD></TR></TABLE></TD><TD>';
	 str += '<TABLE ID="nav-9" ALIGN="center" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="10" WIDTH="10" style="border:solid 2px #ffb900;"><TR><TD></TD></TR></TABLE></TD><TD><a href="javascript:ScrollArrow(\'right\',\'scroller\',\'item_1\',1);" ><img src="/images/navright.jpg" style="border:0" height="21" alt="right scroll arrow" /></a></TD></TR></TABLE>';
	 str += '</div>';
	 str += '';
	 str += '</td></tr><tr><td>';

	 str += '<DIV id="frame" style="overflow: hidden; margin: 0 auto; width: 216px; position: relative; display:inline;height:458px;">';
	 str += '<TABLE ALIGN="left" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="216" HEIGHT="458">';

	for (var i = 1; i < 5; i++) {

		var space = ( i == 3 ? '150' : '154' );

		 str += '<TR ALIGN="left" VALIGN="top" style="height:'+space+'px;"><TD>';
		 str += '<DIV id="scroller-'+i+'" style="width: 216px; margin: 0 auto; overflow: hidden;">';
		 str += '<DIV id="content-'+i+'" style="height: 150px; width: 5250px;">';

		for (var j = 1; j < 5; j++) {
			 str += '<DIV id="item_'+j+'-'+i+'" style="width: 216px; margin: 0px; float: left; height: 150px;">';
			 str += content[k++];
			 str += '</DIV>';
		}

		 str += '</DIV>';
		 str += '</DIV>';
		 str += '</TD></TR>';

	}

	 str += '</TABLE>';
	 str += '</DIV>';

	 str += '</td></tr>';
	 str += '</table>';


	document.write(str);

	autoTimer = setTimeout('AutoScrollIt();', autoDelay1);

}


function AutoScrollIt(){

	ScrollArrow('right','scroller','item_1', 0);

	autoTimer = setTimeout('AutoScrollIt();', autoDelay2);

}

function ScrollSection(nextIndex, scrollArea, offset, bool)
{

	// Store the last section, and update the current section

	if (currentIndex == nextIndex) {
		return;
	}
	lastIndex = currentIndex;
	currentIndex = nextIndex;


	for(var i = 1; i < 5; i++){
		// Get the element we want to scroll, get the position of the element to scroll to
		theScroll[i-1] = document.getElementById(scrollArea+'-'+i);
		position = findElementPos(document.getElementById('item_'+(currentIndex+1)+'-'+i));

		// Get the position of the offset div -- the div at the far left.
		// This is the amount we compensate for when scrolling

		if (offset != "") {
			offsetPos = findElementPos(document.getElementById(offset+'-'+i));
			position[0] = position[0] - offsetPos[0];
		}

		if(bool && no_end){
			timer[i-1] = setTimeout('scrollStart('+position[0]+', "horiz", '+(i-1)+', '+lastIndex+', '+currentIndex+');', 0);
		}
		else{
			timer[i-1] = setTimeout('scrollStart('+position[0]+', "horiz", '+(i-1)+', '+lastIndex+', '+currentIndex+');', (i-1)*timerDelay);
		}

		// return false;

	}


}

// Scroll the page using the arrows

function ScrollArrow(direction, scrollArea, offset, clearAuto) {

	if(clearAuto) clearTimeout(autoTimer);

	toolbarNames = new Array('item_1','item_2','item_3','item_4');

	var bool = 0;

	// Now iterate through our array of tab names, find matches, and determine where to go.

	for (var i = 0; i < toolbarNames.length; i++) {
		if (i == currentIndex) {
			if (direction == "left") {
				if (i - 1 < 0) {
					nextIndex = toolbarNames.length - 1;
					bool =1;
				} else {
					nextIndex = i - 1;
				}
			} else {
				if ((i + 1) > (toolbarNames.length - 1)) {
					nextIndex = 0;
					bool =1;
				} else {
					nextIndex = i + 1;
				}
			}
		}
	}
	
	// Go to the section name!
		ScrollSection(nextIndex, scrollArea, offset, bool);

	if(clearAuto) autoTimer = setTimeout('AutoScrollIt();', autoDelay1);

}



// Scroll the page using the arrows

function ScrollArrowSingle(direction, scrollArea, offset, clearAuto, level) {

	if(clearAuto) clearTimeout(autoTimer);

	toolbarNames = new Array('item_1','item_2','item_3','item_4');

	var bool = 0;

	// Now iterate through our array of tab names, find matches, and determine where to go.

	for (var i = 0; i < toolbarNames.length; i++) {
		if (i == currentIndex) {
			if (direction == "left") {
				if (i - 1 < 0) {
					nextIndex = toolbarNames.length - 1;
					bool =1;
				} else {
					nextIndex = i - 1;
				}
			} else {
				if ((i + 1) > (toolbarNames.length - 1)) {
					nextIndex = 0;
					bool =1;
				} else {
					nextIndex = i + 1;
				}
			}
		}
	}
	
	// Go to the section name!
		ScrollLevel(nextIndex, scrollArea, offset, bool, level);

	if(clearAuto) autoTimer = setTimeout('AutoScrollIt();', autoDelay1);

}


//
// Animated Scroll Functions
// Scrolls are synchronous -- only one at a time.
//

var scrollanim = new Array();

scrollanim[0] = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};
scrollanim[1] = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};
scrollanim[2] = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};
scrollanim[3] = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function scrollStart(end, direction, index, startIndex, endIndex)
{

    var navBox1 = 'nav-' + ((startIndex*3)+(index+1));
	//document.getElementById(navBox1).style.backgroundColor = '';
    //document.getElementById(navBox1).style.border = 'solid 2px #669999';

	elem = theScroll[index];
	start = theScroll[index].scrollLeft;



	if (scrollanim[index].timer != null) {
		clearInterval(scrollanim[index].timer);
		scrollanim[index].timer = null;
	}
	scrollanim[index].time = 0;
	scrollanim[index].begin = start;
	scrollanim[index].change = end - start;
	scrollanim[index].duration = 25;
	scrollanim[index].element = elem;
	
	scrollanim[index].timer = setInterval("scrollHorizAnim("+index+","+endIndex+");", timerInterval);
}


function scrollHorizAnim(index, navIndex)
{

	if (scrollanim[index].time > scrollanim[index].duration) {
		clearInterval(scrollanim[index].timer);
		scrollanim[index].timer = null;

		var navBox2 = 'nav-' + ((navIndex*3)+(index+1));
		document.getElementById(navBox2).style.backgroundColor = '#ffb900';
//		document.getElementById(navBox2).style.borderWidth = '0px';
    	document.getElementById(navBox2).style.border = 'solid 0px #669999';
	}
	else {
		move = sineInOut(scrollanim[index].time, scrollanim[index].begin, scrollanim[index].change, scrollanim[index].duration);
		scrollanim[index].element.scrollLeft = move;
		scrollanim[index].time++;
	}
}

// Utility: Find the Y position of an element on a page. Return Y and X as an array

function findElementPos(elemFind)
{
	var elemX = 0;
	var elemY = 0;
	do {
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} while ( elemFind = elemFind.offsetParent )

	return Array(elemX, elemY);
}


function sineInOut(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}


	/* devang script */
function ScrollArrow1(direction, scrollArea, offset, clearAuto, currentIndex) {

	if(clearAuto) clearTimeout(autoTimer);

	toolbarNames = new Array('item_1','item_2','item_3','item_4');

	var bool = 0;

	// Now iterate through our array of tab names, find matches, and determine where to go.

	for (var i = 0; i < toolbarNames.length; i++) {
		if (i == currentIndex) {
			if (direction == "left") {
				if (i - 1 < 0) {
					nextIndex = toolbarNames.length - 1;
					bool =1;
				} else {
					nextIndex = i - 1;
				}
			} else {
				if ((i + 1) > (toolbarNames.length - 1)) {
					nextIndex = 0;
					bool =1;
				} else {
					nextIndex = i + 1;
				}
			}
		}
	}
}
