function getCookie(c_name) {
if (document.cookie.length>0) {
 c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1) { 
   c_start=c_start + c_name.length+1; 
   c_end=document.cookie.indexOf(";",c_start);
   if (c_end==-1) c_end=document.cookie.length;
   return unescape(document.cookie.substring(c_start,c_end));
  } 
 }
 return "off";
}

function linker() {
 var links = document.getElementsByTagName('A')
 for (var i=0; i<links.length; i++) {links[i].target = '_blank'}
}

var time=getCookie('time')
var weather=getCookie('weather')
var map=getCookie('map')
var skin=getCookie('skin')
var icon=getCookie('icon')
var zoom=getCookie('zoom')

function widgets () {
 if (time=="on") {
	 document.getElementById('time').src="time.html"
	 document.getElementById('time').style.display="inline"
	}
 if (weather=="on") {
	 document.getElementById('weather').src="weather.html"
	 document.getElementById('weather').style.display="inline"
	}
 if (map=="on") {
	 document.getElementById('map').src="map.html"
	 document.getElementById('map').style.display="inline"
	}
 if (skin!="Onyx" && skin!="off") {theme(skin);divWhite();document.getElementById('body').style.color='black'}
 if (skin=="Vista") {document.getElementById('body').style.color='#069'}
 if (icon=="42") {toolbar(42)}
 if (icon=="10") {toolbar(10)}
 if (zoom=="on") {zoomIn()}
}

z=0
function zoomIn() {
 if (z==0) {document.cookie="zoom=on; expires=Thu, 2 Aug 2012 20:47:11 UTC"}
 if (z==2) {document.getElementById('bg1').style.fontSize="13px"}
 if (z==4) {document.getElementById('bg1').style.fontSize="14px"} 
 if (z<6) {
  document.getElementById('div2').style.height=(180+(z*4))+"px"
  document.getElementById('div5').style.height=(180+(z*4))+"px"
  document.getElementById('sdiv').style.marginTop=(154+(z*7))+"px"
  document.getElementById('shdiv').style.marginTop=(154+(z*7))+"px"
  for (var i=2;i<4;i++) {document.getElementById('bg'+i).style.height=(135+(z*7))+"px"}
  document.getElementById('bg1').style.height=(550+(z*8))+"px"
  z+=1
  setTimeout(function(){zoomIn()},0)  
 }
}

function zoomOut() {
 if (z==0) {document.cookie="zoom=off; expires=Thu, 2 Aug 2012 20:47:11 UTC"}
 if (z==2) {document.getElementById('bg1').style.fontSize="12px"}
 if (z==4) {document.getElementById('bg1').style.fontSize="13px"} 
 if (z>-1) {
  document.getElementById('div2').style.height=(180+(z*4))+"px"
  document.getElementById('div5').style.height=(180+(z*4))+"px"
  document.getElementById('sdiv').style.marginTop=(154+(z*7))+"px"
  document.getElementById('shdiv').style.marginTop=(154+(z*7))+"px"
  for (var i=2;i<4;i++) {document.getElementById('bg'+i).style.height=(135+(z*7))+"px"}
  document.getElementById('bg1').style.height=(550+(z*8))+"px"
  z-=1
  setTimeout(function(){zoomOut()},0)  
 }
}

function toggleTime () {
 if (time=="off") {time="on"}
 else {time="off"}
 document.cookie="time="+time+"; expires=Thu, 2 Aug 2012 20:47:11 UTC"
 window.open("/Ver4","_self")
}

function toggleWeather () {
 if (weather=="off") {weather="on"}
 else {weather="off"}
 document.cookie="weather="+weather+"; expires=Thu, 2 Aug 2012 20:47:11 UTC"
 window.open("/Ver4","_self")
}

function toggleMap () {
 if (map=="off") {map="on"}
 else {map="off"}
 document.cookie="map="+map+"; expires=Thu, 2 Aug 2012 20:47:11 UTC"
 window.open("/Ver4","_self")
}

function toolbar(icon) {
 var a=document.getElementsByName("icon");
 for(var i=0;i<a.length;i++) {a[i].style.height=(icon-10)+"px"}
 var a=document.getElementsByName("button");
 for(var i=0;i<a.length;i++) {a[i].style.height=(icon-10)+"px"}
 if (icon==42) {for(var i=0;i<a.length;i++) {a[i].style.marginLeft='-36px'}}
 if (icon==58) {for(var i=0;i<a.length;i++) {a[i].style.marginLeft='-52px'}}
 document.cookie="icon="+icon+"; expires=Thu, 2 Aug 2012 20:47:11 UTC"
}

shade=4
function shaderOff() {
 if (shade>-1) {
  document.getElementById('div2').style.marginTop="-"+(55+(shade*4))+"px"
  document.getElementById('div5').style.marginTop="-"+(55+(shade*4))+"px"
  shade-=1
  setTimeout(function(){shaderOff()},0)  
 }
 else {shade=4}
}

function theme(skin) {
 document.getElementById('div2').style.marginTop="-80px"
 document.getElementById('div5').style.marginTop="-80px"
 document.getElementById('body').style.background="url('"+skin+".jpg')"
 document.getElementById('logo').src="logo"+skin+".png"
 document.getElementById('menu').style.backgroundImage="url('menu"+skin+".png')"
 for (var i=1;i<7;i++) {document.getElementById("item"+i).style.backgroundImage="url('item"+skin+".png')"}
 document.getElementById('toolbar').style.backgroundImage="url('toolbar"+skin+".png')"
 var a=document.getElementsByName('icon')
 for(var i=0;i<a.length;i++) {a[i].src="button"+skin+".png"}
 for (var i=1;i<4;i++) {document.getElementById('bg'+i).style.backgroundImage="url('div"+skin+".jpg')"}
 document.getElementById('footer').style.backgroundImage="url('footer"+skin+".png')"
 document.cookie="skin="+skin+"; expires=Thu, 2 Aug 2012 20:47:11 UTC"
 shaderOff()
}

function divBlack() {
 document.getElementById("divA").src="divBlackTopLeft.png"
 document.getElementById("divB").src="divBlackTopRight.png"
 document.getElementById("divC").src="divBlackLowerLeft.png"
 document.getElementById("divD").src="divBlackLowerRight.png"
 document.getElementById("divAA").src="divBlackTopLeft.png"
 document.getElementById("divBB").src="divBlackTopRight.png"
 document.getElementById("divCC").src="divBlackLowerLeft.png"
 document.getElementById("divDD").src="divBlackLowerRight.png"
 for (var i=1;i<7;i++) {document.getElementById("div"+i).style.backgroundColor="black"}
 document.getElementById("divs").style.backgroundImage="url('divBlackRightShadow.png')"
 document.getElementById("divss").style.backgroundImage="url('divBlackLowerShadow.png')"
 document.getElementById("divSh").style.backgroundImage="url('divBlackRightShadow.png')"
 document.getElementById("divShS").style.backgroundImage="url('divBlackLowerShadow.png')"
 document.getElementById("sdiv").style.backgroundImage="url('divBlackLowerShadow.png')"
 document.getElementById("shdiv").style.backgroundImage="url('divBlackLowerShadow.png')"
}

function divWhite() {
 document.getElementById("divA").src="divTopLeft.png"
 document.getElementById("divB").src="divTopRight.png"
 document.getElementById("divC").src="divLowerLeft.png"
 document.getElementById("divD").src="divLowerRight.png"
 document.getElementById("divAA").src="divTopLeft.png"
 document.getElementById("divBB").src="divTopRight.png"
 document.getElementById("divCC").src="divLowerLeft.png"
 document.getElementById("divDD").src="divLowerRight.png"
 for (var i=1;i<7;i++) {document.getElementById("div"+i).style.backgroundColor="white"}
 document.getElementById("divs").style.backgroundImage="url('divRightShadow.png')"
 document.getElementById("divss").style.backgroundImage="url('divLowerShadow.png')"
 document.getElementById("divSh").style.backgroundImage="url('divRightShadow.png')"
 document.getElementById("divShS").style.backgroundImage="url('divLowerShadow.png')"
 document.getElementById("sdiv").style.backgroundImage="url('divLowerShadow.png')"
 document.getElementById("shdiv").style.backgroundImage="url('divLowerShadow.png')"
}

var fade=new Array()
for (var i=0;i<4;i++) {fade[i]=10}
LastDisplay=new Array()
LastDisplay[0]="menu1"
LastDisplay[1]="intro1"
LastDisplay[2]="menu2"
LastDisplay[3]="intro2"
function Fade(Display, pos) {
 if(fade[pos]>0) {
  document.getElementById(LastDisplay[pos]).style.opacity=(fade[pos]*10)/100
  document.getElementById(LastDisplay[pos]).style.filter="alpha(opacity="+(fade[pos]*10)+")"
  fade[pos]-=1;
  D=Display
  p=pos
  setTimeout(function(){Fade(D, p)},10)
 }
 else {
  fade[pos]=10;
  document.getElementById(LastDisplay[pos]).style.opacity=1
  document.getElementById(LastDisplay[pos]).style.filter="alpha(opacity=100)"
  document.getElementById(LastDisplay[pos]).style.height=0;
  LastDisplay[pos]=Display;
  document.getElementById(Display).style.height='100%'
 }
}
