// menu part
function activate(item) {
	document.getElementById(item).style.visibility = 'visible';
}

function deactivate(item) {
	document.getElementById(item).style.visibility = 'hidden';
}

// day/night switcher
var cookiename = 'zorb_time_check';
var current_url = window.location;
current_url = current_url.toString();

function setcookie(value) {
	document.cookie= cookiename + "=" + escape(value) + "; path=/";
}

function getcookie() {
    var dc = document.cookie;
    var prefix = cookiename + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = dc.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function check(timeoftheday) {
	if (getcookie()) return true;
	else {
		setcookie(1);
		checkswitch(timeoftheday);
	}
}

function checkswitch(timeoftheday) {
	time = checktime();
	
	if ((time == 'day') && (timeoftheday == 'night')) {
		switchtimeto('day');
	}
	if ((time == 'night') && (timeoftheday == 'day')) {
		switchtimeto('night');
	}
}

function checktime() {
	var curdate = new Date();
	var hours = curdate.getHours();
	if ((hours >= 9) && (hours < 21)) {
		time = 'day';
	}
	else {
		time = 'night';
	}
	return(time);
}

function switchtimeto(timeoftheday) {
	var check_str_night = '/night';
	var check_str_day = '.html';
	
	if (timeoftheday == 'day') {
		var start = current_url.indexOf(check_str_night);
		var count = new Array();
		count = current_url.split('/');
		
		if (count.length == 4) {
			// index page
			var newurl = current_url.substring(0, start) + '/';
		}
		else {
			// other pages
			var newurl = current_url.substring(0, start) + current_url.substring(start+check_str_night.length, current_url.length);
		}
	}
	
	if (timeoftheday == 'night') {
		var start = current_url.indexOf(check_str_day);
		
		if (start > 0) {
			// index page
			var newurl = current_url.substring(0, start) +  check_str_night + current_url.substring(start, current_url.length);
		}
		else {
			// other pages
			var newurl = current_url.substring(0, current_url.length-1) + check_str_night + check_str_day;
		}
	}
	window.location = newurl;
}