/////////////// browser detection //////////////////////

var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")!=-1) );

var MAC = navigator.platform.indexOf("Mac") != -1;

//////////////////////////// common functions ////////////////////////////////////

// open a window with a specific size
function openWin(url,winName,opts) {
	
	// 10.05.2005 13:35 negg changed width=600,height=400, because safari showed white borders
	if(!opts) opts = "width=600,height=420,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0";

	// if screensize bigger than 1024x768 than adjust left and top position
	if (screen.width > 800) { wleft = 30;	} else { wleft = 10 }
	if (screen.height > 600) { wtop = 90;	} else { wtop = 10 }
	opts = "left="+wleft+",top="+wtop+","+opts;
	
	if(!winName) winName = "blank";
	win = window.open(url,winName,opts);
	win.focus();
}


//
// init
//

// variables
var globalVar = 0;
var nr = 0;
//var nrImg = 0;
var arr_img = new Array; // image array for rollover images
var initOk = false;

function init() {

        // initialize main functions
        a1ImgMenuPreload();

        // ready
        initOk = true;
}


// a1ImgMenu - defining a set of images that behave like a menu
// 2002 by aspekt (ar@aspekt1.net)
//
// mouseover images come in groups that behave like a menu. They are
// defined in arr_img, an array of preloaded mouseover images.
// The naming scheme for files is:
// "groupName"_"imageId"_"state""mouseOverState"
// where:
//   groupName [string] all images of a group share this string
//   imageId [int] identifier of this image in the group, starting with 0
//   state [int 0|1|2] menu state the image represents
//     0 = inactive
//        1 = neutral
//        2 = active
//      mouseOverState [int 0|1] the mouseOver state of the image
//              0 = neutral
//              1 = mouseover
// E.g. menu_1_20 = the second "menu" image in active, noMouseOver state
//
// Also define the path to the images (with slash) in var imgPath
//
// This script has a second part that has to be included after the images
// in the HTML flow. There the setting for a rollover-set are defined.

//
// preparation
//

function a1ImgMenuPreload() {
        // preloading images from the arr_img
        // all images are loaded into arr_img[group][imageId][mouseover state]
        for (group in arr_img) {
                // go through each image group
                for (i=0; i<arr_img[group]["nrOfItems"]; i++) {
                        arr_img[group][i] = new Array;
                        arr_img[group][i][0] = new Image;
                        arr_img[group][i][1] = new Image;
                        // preload all image states
                        if (i == arr_img[group]["activeItem"]) {
                                arr_img[group][i][0].src = imgPath + group + "_" + i + "_" + "11" + arr_img[group]["fileType"]; // at ahl website we simply show the
                                arr_img[group][i][1].src = imgPath + group + "_" + i + "_" + "11" + arr_img[group]["fileType"]; // mouseover image for the active item!
                        } else {
                                arr_img[group][i][0].src = imgPath + group + "_" + i + "_" + "10" + arr_img[group]["fileType"];
                                arr_img[group][i][1].src = imgPath + group + "_" + i + "_" + "11" + arr_img[group]["fileType"];
                        }
                }
        }
}

// loading the initial state of the images of a group
// so you do not need to specify a src in the image tag
// call this function right after the img-Tags in the
// HTML-flow, after specifying the menu-parameters
function a1ImgMenuInit(group) {
        for (i=0; i<arr_img[group]["nrOfItems"]; i++) {
                if (i == arr_img[group]["activeItem"]) document.images[group+"_"+i].src = imgPath + group + "_" + i + "_" + "11" + arr_img[group]["fileType"];
                else document.images[group+"_"+i].src = imgPath + group + "_" + i + "_" + "10" + arr_img[group]["fileType"];
        }
}

// mouseover and mouseout functions
function a1In(imgGroup,imgId) {
        if (document.images && initOk) {
                document.images[imgGroup + "_" + imgId].src = arr_img[imgGroup][imgId]["1"].src;
                // ahl website special
                if (imgGroup == 'menu') document.images["menuDisp"].src = menuDisp[imgId].src;
        }
}
function a1Out(imgGroup,imgId) {
        if (document.images && initOk) {
                document.images[imgGroup + "_" + imgId].src = arr_img[imgGroup][imgId]["0"].src;
                // ahl website special
                if (imgGroup == 'menu') document.images["menuDisp"].src = menuDisp[arr_img["menu"]["activeItem"]].src;
        }
}

// makes a div visible | divObj:  the div to make visible
function showDiv(divObj) {
        if (initOk) {
                obj = document.getElementById(divObj);
                obj.style.visibility = "visible";
                obj.blur(); //weg mit dem ekligen IE.mac-focus-rectangle !

        }
}

// makes a div invisible
function hideDiv(divObj) {
        if (initOk) {
                obj = document.getElementById(divObj);
                obj.style.visibility = "hidden";
        }
}




//
// list functions
//

function invertRow (elmt) {
        eA = document.getElementById("r"+elmt);
        eB = document.getElementById("r"+elmt+'B');
        eC = document.getElementById("r"+elmt+'C');
        eA.style.backgroundColor = eB.style.backgroundColor = eC.style.backgroundColor = "#000000";
        eA.style.color = eB.style.color = eC.style.color = "#ffffff";
}

function invertInactRow (elmt) {
        eA = document.getElementById("r"+elmt);
        eB = document.getElementById("r"+elmt+'B');
        eC = document.getElementById("r"+elmt+'C');
        eA.style.backgroundColor = eB.style.backgroundColor = eC.style.backgroundColor = "#eeeeee";
}

function normalizeRow(elmt) {
        eA = document.getElementById("r"+elmt);
        eB = document.getElementById("r"+elmt+'B');
        eC = document.getElementById("r"+elmt+'C');
        eA.style.backgroundColor = eB.style.backgroundColor = eC.style.backgroundColor = "#ffffff";
        eA.style.color = eB.style.color = eC.style.color = "#000000";
}


function imgPreload(number, img){
        newImg = "img" + number;
        newImg = new Image;
        newImg.src = img;
}

function changeImg(imgNr, nrImg){
        globalVar = imgNr;
        newImgSrc = document.getElementById(imgNr).src;
        oldImg = document.getElementById('mainImg');
        oldImg.src = newImgSrc;
        changeMenuColor(imgNr, nrImg);
}

function preImg(nrImg){
        nr = globalVar;
        if(nr != 0){
                nr--;
                changeImg(nr, nrImg);
        }
}
function nextImg(size){
        nr = globalVar;
        if(nr != size){
                nr++;
                changeImg(nr, size);
        }
}
