// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults



function GoBack() {
	
	document.location = document.referrer
}

function ShowHideAndrum(div) {
	
	var connr = document.getElementById('content').getElementsByTagName('div').length;
	var con = document.getElementById('content').getElementsByTagName('div');
	
	for (i=0; i<connr; i++) {
	
			(con)[i].style.display = "none";
	}
	
	new Effect.Appear(div)
}

function MenuAppear(id) {
	
	//alert(id)
	//document.getElementById(id).style.display = 'none'
	StartLoader()
	new Effect.Morph(id, { style: 'color: #FFF;', duration: 0.2})
}

function MenuFade(id) {
	
	//alert(id)
	//document.getElementById(id).style.display = 'none'
	//document.getElementById('dog').style.visibility = 'hidden'
	StopLoader()
	new Effect.Morph(id, { style: 'color: #333;', duration: 0.5})
}

function StartLoader() { 
	
	id = 'loader';
	d = 80;
	var imgnr = document.getElementById(id).getElementsByTagName('img').length;
	var img = document.getElementById(id).getElementsByTagName('img');
	
	if(typeof(c)=="undefined" || c == null){
			c = 0;
			document.getElementById(id).style.display = 'block'
			loadid = id;
		}
			
			for (i=0; i<imgnr; i++) {
				if(img[i].style.display == "block") {
					(img)[i].style.display = "none";
				}
			}
			
		if(c == imgnr){
			c = 0;
		}
		
		(img)[c].style.display = "block";
				
		c = c + 1;
		
		loader = setTimeout(function () { StartLoader(d) },d)
			
}

function StopLoader(){
	clearTimeout(loader)
	c = null;
	document.getElementById(loadid).style.display = 'none'
}



function BrowserDetect() {
	
	var browser = "Unknown"
	
	if(navigator.userAgent.search("Safari") != -1) {
		var browser = "Safari"
	}
	if(navigator.userAgent.search("MSIE") != -1) {
		var browser = "IE"
	}
	if(navigator.userAgent.search("Firefox") != -1) {
		var browser = "Firefox"
	}
	if(navigator.userAgent.search("Camino") != -1) {
		var browser = "Camino"
	}
	if(navigator.userAgent.search("Opera") != -1) {
		var browser = "Opera"
	}
	if(navigator.userAgent.search("iCab") != -1) {
		var browser = "iCab"
	}
	if(navigator.userAgent.search("KDE") != -1) {
		var browser = "KDE"
	}
	
	return browser
	
}

function PlatformDetect() {
	
	var platform = "Unknown"
	
	
	if(navigator.platform.search("Win") != -1) {
		var platform = "Windows"
	}
	if(navigator.platform.search("Mac") != -1) {
		var platform = "Mac"
	}
	if(navigator.platform.search("Linux") != -1) {
		var platform = "Linux"
	}
	
	
	return platform
	
}



function xDocSize()
{
  var b=document.body, e=document.documentElement;
  var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0;
  if (e) {
    esw = e.scrollWidth;
    eow = e.offsetWidth;
    esh = e.scrollHeight;
    eoh = e.offsetHeight;
  }
  if (b) {
    bsw = b.scrollWidth;
    bow = b.offsetWidth;
    bsh = b.scrollHeight;
    boh = b.offsetHeight;
  }
alert('compatMode: ' + document.compatMode + '\n\ndocumentElement.scrollHeight: ' + esh + '\ndocumentElement.offsetHeight: ' + eoh + '\nbody.scrollHeight: ' + bsh + '\nbody.offsetHeight: ' + boh + '\n\ndocumentElement.scrollWidth: ' + esw + '\ndocumentElement.offsetWidth: ' + eow + '\nbody.scrollWidth: ' + bsw + '\nbody.offsetWidth: ' + bow);
  return {w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
}



init = function() {
	
	//window.scrollTo(0,4800)
	//xDocSize()
	//alert(document.body.scrollTop || document.documentElement.scrollTop)
	menu_w = document.getElementById('menu').offsetWidth
	//alert(parseInt(menu_w))
	document.getElementById('top').style.width = menu_w
	morphset = 'no'
	logomorphset = 'no'
}

function RandomColor() {
	
	goToColor = '#B2DEE4'
	var randomnumber = Math.floor(Math.random()*4)
	
	if(randomnumber == 0) {
		//ljusblåturkos
		goToColor = '#B2DEE4'
	}
	if(randomnumber == 1) {
		//ljusgrön
		goToColor = '#99FF33'
	}
	if(randomnumber == 2) {
		//gröngrå
		goToColor = '#666A55'
		document.getElementById('tagline').style.color = '#FFF'
	}
	if(randomnumber == 3) {
		//gul
		goToColor = '#FC0'
	}

	
}

function MorphLeftColumn(){
	
		if(pe <= 10){
			sideMorph.cancel()
			new Effect.Morph('sidecolumn', { style: 'background: #333; color: #333', duration: 1})
		}else{
			sideMorph = new Effect.Morph('sidecolumn', { style: 'background: #000; color: #000', duration: 1})
		}
}

function MorphGradient(){
		
		if(pe <= 1 && logomorphset == 'ok'){
				logofade.cancel()
				logomorphset = 'no'
				new Effect.Appear('logo')
				
			
		} else if (pe > 1 && logomorphset == 'no') {
				logomorphset = 'ok'
				logofade = new Effect.Fade('logo', { duration: 0.5 })
		}
		
		
		if(pe <= 10 && morphset == 'ok'){
				downMorph.cancel()
				morphset = 'no'
				new Effect.Morph('visualcounter', { style: 'color: #FFF', duration: 1})
				//#262424
			
		} else if (pe > 10 && morphset == 'no') {
				morphset = 'ok'
				RandomColor()
				downMorph = new Effect.Morph('visualcounter', { style: 'color:' + goToColor +'', duration: 1})
		}
		
}

DoScrollScript = function() {
	
	
	
	yScroll = document.body.scrollTop || document.documentElement.scrollTop
	yHeight = document.documentElement.scrollHeight

	pe = Math.round(((yScroll / yHeight) * 100))
	
	
	// if(pe > 20) {
	// 		document.getElementById('visualcounter').innerHTML = pe
	// 	}else{
	// 		document.getElementById('visualcounter').innerHTML = "PÅL"
	// 	}

			
	
	if(pe <= 4) {
		document.getElementById('uplink').style.display = 'none'
	}
	else {
		document.getElementById('uplink').style.display = 'block'
	}
	
	//color = document.getElementById('bodygradient').style.backgroundColor
	//document.getElementById('test').innerHTML = color
	
	//MorphGradient()
	
}

window.onload = init;
window.onscroll = DoScrollScript;
