isLoaded=0

pageMinW=785
pageMinH=555

pageMaxW=1100
pageMaxH=778

pageRatio=1.414
pageActualWidth=785

borderW=1 // how big is the dotted page border?
menuVisible=0;

isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
isSafari= (navigator.userAgent.toLowerCase().indexOf("safari") != -1) ? 1:0;

function newsletterOK() {
	obj=getObj('thenewsletter')
	obj.innerHTML='<span class="headline">Thank you, you have been added to our newsletter.</span>'	
}

function newsletterBAD() {
	obj=getObj('thenewsletter')
	obj.innerHTML='<span class="headline">There has been a problem with the newsletter.<br>Please try later again.</span>'	
}

function resizeText() {
	if (!document.styleSheets) return;
	var theRules = new Array();
	if (document.styleSheets[0].cssRules)
		theRules = document.styleSheets[0].cssRules
	else if (document.styleSheets[0].rules)
		theRules = document.styleSheets[0].rules
	else return;
	
	txtsize=pageActualWidth/33
	lH=Math.round(txtsize*0.85) // line height
	
	// .headline
	theRules[0].style.fontSize=txtsize+"px"
	theRules[0].style.lineHeight=lH+"px"
	
	// .nexttext
	theRules[15].style.fontSize=txtsize+"px"
	theRules[15].style.lineHeight=lH+"px"
	
	// .archiveblue
	theRules[11].style.fontSize=txtsize+"px"
	theRules[11].style.lineHeight=lH+"px"
	
	// .archiveblack
	theRules[12].style.fontSize=txtsize+"px"
	theRules[12].style.lineHeight=lH+"px"
	
	
	// .headlinethin
	theRules[1].style.fontSize=txtsize+"px"
	theRules[1].style.lineHeight=lH+"px"
	
	// INPUT.newslett
	theRules[17].style.fontSize=txtsize+"px"
	
	// a.menu
	theRules[3].style.fontSize=txtsize+"px"
	
	// a.mediumlink
	txtsize2=Math.round(txtsize*0.50)
	lH2=Math.round(txtsize2*1.1)
	theRules[4].style.fontSize=txtsize2+"px"
	theRules[4].style.lineHeight=lH2+"px"
	
	// .addedtomag
	theRules[16].style.fontSize=txtsize2+"px"
	theRules[16].style.lineHeight=lH2+"px"
	
	// .submenuactive
	theRules[5].style.fontSize=txtsize2+"px"
	theRules[5].style.lineHeight=lH2+"px"
	
	// .titletext
	theRules[6].style.fontSize=txtsize2+"px"
	//theRules[6].style.lineHeight=lH2+"px"
	
	// .prevnext
	txtsize=pageActualWidth/45
	lH=Math.round(txtsize*0.85) // line height
	theRules[7].style.fontSize=txtsize+"px"
	theRules[7].style.lineHeight=lH+"px"
	
	// .headlinesmaller
	theRules[10].style.fontSize=txtsize+"px"
	lH=Math.round(txtsize*0.93) // line height
	theRules[10].style.lineHeight=lH+"px"
	
	// magazinetext
	theRules[14].style.fontSize=txtsize+"px"
	lH=Math.round(txtsize*0.93) // line height
	theRules[14].style.lineHeight=lH+"px"
	
	// .normaltext
	txtsize=pageActualWidth/75
	if (txtsize>14) {
		txtsize=14
	}
	theRules[8].style.fontSize=txtsize+"px"
	
	// .smalllink
	theRules[9].style.fontSize=txtsize+"px"
	
	// magazine pages // width:297px; height:210
	mgzW=pageActualWidth/3.8
	mgzH=(210/297)*mgzW
	theRules[13].style.width=mgzW+"px"
	theRules[13].style.height=mgzH+"px"
	
	
}


function getObj(name){
	if(document.getElementById){
		return document.getElementById(name);
	}else if(document.all){
		return document.all[name];
	}
}

function getStyle(name){
	return getObj(name).style;
}

function winW() {
	if (document.all) {
		return document.body.offsetWidth
	} else {
		return window.innerWidth
	}
}

function winH() {
	if (window.innerWidth) {
		  return window.innerHeight;
	} else if (document.documentElement && document.documentElement.offsetHeight) {
		return document.documentElement.offsetHeight
	} else if (document.body) {
		  return document.body.offsetHeight
	}
}

function makeTextVisible() {
	// makes accompaining text visible when the related picture is loaded
	obj=getStyle('picTitle')
	obj.visibility="visible"
	
}


function resizeAll() {
	if (isLoaded) {
		h=winH()-10
		
	
		// calculate width // 30 is offset from above // 
		w=Math.round((h-30)*pageRatio)
			
		if (w>=pageMinW) {
			// adjust red bar
			obj=getStyle('redbar')
			obj.width=(w+borderW)+"px"
			
			// adjust page
			obj=getStyle('page')
			obj.width=w+"px"
			obj.height=(h-30)+"px"
			
			// adjust menu
			obj=getStyle('menu')
			obj.width=(w+borderW)+"px"
			obj.height=(h-30+borderW)+"px"
			
			// adjust click background
			obj=getStyle('bg')
			obj.width=(winW())+"px"
			obj.height=(winH()-15)+"px"
			
			pageActualWidth=w
			
		}
		
		centerAll()
		resizeText()
		
		loadImages() // load images into page if there are some
	}
}

function swapImg(i, newImg) {
	if(document.images) {
		obj = eval('document.'+i);
		obj.src = newImg;
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


function centerAll() {
	if (isLoaded) {
		
		w=winW()
		if (w>800) {
			leftO=Math.round((w-pageActualWidth)/2)
		} else {
			leftO=5
		}
		
		obj=getStyle('redbar')
		obj.left=leftO+"px"
		
		obj=getStyle('menu')
		obj.left=leftO+"px"
		
		obj=getStyle('page')
		obj.left=leftO+"px"
		
		
	}	
	
}

menuTimer=0; // timeout for menu
menuTimerObj="";
menuTimerObj2="";

function extendMenuTime() {
}

function showMenuSoon() {
	menuTimerObj=setTimeout("showMenu()", 250);	
}

function clearMenuSoon() {
	clearTimeout(menuTimerObj)
}

function hideMenuSoon() {
	menuTimerObj2=setTimeout("hideMenu()", 350);	
}

function clearHideMenuSoon() {
	clearTimeout(menuTimerObj2)
}

function showNextText() {
	obj=getObj('theLine2')
	obj.innerHTML=nextText
}

function showMenu() {
	menuVisible=1
	obj=getStyle('menu')
	obj.visibility='visible'
	if (hasFlash && isSafari) {
		// hide the movie, bug in safari
		if (flashdata=="") {
			flashdata = document.getElementById("flashcontent").innerHTML;
		}
		document.getElementById("flashcontent").innerHTML = "";
	}
}

function switchMenu() {
	if (menuVisible) {
		hideMenu()
	} else {
		showMenu()
	}
}


function hideMenu() {
	clearTimeout(menuTimerObj)
	if (menuVisible) {
		menuVisible=0
		obj=getStyle('menu')
		obj.visibility='hidden'
		if (hasFlash && isSafari) {
			document.getElementById("flashcontent").innerHTML = flashdata;
		}
	}
}


function noSpam(who,domain) {
	str = "mailto:" + who + "@" + domain;
	window.location = str;
}


function getNewsletter() {
	if (noShit()) {
		document.newsletter.submit();
	}
}

function noShit() {
	var ok = false;
	if (document.newsletter.absender.value.indexOf("@") == -1 || document.newsletter.absender.value.indexOf(".") == -1)
	{
		document.newsletter.absender.value="NO TRASH PLEASE.";
	}
	else
	{
		ok = true;
	}
	return ok;
}

