var contentWidth = 884;
var minWinWidth = 904;

var staticLinksCount = 9; //anzahl links vor/ober der 2. navi-ebene

var myImages = new Array();

var suffix = "";

function calculateLeftmargin() {
	if(window.innerWidth) {
		width = window.innerWidth;		
	}
	else if(document.body) {
		width = document.body.offsetWidth;
	}
	
	if(width < minWinWidth) {
		width = minWinWidth;
	}
	leftmargin = (width-contentWidth)/2;		
	leftmargin -= 10; //scrollbar	
	return(leftmargin);
}

function setLeftmargin() {
	leftMargin = calculateLeftmargin();
	document.getElementById("mainbox").style.marginLeft = leftMargin+"px";
	document.getElementById("mainbox").style.display = "";
}


function getStyle(x, stylePropFF, stylePropIE) {
	if (x.currentStyle)
		var y = x.currentStyle[stylePropIE];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(stylePropFF);
	return y;
}

//act: wenn navigationspunkt aktiv ist (subnavi aufgelappt)
function naviOver(theElement,act) {
	bgImg = getStyle(theElement, "background-image", "backgroundImage");			// !!
	newBgImg = bgImg.replace(/0\.gif/g,"1.gif")
	theElement.style.backgroundImage = newBgImg;
}

function naviOut(theElement,act) {
	bgImg = getStyle(theElement, "background-image", "backgroundImage");
	newBgImg = bgImg.replace(/1\.gif/g,"0.gif")
	theElement.style.backgroundImage = newBgImg
}


//bottop: 1: wenn navi-punkt direkt ober einem navi-punkt mit aktiviertem rahmen;
//bottop: 2: wenn navi-punkt direkt unter einem navi-punkt mit aktiviertem rahmen;
//bottop: 3: wenn navi-punkt zwischen zwei navi-punkten mit aktiviertem rahmen;
function navi2over(theElement,bottop) {
	//theElement = document.getElementById('navi2_'+i);	
	theElement.style.backgroundColor = '#171717';
	if(theElement.childNodes[1]) {
		theElement.childNodes[1].firstChild.style.color = "#ffffff";
	}
	else {
		//alert(theElement.childNodes[0].firstChild.tagName);
		theElement.childNodes[0].firstChild.style.color = "#ffffff";	// IE DOM
	}
}

function navi2out(theElement) {
	//theElement = document.getElementById('navi2_'+i);
	theElement.style.backgroundColor = '#ececec';
	//alert(theElement.childNodes[1].firstChild);
	if(theElement.childNodes[1]) {
		theElement.childNodes[1].firstChild.style.color = "#333";		
	}
	else {
		theElement.childNodes[0].firstChild.style.color = "#333";	// IE
	}
}


function navigate(url) {
	window.location.href = url;
}

function resizeImprBox() {	
	document.getElementById("imprboxinner").style.width = totImprWidth;
}

function nav2active(p) {
	for(i=1; i<document.links.length-staticLinksCount; i++) {
		if(i==p) {
			linkClass = document.links[i+staticLinksCount].className;
			linkClass = linkClass.substr(0,5);			
			if(linkClass == "navi2") {
				document.links[i+staticLinksCount].style.color = "e54320";
				break;
			}
		}
	}
}

function preloadImages() {
    for (i=0;i<preloadImages.arguments.length;i++) {
        myImages[i] = new Image();
        myImages[i].src = preloadImages.arguments[i];
    }
}

function bigImpr(filename) {
    imgWindow = window.open("bigimg.php?filename="+filename,"bigImgWin","width=20,height=20,top=50,left=100,scrollbars=no");
    imgWindow.focus();
}

function newsDetails(reference,lang) {
	referenceArray = reference.split("=");
	id = referenceArray[1];
	details = window.open("newsdetails.php?id="+id+"&lang="+lang,"newsDetailWin","width=500,height=330,top=50,left=100,scrollbars=yes");
    details.focus();
}

function referenzDetails(reference,lang) {
	referenceArray = reference.split("=");
	id = referenceArray[1];
	details = window.open("refdetails.php?id="+id+"&lang="+lang,"newsDetailWin","width=650,height=450,top=50,left=100,scrollbars=yes");
    details.focus();
}

function openDisclaimer() {
	disclaimer = window.open("disclaimer.html","disclWin","width=650,height=450,top=50,left=100,scrollbars=yes");
    disclaimer.focus();
}

function popNewsletter(inout) {
	address = document.forms["optinout"].elements[0].value;
	if(address && (address!="Ihre eMail-Adresse")) {
		var url = "http://letters.popletter.com/cosmosgolf/optinout.php?inOut="+inout+"&address="+address;
		window.open(url,"optWin","width=300,height=180,top=50,left=100,scrollbars=no");
	}
	else {
		alert("Bitte geben Sie eine Adresse ein.");
	}
}

//NEWS:
function news(nr) {
    window.open("../news.php?nr="+nr,"news_win","width=350,height=250,top=50,left=100,scrollbars=yes");
}

//EVENTS:
function openEvent(id) {
    detailWindow = window.open("popEvents/event_details.php?elementID="+id,"eventWin","width=524,height=315,top=50,left=100,scrollbars=yes");
    detailWindow.focus();
}

function openImg(w,h,source) {
	disclaimer = window.open(source,"disclWin","width="+w+",height="+h+",top=0,left=100,scrollbars=yes");
    disclaimer.focus();
}


//MAGNA SWEETS:
function openMagna() {
	msgwindow=window.open('http://www.promotionsweets.de/de/index.php?customer=CosmosGolf','Popupfenster','toolbar=no,width=800,height=600,status=no,scrollbars=yes,resizable=yes,menubar=no');
	msgwindow.focus();
}

//ROEMER PRAESENTIDEEN:
function openPraesent() {
	msgwindow=window.open('http://www.promotionsweets.de/de/index.php?customer=CosmosGolf','Popupfenster','toolbar=no,width=800,height=600,status=no,scrollbars=yes,resizable=yes,menubar=no');
	msgwindow.focus();
}


//ROEMER PRAESENTIDEEN:
function openWellness() {
	msgwindow=window.open('http://www.promotionsweets.de/de/index.php?customer=CosmosGolf','Popupfenster','toolbar=no,width=800,height=600,status=no,scrollbars=yes,resizable=yes,menubar=no');
	msgwindow.focus();
}