var url = window.location.href;
var sf = (url.indexOf("server-asp")>-1) ? "www.clickus.it/" : "";
var page_name = url.substring(url.lastIndexOf('/') + 1);

window.onload = function() {
	var menus = new Array("menu");
	for (var n=0; n<menus.length; n++) {
		var menu = menus[n];
		if ($(menu)) {
			var tags = $(menu).getElementsByTagName("img");
			for (var i = 0; i <  tags.length  ; i++) {
				if (tags[i].className != "current" ) {
					tags[i].onmouseover = function() {
						thisId = this.id;
						//thisIdR = thisId.replace("menu_", "")
						var source = $(thisId).src;
						source = source.replace(".jpg", "_on.jpg");
						$(thisId).src = source;
					}
					tags[i].onmouseout = function() {
						thisId = this.id;
						var source = $(thisId).src;
						source = source.replace("_on.jpg", ".jpg");
						$(thisId).src = source;
					}
				}
			}
		}
	}
	if (document.getElementById("newsBox")) {
		slideNews();
	}
	swfs();
	
	$$('.flash_header').each(function(element) {
		var id = element.id.replace("header_", "");
		//alert(id);
		//element.hide();
		var params = {wmode: "transparent"};
		swfobject.embedSWF("/" + sf + "swf/" + id + ".swf", "header_" + id, "682", "147", "9.0.0", false, {}, params);
	});
}

function swfs() {
	if ($("photoflow")) {
		//alert(sf);
		//var flashvars = {XMLFile: "swf/photoflow/gallery.xml"};
		var flashvars = {XMLFile: "xml.asp"};
		var params = {wmode: "transparent"};
		swfobject.embedSWF("/" + sf + "swf/photoflow.swf", "photoflow", "682", "199", "9.0.0", false, flashvars, params);
	}
	
	if($("flash_portfolio")) {
		//var params = {wmode: "transparent"};
		 var params = {scale: "noscale", allowFullScreen: "true"};
		//swfobject.embedSWF("/" + sf + "swf/gallery.swf", "flash_portfolio", "680", "380", "9.0.0", false, {}, params); //tn2
		swfobject.embedSWF("/" + sf + "swf/gallery.swf", "flash_portfolio", "680", "700", "9.0.0", false, {}, params);
		
	}
	
}

startTop = 140;
startId = 0;
nextId = 1;
delay = 6000;

function slideNews() {
	nextId = startId + 1;
	if (startId == 5) {
		nextId = 1;	
	}
	if (startId == 6) {
		startId = 1
		nextId = 2;	
	}
	/*for (n = 1; n <=5; n++) {
		document.getElementById("news_" + n).style.zIndex = "1";
	}
	document.getElementById("news_" + startId).style.zIndex = "2";*/
	for (n = 1; n <=5; n++) {
		if (document.getElementById("news_" + n)) {
			document.getElementById("news_" + n).style.display = "none";
		}
	}
	if (document.getElementById("news_" + nextId)) {
		document.getElementById("news_" + nextId).style.top = startTop + "px";
		document.getElementById("news_" + nextId).style.display = "block";
	}
	slideBox();
}

function slideBox() {
	startTop = startTop-5;
	if (document.getElementById("news_" + nextId)) {
		document.getElementById("news_" + nextId).style.top = startTop + "px";
		slideTimer = setTimeout("slideBox()", 10);
	} else {
		startTop = 140;
		startId++;
		setTimeout("slideNews()", 0);
	}
	if (startTop == 0) {
		clearTimeout(slideTimer);
		startTop = 140;
		startId++;
		setTimeout("slideNews()", delay);
	}
}
