var images = "";							// To load list elements from ul#images (automatically)
var messages = "";						// To load list elements from ul#messages (automatically)
var buttons = "";							// To load list elements from ul#buttons (automatically)
var imgNumber = 0;						// Number of images will be stored here (automatically)
var Index = 0;								// Current shown image will be stored here (automatically)
var AppearValue = 2.0;				// Value (in seconds) how long appearing time (load) of an image has to be
var AppearValueMsg = 0.5;			// Value (in seconds) how long appearing time (load) of a message has to be
var FadeValue = 0.5;					// Value (in seconds) how long fading time (unload) of an image has to be			
var TimerValue = 5000;				// Rotating time (in miliseconds, 1000 = 1 sec)
var imgControl = "";					// Handles rotating time
var msgControl = "";					// Handles rotating time
var visibleButtons = 4;				// Number of buttons visible at one time
var timer = null;							// Needed for manual scrolling
var scrolling = null;					// Needed for automatic srolling


/* Start animation */
function Rotate(){
	// Reset Index
	Index = 0;
	
	// Fetch elements
	images = document.getElementById('images').getElementsByTagName('li');
	messages = document.getElementById('messages').getElementsByTagName('li');
	buttons = document.getElementById('buttons').getElementsByTagName('li');
	
	// Hide all images
	for(i=0; i<images.length; i++){
		images[i].style.display = "none";
		messages[i].style.display = "none";
	}
	
	// Set number of images
	imgNumber = images.length;
	
	// Start rotation
	Show_Next();
}


function Show_Msg(){
	if (navigator.appName.indexOf("Internet Explorer") != -1){
		document.getElementById('message'+Index).style.display = "";		
	}else{
		Effect.Appear('message'+Index, { duration: AppearValueMsg });	
	}
	Effect.Appear('msg'+Index, { duration: AppearValueMsg });
}


/* Show next button and image */
function Show_Next(){
	
	switch(Index){
		case 0:
			// Show first image and start rotation by time control
			Index = (Index+1);
			// activeate button
			ChangeBtnClass('button'+Index,"active");
			// load image
			Effect.Appear('image'+Index, { duration: AppearValue });
			// show message
			msgControl = setTimeout("Show_Msg()", 1000);
			// goto next element
			imgControl = setTimeout("Show_Next()", TimerValue);
			break;
			
		case images.length:
			// Return to first image
			scroll_top();
			// disable button
			ChangeBtnClass('button'+Index,"");
			// onload image
			Effect.Fade('image'+Index, { duration: FadeValue });
			// unload message
			Effect.Fade('msg'+Index, { duration: FadeValue });
			// unload message bar
			if (navigator.appName.indexOf("Internet Explorer") != -1) {
	  		document.getElementById('message' + Index).style.display = "none";
	  	}else{
				Effect.Fade('message'+Index, { duration: FadeValue });
			}
			// reset index
			Index = 0;
			// goto first element
			Show_Next();
			break;
			
		default:
			// Show next image
			ChangeBtnClass('button'+Index,"");
			// unload image
			Effect.Fade('image'+Index, { duration: FadeValue });
			// unload message
			Effect.Fade('msg'+Index, { duration: FadeValue });
			// unload message bar
			if (navigator.appName.indexOf("Internet Explorer") != -1) {
	  		document.getElementById('message' + Index).style.display = "none";
	  	}else{
				Effect.Fade('message'+Index, { duration: FadeValue });
			}
			// scroll to next button
			Index = (Index+1);
			if(Index > visibleButtons){
				scroll_down();
			}
			// activate next button
			ChangeBtnClass('button'+Index,"active");
			Effect.Appear('image'+Index, { duration: AppearValue });
			// show message
			msgControl = setTimeout("Show_Msg()", 1000);
			// goto next element
			imgControl = setTimeout("Show_Next()", TimerValue);
	}
}


/* Stop animation */
function Stop(){
	clearTimeout(imgControl);
}


/* Resume animation */
function Resume(){
	imgControl = setTimeout("Show_Next()", TimerValue);
}


/* Change css class of a button to display active one */
function ChangeBtnClass(ID,Class){
	var btn = document.getElementById(ID);
	btn.setAttribute("class", Class);
	btn.setAttribute("className", Class); 
}


/* Handler for mouseover effect on a button */
function HoverButton(ID){
	Stop();
	
	switch(ID){
		case Index:
			// Button on mouse is the active one -> do nothing
			break;
			
		default:
			// Show hovered button and image
			ChangeBtnClass('button'+Index,"");
			//Effect.Fade('image'+Index);
			document.getElementById('image'+Index).style.display = "none";
			document.getElementById('message'+Index).style.display = "none";
			document.getElementById('msg'+Index).style.display = "none";
			Index = ID;
			ChangeBtnClass('button'+ID,"active");
			//Effect.Appear('image'+ID);
			document.getElementById('image'+Index).style.display = "";
			document.getElementById('message'+Index).style.display = "";
			document.getElementById('msg'+Index).style.display = "";
	}
}


/* Button scrolling handler */
var scrollCount = 10;
function scroll_up() {
    var d = document.getElementById('buttons');

    d.scrollTop = d.scrollTop - 10;
		
		if(scrollCount == 60){
			scrollCount = 10;
		}else{
			scrollCount = (scrollCount + 10)
			scrolling = window.setTimeout(function() {
        scroll_up();
    	}, 100);	
		}
}

function scroll_down() {
    var d = document.getElementById('buttons');
		
    d.scrollTop = d.scrollTop + 10;

    if(scrollCount == 60){
			scrollCount = 10;
		}else{
			scrollCount = (scrollCount + 10)
			scrolling = window.setTimeout(function() {
        scroll_down();
    	}, 100);	
		}
		
}

function scroll_top() {
    var d = document.getElementById('buttons');

    d.scrollTop = 0;
}

function stop_scroll() {
    window.clearTimeout(scrolling);
}


function Scroll(action){
	var t = document.getElementById('buttons');
	
	switch(action){
		case "Up":
			t.scrollTop = t.scrollTop - 10;
			timer = window.setTimeout(function() {
        Scroll(action);
    	}, 100);
			break;
			
		case "Down":
			t.scrollTop = t.scrollTop + 10;
			timer = window.setTimeout(function() {
        Scroll(action);
    	}, 100);
			break;
			
		case "Stop":
			window.clearTimeout(timer);
			break;
			
		default:
		
	}
}


function LoadSingleBanner(){
	var banner_text = document.getElementById('banner_text');
	
	/* show banner */
	Effect.Appear('banner', { duration: AppearValue });
	
	if(banner_text){
		bannerControl = setTimeout("LoadSingleText()", 1000);
	}		
	
}

function LoadSingleText(){
	if (navigator.appName.indexOf("Internet Explorer") != -1){
		document.getElementById('banner_text').style.display = "";		
	}else{
		Effect.Appear('banner_text', { duration: AppearValueMsg });	
	}
	Effect.Appear('text', { duration: AppearValueMsg });
}