
var currentPanel = 1;
var scrollPanel;
var scrollDuration = 0.5;
var scrollPanelWidth = 768;

function initHomeScroll() {

	scrollPanel = new Tween(document.getElementById("scrollbar_content").style,'left',Tween.regularEaseInOut,0,0,scrollDuration,'px');
	
	var leftButton = document.getElementById("scrollbar_leftButton");
	if (leftButton != null) {
		leftButton.onclick = function() {
			currentPanel--;
			if (currentPanel == 0) currentPanel = 3;
			scrollbarShowPanel();
		};
	}

	var rightButton = document.getElementById("scrollbar_rightButton");
	if (rightButton != null) {
		rightButton.onclick = function() {
			currentPanel++;
			if (currentPanel == 4) currentPanel = 1;
			scrollbarShowPanel();
		};
	}

	var button1 = document.getElementById("scrollbar_selectButton1");
	if (button1 != null) {
		button1.onclick = function() {
			scrollbarShowPanel1();
		};
	}
	
	var button2 = document.getElementById("scrollbar_selectButton2");
	if (button2 != null) {
		button2.onclick = function() {
			scrollbarShowPanel2();
		};
	}
	
	var button3 = document.getElementById("scrollbar_selectButton3");
	if (button3 != null) {
		button3.onclick = function() {
			scrollbarShowPanel3();
		};
	}

}

function scrollbarShowPanel() {
	if (currentPanel == 1) scrollbarShowPanel1();
	if (currentPanel == 2) scrollbarShowPanel2();
	if (currentPanel == 3) scrollbarShowPanel3();
}

function scrollbarShowPanel1() {
	
	var selectButton1 = document.getElementById("scrollbar_selectButton1_img");
	var selectButton2 = document.getElementById("scrollbar_selectButton2_img");
	var selectButton3 = document.getElementById("scrollbar_selectButton3_img");
	
	if (selectButton1 != null) selectButton1.src="/images_m/scrollSelected.png";
	if (selectButton2 != null) selectButton2.src="/images_m/scrollUnselected.png";
	if (selectButton3 != null) selectButton3.src="/images_m/scrollUnselected.png";
	
	scrollPanel.continueTo(0,scrollDuration);
	currentPanel = 1;
}

function scrollbarShowPanel2() {

	var selectButton1 = document.getElementById("scrollbar_selectButton1_img");
	var selectButton2 = document.getElementById("scrollbar_selectButton2_img");
	var selectButton3 = document.getElementById("scrollbar_selectButton3_img");
	
	if (selectButton1 != null) selectButton1.src="/images_m/scrollUnselected.png";
	if (selectButton2 != null) selectButton2.src="/images_m/scrollSelected.png";
	if (selectButton3 != null) selectButton3.src="/images_m/scrollUnselected.png";
	
	scrollPanel.continueTo(0-scrollPanelWidth,scrollDuration);
	currentPanel = 2;
}

function scrollbarShowPanel3() {

	var selectButton1 = document.getElementById("scrollbar_selectButton1_img");
	var selectButton2 = document.getElementById("scrollbar_selectButton2_img");
	var selectButton3 = document.getElementById("scrollbar_selectButton3_img");
	
	if (selectButton1 != null) selectButton1.src="/images_m/scrollUnselected.png";
	if (selectButton2 != null) selectButton2.src="/images_m/scrollUnselected.png";
	if (selectButton3 != null) selectButton3.src="/images_m/scrollSelected.png";
	
	scrollPanel.continueTo(0-(scrollPanelWidth*2),scrollDuration);
	
	currentPanel = 3;
}

//set onload func
if (window.addEventListener) window.addEventListener("load",initHomeScroll,false);
else if (window.attachEvent) window.attachEvent("onload",initHomeScroll);
else window.onload = initHomeScroll;

