var ns4,ns6,ie,doc,doc2,doc3,sty;
//Check in this order to prevent IE5 from being W3C DOM browser
if(document.layers) {
	//if Netscape4
	doc="document.";
	doc2=".document.";
	doc3="";
	sty="";
	ns4=true;
} else if (document.all) {
	//if IE
	doc="document.all.";
	doc2="";
	doc3="";
	sty=".style";
	ie=true;
} else if (document.getElementById) {
    	//if DOM Compliant
	doc="document.getElementById('";
	doc2="')";
	doc3="')";
	sty="').style";
	ns6=true;
}
function moveblock() {
//function specific for this page
  elem1=eval(doc+'Bblock1'+sty);
  elem2=eval(doc+'Bblock2'+sty);
  logo=eval(doc+'NWbigtext'+sty);
  logo.visibility='visible';
  var incr=2;
  btop1=btop1-incr;
  btop2=btop2+incr;
  if (ie){
	elem1.pixelTop=btop1;
	elem2.pixelTop=btop2;
  }else{
	elem1.top=btop1+'px';
	elem2.top=btop2+'px';
  }
  if (btop2>winheight+10){
	clearInterval(blockTimer);
	setTimeout('',1000);
	showhide('Bblock1','hidden');
	showhide('Bblock2','hidden');
	sizeobj('Blockimg1',1,1);
	sizeobj('Blockimg2',1,1);	
	//removing scroll bar because of negative bottom placement
	placeobj('Bblock1',-100,null,-100,null);
	placeobj('Bblock2',-100,null,-100,null);	
	callLogomove();
  }
}

function callLogomove() {
       step=15;
       begintop=(winheight-204)/2;
       if (begintop<5){begintop=5};
       endtop=5;
       beginwidth=768;
       endwidth=151;
       beginheight=204;
       endheight=40;
       beginleft=(winwidth-768)/2;
       endleft=5;
       if (beginleft<0) {beginleft=0};
       //calculated variables
       topdim=(begintop-endtop)/step;
       widthdim=(beginwidth-endwidth)/step;
       heightdim=(beginheight-endheight)/step;
       leftdim=(beginleft-endleft)/step;
       moveTimer=setInterval('logomove()',75);
}


function logomove(){	
	//moves logo from mid position to upperleft corner and changes image size
	movdiv=eval(doc+'NWbigtext'+sty);
	sizeimg=eval(doc+'logoimg'+sty);	
	begintop=begintop-topdim;
	beginwidth=beginwidth-widthdim;
	beginheight=beginheight-heightdim;
	beginleft=beginleft-leftdim;
	//compensate for deviation in calculation
	if (begintop<=endtop) {
		begintop=endtop;
		beginwidth=endwidth;
		beginheight=endheight;
	}
	if (ie) {
		movdiv.pixelTop=begintop;
		movdiv.pixelLeft=beginleft;
	}else{
		movdiv.top=begintop+'px';
		movdiv.left=beginleft+'px';
	}
	sizeimg.width=beginwidth+'px';
	sizeimg.height=beginheight+'px';
	if (begintop<=endtop) {
		clearInterval(moveTimer);
		starting=false;
		setTimeout("layoutoval()",750);
	}
}
		
function dimensions() {
//get dimensions
	if (ie) {
		winwidth=document.body.clientWidth;
		winheight=document.body.clientHeight;
	}else{
		winwidth=window.innerWidth;
		winheight=window.innerHeight;
	}
	centerhor=winwidth/2;
	centerver=winheight/2;
}


function centerobj(objname,dimh,dimv) {
	toppos=(winheight-dimv)/2;
	if (toppos<0) {toppos=0};
	leftpos=(winwidth-dimh)/2;
	if (leftpos<0) {leftpos=0};
	object=eval(doc+objname+sty);
	if (ie){
		object.pixelTop=toppos;
		object.pixelLeft=leftpos;
	}else{
		object.top=toppos;
		object.left=leftpos;
	}
	return(true);
}

function placeobj(objname,leftp,rightp,topp,bottomp) {
	object=eval(doc+objname+sty);
	if (ie) {
		if (leftp!=null) {object.pixelLeft=leftp};
		if (rightp!=null) {object.pixelRight=rightp};		
		if (topp!=null) {object.pixelTop=topp};	
		if (bottomp!=null) {object.pixelBottom=bottomp};
	}else{
		if (leftp!=null) {object.left=leftp};
		if (rightp!=null) {object.right=rightp};		
		if (topp!=null) {object.top=topp};	
		if (bottomp!=null) {object.bottom=bottomp};
	}
}

function sizeobj(objname,imgw,imgh) {
	object=eval(doc+objname+sty);
	object.width=imgw+'px';
	object.height=imgh+'px';
}

function showhide(objname,state){
  elem=eval(doc+objname+sty);
  elem.visibility=state;
}
function startpage() {
//specific for this page
	dimensions();
	blockheight=(winheight/2);
	sizeobj('Blockimg1',winwidth,blockheight);
	sizeobj('Blockimg2',winwidth,blockheight);
	placeobj('Bblock1',0,null,0,null);
	placeobj('Bblock2',0,null,centerver,null);
	centerobj('NWbigtext',768,204);
	showhide('Bblock1','visible');
	showhide('Bblock2','visible');
	placeobj('Loading',-500,null,-500,null);
	btop1=0;
	btop2=centerver;
	setTimeout("NWMwater()",randomtime);
	blockTimer=setInterval('moveblock()',2);
}


function layoutoval() {
//activated upon load and resize
	if (starting) {
		window.location.reload(true); //always display logo full screen
		return(false);
		}
     	dimensions(); // if resize or layout after logo display
     	if (winwidth<1039 || winheight<683) {
     		factor=((winwidth-30)/1019);
     		ovalw=1019*factor
     		ovalh=663*factor
     		if (factor<0.6){factor=0.6} // Minimum screen size of +/- 650*400
     		sizeobj('Ovalimg',1019*factor,663*factor);
		sizeobj(activetext,570*factor,530*factor)     		
	     	placeobj(activetext,240*factor,null,90*factor,null);
     		placeobj('Oval',10,null,20,null); //looks better, but not centered
		placeobj('NWmirror',0,null,ovalh,null);
		placeobj('Buttonsb',null,null,ovalh,null);
		placeobj('Ringb',null,null,ovalh+1,null);
     	}else{
		placeobj('NWmirror',0,null,winheight-40,null);
		placeobj('Buttonsb',null,null,winheight-40,null);
		placeobj('Ringb',null,null,winheight-39,null);     
     	     	sizeobj('Ovalimg',1019,663);
     		sizeobj(activetext,570,530);	
     		centerobj(activetext,570,530);     	     	
     		centerobj('Oval',1019,663);
     	}
     	showhide('Oval','visible');
     	showhide('Buttons','visible');
     	showhide('Buttonsb','visible');
     	showhide('NWmirror','visible');
     	if (firsttime) { //if page hasn't been layed out before
		showhide(activetext,'visible');
      	firsttime=false;
      	//showNews();
      }
      
}

function displaytext(textvar,ringvar,ringpl,ringpr,ringpt,ringpb) {
	showhide(activetext,'hidden');
	placeobj(activetext,0,null,-1500,0); //move out of sight because of scrollbar	
	textvar=textvar+'text'+lang;
	showhide(textvar,'visible');
     	if (winwidth<1039 || winheight<683) {
     		sizeobj(textvar,570*factor,530*factor)     		
	     	placeobj(textvar,240*factor,null,90*factor,null);
	}else{
     		sizeobj(textvar,570,530);	
     		centerobj(textvar,570,530);
     	}
	if (ringvar=="Ring") {
		placeobj('Ring',ringpl,ringpr,ringpt,ringpb);
		showhide('Ring','visible');
		showhide('Ringb','hidden');
	}else{
		showhide('Ring','hidden');
		showhide('Ringb','visible');
	}
	activetext=textvar;
}

function chglang(newlang) {
	showhide(description,'hidden')
	lang=newlang;
	description="Descr"+lang;
	displaytext('Welcome','Ringb');
}

//Swap picture
function swappic(imgobj,imgnew) {
 imgorg = eval(doc+imgobj+doc2);
 imgorg.src = eval(imgnew+'.src');
 }
 
/* obtain a random positive number between lownum and highnum */ 
function randomize(lownum, highnum) {
randomtime=Math.floor(Math.abs(Math.random() * (highnum - lownum + 1) - 0.0000000001)) + lownum;
}

//Randomly display the mirror logo with 'water circles'
function NWMwater() {
	swappic("NWmirrorimg","NWMwaterimg");
	randomize(5000,15000);
	setTimeout("NWMwater()",randomtime);
}

//Open new window
function NWwindow(url,w,h) {
settings = '"channelmode=no fullscreen=no toolbar=yes, directories=no, menubar=no, scrollbars=yes, resizable=yes, status=no, width= '+w+', height='+h+'"';
closeWindow();
newwin=window.open(url,'newwin', settings);
newwin.focus();
}

function closeWindow() {
if (newwin && !newwin.closed) {
newwin.close();
}
}

function showNews() {
	newUrl = "news" + lang + ".html"
	NWwindow (newUrl,790,550);
}

