﻿function addEvent(target, functionref, tasktype) {
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false);
	else if (target.attachEvent)
		target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
}

function removeEvent(target, functionref, tasktype) {
    if (target.addEventListener)
        target.removeEventListener(tasktype, functionref, false);
    else if (target.attachEvent)
        target.detachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
}


function $_(obj){
    return document.getElementById (obj);
}

function hoverOver(obj, name){
    var myObj = $_(obj);
    myObj.src = '/images/templates/top_nav/ro/' + name;
}

function hoverOut(obj, name){
    var myObj = $_(obj);
    myObj.src = '/images/templates/top_nav/' + name;
}
        


function changeArrow(obj){
    try
    {
        var myImg = obj.getElementsByTagName("img")[0];
        myImg.src = '/images/templates/arrow_right.png';
        addEvent(obj, function () { changeArrowBack(obj); }, "mouseout");
    }
    catch(e){
    
    }
}

function changeArrowBack(obj){
    try
    {
        var myImg = obj.getElementsByTagName("img")[0];
        myImg.src = '/images/templates/arrow_right.png';
    
        removeEvent(obj, function () { changeArrowBack(obj); }, "mouseout");
    }
    catch (e) {}
}

function changeArrow2(obj){
    try
    {
        var myImg = obj.getElementsByTagName("img")[0];
        myImg.src = '/images/templates/arrow_right.png';
    
        addEvent(obj, function () { changeArrowBack2(obj); }, "mouseout");
    }
    catch (e) {}
}

function changeArrowBack2(obj){
    try
    {
        var myImg = obj.getElementsByTagName("img")[0];
        myImg.src = '/images/templates/arrow_right.png';
    
        removeEvent(obj, function () { changeArrowBack2(obj); }, "mouseout");
    }
    catch (e) {}
}

 function MouseOff(obj, level){
        obj.style.backgroundImage = "url(/images/templates/level" + level + "_bottom.png)";
        
        switch(level){
            case 1:
                obj.style.color = '#275376';
                break;
            case 2:
                obj.style.color = 'White';
                break;
            case 3:
                obj.style.color = '#275376';
                break;                
        }
    }
    
    function MouseOn(obj, level){
        obj.style.backgroundImage = "url(/images/templates/level" + level + "_bottom_ro.png)";
        switch(level){
            case 1:
                obj.style.color = '#FFFFFF';
                break;
            case 2:
                obj.style.color = '#335d79';
                break;
            case 3:
                obj.style.color = '#275376';
                break;
        }
    }


function initTopNav(){
    var links = document.getElementsByName("rounded_bottom1");
    
    for (i = 0; i < links.length; i++){
        addEvent(links[i], function () { MouseOn(this, 1);  }, "mouseover");
        addEvent(links[i], function () { changeArrow(this); }, "mouseover");
        
        addEvent(links[i], function () { MouseOff(this, 1); }, "mouseout");
        
    }
    
    links = document.getElementsByName("rounded_bottom2");
    for (i = 0; i < links.length; i++){
        links[i].onmouseover= function () {
            MouseOn(this, 2);
        }
        
        links[i].onmouseout = function (){
            MouseOff(this, 2);
        }
    }
    
    links = document.getElementsByName("rounded_bottom3");
    
    for (i = 0; i < links.length; i++){
        links[i].onmouseover= function () {
            MouseOn(this, 3);
            
        }
        
        links[i].onmouseout = function (){
            MouseOff(this, 3);
        }
    }
}



































function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}