// browser check
var browserName = navigator.appName;
var browserVersion = parseInt ( navigator.appVersion );
var oldIE;

if (browserName == "Microsoft Internet Explorer" && 
    browserVersion == 4 && 
    navigator.appVersion.indexOf("MSIE 5.5") != -1) {
    oldIE=true;	// IE 5.5
}
else if (browserName == "Microsoft Internet Explorer" && 
    browserVersion == 4 && 
    navigator.appVersion.indexOf("MSIE 5.0") != -1) {
    oldIE=true;	// IE 5.0
}

// calculate height
function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight)=='number') {
windowHeight=window.innerHeight;
}
else {
if (document.documentElement&&document.documentElement.clientHeight) {
windowHeight=document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight=document.body.clientHeight;
}
}
}
return windowHeight;
}

// calculate width
function getWindowWidth() {
var windowWidth=0;
if (typeof(window.innerWidth)=='number') {
windowWidth=window.innerWidth;
}
else {
if (document.documentElement&&
document.documentElement.clientWidth) {
windowWidth=document.documentElement.clientWidth;
}
else {
if (document.body&&document.body.clientWidth) {
windowWidth=document.body.clientWidth;
}
}
}
return windowWidth;
}

// get elements by classname
function elementByClassName(cname,elm){
elements=document.getElementsByTagName(elm);
for(i=0; i<elements.length ; i++){
if(elements[i].className && elements[i].className==cname){
return(elements[i]);
}
}
}

// positioning of SideMenu
function positionSideMenu(){
// don't run script for intropage and floatpage
if(document.getElementById("welcome") || document.getElementById("floatpage")) return;	
windowW=getWindowWidth();
sMenu=elementByClassName("side_menu","div");
sMenuW=sMenu.clientWidth;
minW=792;
maxW=992;
if(windowW < minW){
	sMenu.style.left=minW - sMenuW + "px"
}
else if(windowW > maxW){
	sMenu.style.left=maxW - sMenuW + "px"
}
else{
	sMenu.style.left=windowW - sMenuW + "px"
}
}

// positioning of footer
function positionFooter(){
// don't run script for intropage
if(document.getElementById("welcome")) return;	
if(oldIE) return;
windowH=getWindowHeight();
foot=document.getElementById("footer");
footH=foot.clientHeight;
wrap=document.getElementById("wrapper");
wrapH=wrap.clientHeight;
if(wrapH + footH > windowH){
foot.style.position="static";
}
else{
foot.style.position="absolute";
foot.style.bottom="0px";
}
}

//newsticker
function tickerinit(){
	if(!document.getElementById("newsticker")) return;
	cTent=document.getElementById("tickercontent");
	cTainer=document.getElementById("newsticker");
	topDistance=cTainer.offsetHeight;
	scrollSpeed=1;
	ticker();
	addEvent(cTainer, 'mouseover', stop, false);
	addEvent(cTainer, 'mouseout', reStart, false);
}
function stop(){
	scrollSpeed=0;
}
function reStart(){
	scrollSpeed=1;	
}
function ticker(){
	if(topDistance==cTent.offsetHeight*(-1)){
	topDistance=cTainer.offsetHeight;
	}
	cTent.style.marginTop=topDistance + "px";
	topDistance-=scrollSpeed;
	setTimeout("ticker()",40);
}


function addEvent(elm, evType, fn, useCapture){
	if(elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if(elm.attachEvent){
		var r=elm.attachEvent('on' + evType, fn);	
		return r;
	}
	else{
		elm['on' + evType]=fn;
	}
}
addEvent(window, 'load', positionFooter, false);
addEvent(window, 'load', positionSideMenu, false);
addEvent(window, 'resize', positionFooter, false);
addEvent(window, 'resize', positionSideMenu, false);
addEvent(window, 'load', tickerinit, false);
