/* --------------------------------------------------- 
CARIRAN Redesign Script Library
	- Image box functions
	- Banner changer function
--------------------------------------------------- */

var curr_item = 1;
addLoadEvent(start_box_timer);

//Menu Definetion
var curr_menu = -1;

//We have to start timer
function start_box_timer(){
	setInterval("next_box_item()",5000);	
}

//Best Box Functions
function next_box_item(){
	if(curr_item >= 5){
		curr_item = 1;	
	}
	else{
		curr_item++;	
	}
	
	change_item();
}

function previous_box_item(){
	if(curr_item <= 1){
		curr_item = 5;	
	}
	else{
		curr_item--;	
	}
	
	change_item();
}

function change_item(){
	for(var i=1; i <= 5; i++){
		document.getElementById('best_image_' + i).style.display = "none";
		document.getElementById('best_description_' + i).style.display = "none";
		document.getElementById('best_title_' + i).style.display = "none";
		document.getElementById("best_curr_" + i).src = root_dir + "images/best_current_deactive.gif";
	}
	
	document.getElementById("best_image_" + curr_item).style.display = "block";
	document.getElementById('best_description_' + curr_item).style.display = "block";
	document.getElementById('best_title_' + curr_item).style.display = "block";
	document.getElementById("best_curr_" + curr_item).src = root_dir + "images/best_current_active.gif";
}

function banner_select(){
	var today = new Date();
	var day = today.getDay();
	
	if(day > 6){
		day = 1;	
	}
	
	var page_body = document.getElementsByTagName("body");
	page_body[0].style.background = "url('" + root_dir + "backgrounds/" + day + ".jpg') top center no-repeat #fff";
}

// Menu Functions
function menu(ind,e){
	if(curr_menu){
		for(var i=1; i <= 3; i++){
			document.getElementById('sub_menu_' + i).style.display = "none";
			document.getElementById('sub_menu_link_' + i).className= "";
		}
	}
	
	if(ind != curr_menu && ind != -1){
		document.getElementById('sub_menu_' + ind).style.display = "block";
		e = e || window.event;
		t = e.target || e.srcElement;
		t.className = 'menu_active';
		curr_menu = ind;
	}
	else{
		curr_menu = -1;	
	}
}

// Public Functions

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}