var is_chrome = false, chrome_version = false;
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
       is_chrome = true;
       chrome_version = navigator.userAgent.replace(/^.*Chrome\/([\d\.]+).*$/i, '$1')
}

function absPosition(obj) {
	var x = 0
	while(obj) {
		x += obj.offsetLeft
		obj = obj.offsetParent
	}
	return x;
}

function setMenuPosition(margin){
	var ul = document.getElementById('nav')
	if (margin == 0) {
		ul.style.background = "left bottom url('fileadmin/template/images/top_menu_second_1.jpg') no-repeat"
	}
	else if (margin == 79) {
		ul.style.background = "left bottom url('fileadmin/template/images/top_menu_second_2e.jpg') no-repeat"
	}
	else if (margin == 80) {
		ul.style.background = "left bottom url('fileadmin/template/images/top_menu_second_2g.jpg') no-repeat"
	}
	else if (margin == 180) {
		ul.style.background = "left bottom url('fileadmin/template/images/top_menu_second_3e.jpg') no-repeat"
	}
	else if (margin == 214) {
		ul.style.background = "left bottom url('fileadmin/template/images/top_menu_second_3g.jpg') no-repeat"
	}
	else {
		ul.style.background = "left bottom url('fileadmin/template/images/top_menu_second_1.jpg') no-repeat"
	}
	ul.style.marginLeft = margin
	if (is_chrome) {
		ul.style.marginTop = 2
	}
	ul.style.display = "block"
}

function calculateMenuMargin() {
	setTimeout("calculateMenuMarginWithoutDelay()",500)
}

function calculateMenuMarginWithoutDelay() {
	var firstItem = document.getElementById('menu_1')
	var activeItem = document.getElementById('active')
	var left1 = absPosition(firstItem)
	var left2 = absPosition(activeItem)

	var margin = left2 - left1;
	setMenuPosition(margin);
}

function checkSelected() {
	setTimeout("checkSelectedWithoutDelay()",500)
}

function checkSelectedWithoutDelay() {
	var reffer = new String(document.referrer);
	var current = new String(document.location);

//	var ids = "";
//	ids = get_url_param(current, 'ids');

	var mp = get_url_param(reffer, 'MP');

	var platformID = "";
	
	if (mp) {
		var mpp = mp.split("-");
		platformID = mpp[1];
	}
	else {
		var id = get_url_param(reffer, 'id');
		var platform = getPlatfom(id);
		if (platform) {
			platformID = id;
		}
	}
	
//	if (ids){
//		platformID = ids;
//	}

	if (platformID) {
		var boldOn = document.getElementById('selected');
		if (!boldOn) {
		
			var links = document.getElementsByTagName("a");
			for (var i=0; i<links.length;i++) {
				var h = links[i].href;
				var platformIndex = h.indexOf("id=" + platformID);
				if (platformIndex >= 0) {
				// bold
//					if (!ids) {
//					addGetParametrs ('&ids='+platformID);
//					}
					var aParent = links[i].parentNode.className;
					if (aParent=="first" || aParent=="middle" || aParent=="final"){
					links[i].style.fontWeight = "bold";
					}
				}
			}
		}
	}
}

function get_url_param(url, name)
{  
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
var regexS = "[\\?&]"+name+"=([^&#]*)";  
var regex = new RegExp( regexS );  
var results = regex.exec( url );  
if( results == null )    return "";  
else return results[1];
}

function getPlatfom (id)
{
 if (id==5 || id==6 || id==7 || id==8){return id;}
 else {return "";}
}

//function addGetParametrs(addon) {
//  window.location.search += addon;
//}

