
var mar_plaing = true;
var mar_timer;
var mar_nextTime = 6000;
var max_tab_width = 0;
function mar_DisplayControl() {
    if (mar_maxEl == 0) {
        document.getElementById("mbBlock").style.display = "none";
        return;
    }
//    var lis = document.getElementById("mar_numbers");
//    if (lis != null) {
//        lis.innerHTML = "";
//        var iBegin = 1;
//        var iEnd = 6;
//        if (mar_maxEl > 6) {
//            if (mar_currentImg <= 3) {
//                iBegin = 1;
//                iEnd = 6;
//            } else {
//                if (mar_currentImg >= mar_maxEl - 2) {
//                    iBegin = mar_maxEl - 5;
//                    iEnd = mar_maxEl;
//                } else {
//                    iBegin = mar_currentImg - 2;
//                    iEnd = mar_currentImg + 3;
//                }
//            }
//        } else {
//            iBegin = 1;
//            iEnd = mar_maxEl;
//        }

//        var s = "";
//        for (var i = iBegin; i <= iEnd; i++) {
//            var liTag = document.createElement("span");
//            var liTag2 = document.createElement("span");
//            var aTag = document.createElement('a');
//            aTag.setAttribute('href', 'javascript:mar_SetImg(' + i + ');');
//            if (i == mar_currentImg) {
//                aTag.setAttribute("id", "activeLi");
//            }
//            var oTx = document.createTextNode("" + i);
//            aTag.appendChild(oTx);
//            liTag.appendChild(aTag);
//            if (i > iBegin) {
//                liTag2.appendChild(document.createTextNode("|"));
//                lis.appendChild(liTag2);
//            }
//            lis.appendChild(liTag);
//        }
//    }
    
    
    document.getElementById("displayedImageDiv").display = '';
    if (mar_currentImg > 0) {
    
        //document.getElementById("activeLi").className = "active";
        document.getElementById("displayedImageDiv").src = document.getElementById("displayedImage").src;
        
        changeOpac(0, "displayedImage");
        
        document.getElementById("displayedImage").src = mar_imageUrl[mar_currentImg - 1];
        
        document.getElementById("mar_title1").innerHTML = mar_imageAlt[0];
        
        //Added by JvL on 20110504
        //Add url to image using a click event
        var GoNext;
        if (mar_imageTarget[mar_currentImg - 1]== "Parent")
            GoNext = 'location.href="' + mar_imageLink[mar_currentImg - 1] + '";';
        else
        {
            var url = mar_imageLink[mar_currentImg - 1];
            if (url.toLowerCase().indexOf("http://")<0)
                url = 'http://' + url;
            GoNext = 'var TheWindow = window.open("'+  url + '"); TheWindow.focus()';
        }
        document.getElementById("displayedImage").onclick = new Function(GoNext);
        //End addition
        
        

        var heightTxt =  (260 - (mar_imageAlt.length*30)) / mar_imageAlt.length;
        document.getElementById("mar_title1").parentNode.parentNode.nextSibling.style.height = heightTxt + "px";
        if(mar_imageAlt.length > 1){
            document.getElementById("mar_title2").innerHTML = mar_imageAlt[1];
            document.getElementById("mar_title2").parentNode.parentNode.nextSibling.style.height = heightTxt + "px";
            }
        else{
            document.getElementById("mar_title2").parentNode.style.display = "none";
            document.getElementById("mar_img2").parentNode.style.display = "none";            
        }
        if(mar_imageAlt.length > 2){
             document.getElementById("mar_title3").innerHTML = mar_imageAlt[2];  
             document.getElementById("mar_title3").parentNode.parentNode.nextSibling.style.height = heightTxt + "px";              
        }
        else{
            document.getElementById("mar_title3").parentNode.style.display = "none";
            document.getElementById("mar_img3").parentNode.style.display = "none";
        }
        if(mar_imageAlt.length > 3){
            document.getElementById("mar_title4").innerHTML = mar_imageAlt[3];
            document.getElementById("mar_title4").parentNode.parentNode.nextSibling.style.height = heightTxt + "px";
            }
        else{
            document.getElementById("mar_title4").parentNode.style.display = "none";    
            document.getElementById("mar_img4").parentNode.style.display = "none";
        }
        if(mar_imageAlt.length > 4){
            document.getElementById("mar_title5").innerHTML = mar_imageAlt[4];
            document.getElementById("mar_title5").parentNode.parentNode.nextSibling.style.height = heightTxt + "px";
        }            
        else{
            document.getElementById("mar_title5").parentNode.style.display = "none";    
            document.getElementById("mar_img5").parentNode.style.display = "none";
        }
        
        if (mar_currentImg <= mar_imageNextTab[0]) {
            document.getElementById("mar_title1").style.color = "white";
            
            //Adjusted by JvL on 20110504
            //The rounded button style should not use display but visiblilty
            //This way the text remains at the same level
            
//            document.getElementById("mar_img").parentNode.style.display = "";
//            document.getElementById("mar_img2").parentNode.style.display = "none";
//            document.getElementById("mar_img3").parentNode.style.display = "none";
//            document.getElementById("mar_img4").parentNode.style.display = "none";
//            document.getElementById("mar_img5").parentNode.style.display = "none";
            
            document.getElementById("mar_img").parentNode.style.visibility = "visible"
            document.getElementById("mar_img2").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img3").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img4").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img5").parentNode.style.visibility = "hidden";
            
            
            document.getElementById("mar_title1").parentNode.className = "mar_title1_maintd";
            document.getElementById("mar_title2").style.color = "#987801";
            document.getElementById("mar_title2").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title3").style.color = "#987801";
            document.getElementById("mar_title3").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title4").style.color = "#987801";
            document.getElementById("mar_title4").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title5").style.color = "#987801";
            document.getElementById("mar_title5").parentNode.className = "mar_title1_maintd1";
        }
        else if (mar_imageAlt.length > 1 && mar_currentImg <= mar_imageNextTab[1]) {
        
//            document.getElementById("mar_img").parentNode.style.display = "none";
//            document.getElementById("mar_img2").parentNode.style.display = "";
//            document.getElementById("mar_img3").parentNode.style.display = "none";
//            document.getElementById("mar_img4").parentNode.style.display = "none";
//            document.getElementById("mar_img5").parentNode.style.display = "none";
            
            document.getElementById("mar_img").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img2").parentNode.style.visibility = "visible";
            document.getElementById("mar_img3").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img4").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img5").parentNode.style.visibility = "hidden";
            
            
            document.getElementById("mar_title2").style.color = "white";
            document.getElementById("mar_title2").parentNode.className = "mar_title1_maintd";
            document.getElementById("mar_title1").style.color = "#987801";
            document.getElementById("mar_title1").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title3").style.color = "#987801";
            document.getElementById("mar_title3").width = "280px";
            document.getElementById("mar_title3").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title4").style.color = "#987801";
            document.getElementById("mar_title4").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title5").style.color = "#987801";
            document.getElementById("mar_title5").parentNode.className = "mar_title1_maintd1";
        }
        else if (mar_imageAlt.length > 2 && mar_currentImg <= mar_imageNextTab[2]) {
            
//            document.getElementById("mar_img").parentNode.style.display = "none";
//            document.getElementById("mar_img2").parentNode.style.display = "none";
//            document.getElementById("mar_img3").parentNode.style.display = "";
//            document.getElementById("mar_img4").parentNode.style.display = "none";
//            document.getElementById("mar_img5").parentNode.style.display = "none";
            
            document.getElementById("mar_img").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img2").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img3").parentNode.style.visibility = "visible";
            document.getElementById("mar_img4").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img5").parentNode.style.visibility = "hidden";
            
            document.getElementById("mar_title3").style.color = "white";
            document.getElementById("mar_title3").parentNode.className = "mar_title1_maintd";
            document.getElementById("mar_title2").style.color = "#987801";
            document.getElementById("mar_title2").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title1").style.color = "#987801";
            document.getElementById("mar_title1").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title4").style.color = "#987801";
            document.getElementById("mar_title4").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title5").style.color = "#987801";
            document.getElementById("mar_title5").parentNode.className = "mar_title1_maintd1";
        }
        else if (mar_imageAlt.length > 3 && mar_currentImg <= mar_imageNextTab[3]) {
        
//            document.getElementById("mar_img").parentNode.style.display = "none";
//            document.getElementById("mar_img2").parentNode.style.display = "none";
//            document.getElementById("mar_img3").parentNode.style.display = "none";
//            document.getElementById("mar_img4").parentNode.style.display = "";
//            document.getElementById("mar_img5").parentNode.style.display = "none";
            
            document.getElementById("mar_img").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img2").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img3").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img4").parentNode.style.visibility = "visible";
            document.getElementById("mar_img5").parentNode.style.visibility = "hidden";
            
            document.getElementById("mar_title4").style.color = "white";
            document.getElementById("mar_title4").parentNode.className = "mar_title1_maintd";
            document.getElementById("mar_title2").style.color = "#987801";
            document.getElementById("mar_title2").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title1").style.color = "#987801";
            document.getElementById("mar_title1").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title3").style.color = "#987801";
            document.getElementById("mar_title3").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title5").style.color = "#987801";
            document.getElementById("mar_title5").parentNode.className = "mar_title1_maintd1";
        }
        else if (mar_imageAlt.length > 4 && mar_currentImg <= mar_imageNextTab[4]) {
            
//            document.getElementById("mar_img").parentNode.style.display = "none";
//            document.getElementById("mar_img2").parentNode.style.display = "none";
//            document.getElementById("mar_img3").parentNode.style.display = "none";
//            document.getElementById("mar_img4").parentNode.style.display = "none";
//            document.getElementById("mar_img5").parentNode.style.display = "";
            
            document.getElementById("mar_img").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img2").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img3").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img4").parentNode.style.visibility = "hidden";
            document.getElementById("mar_img5").parentNode.style.visibility = "visible";
            
            document.getElementById("mar_title5").style.color = "white";
            document.getElementById("mar_title5").parentNode.className = "mar_title1_maintd";
            document.getElementById("mar_title2").style.color = "#987801";
            document.getElementById("mar_title2").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title1").style.color = "#987801";
            document.getElementById("mar_title1").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title3").style.color = "#987801";
            document.getElementById("mar_title3").parentNode.className = "mar_title1_maintd1";
            document.getElementById("mar_title4").style.color = "#987801";
            document.getElementById("mar_title4").parentNode.className = "mar_title1_maintd1";
        }
        document.getElementById("displayedImageDiv").display = 'none';
        for (i = 0; i <= 100; i += 5) {
            setTimeout("changeOpac(" + i + ",'displayedImage')", (i * 5));
        }
    }
}
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 mar_PlayPause() {
    if (mar_plaing) {
        mar_Pause();
    } else {
        mar_Play();
    }
}
function mar_Pause() {
    clearTimeout(mar_timer);
    mar_plaing = false;
    mar_DisplayControl();
}
function mar_Play() {
    mar_plaing = true;
    mar_DisplayControl();
    mar_timer = setTimeout("mar_PlayNextPicture();", mar_nextTime);
}
function mar_NextPict() {
    if (mar_plaing) {
        mar_Pause();
    }
    mar_currentImg += 1;
    if (mar_currentImg > mar_maxEl) {
        mar_currentImg = 1;
    }
    mar_DisplayControl();
}
function mar_PrevPict() {
    if (mar_plaing) {
        mar_Pause();
    }
    mar_currentImg -= 1;
    if (mar_currentImg < 1) {
        mar_currentImg = mar_maxEl;
    }
    mar_DisplayControl();
}
function mar_PlayNextPicture() {
    mar_currentImg += 1;
    if (mar_currentImg > mar_maxEl) {
        mar_currentImg = 1;
    }
    mar_DisplayControl();
    mar_timer = setTimeout("mar_PlayNextPicture();", mar_nextTime);
}
function mar_SetImg(num) {
    if (mar_plaing) {
        mar_Pause();
    }
    mar_currentImg = num;
    mar_DisplayControl();
}
function mar_StartDisplay() {
    mar_DisplayControl();
    
    //Added by JvL on 20110504
    //Set a proper width from the image based on the widest text tab
    for (t=1; t<=mar_imageAlt.length; t++)
    {
        var tabwidth = document.getElementById("SSTab" + t.toString()).offsetWidth;
        if (max_tab_width<tabwidth)
            max_tab_width = tabwidth;
        
        var obj = document.getElementById("mar_title" + t.toString());
        var imgNr = t==1 ?1 : parseInt(mar_imageNextTab[t-2],10) + 1;
        obj.onclick = new Function('mar_SetImg(' + imgNr + ');mar_Play();');
    }
    
    if (max_tab_width!=0)
    {
        var imgWidth = 765 - max_tab_width;
        
        //Adjust width of image based on widest text tab
        document.getElementById("displayedImageDiv").style.width = imgWidth + "px";
        document.getElementById("displayedImage").style.width = imgWidth + "px";
        
        //Set image to fixed height
        document.getElementById("displayedImageDiv").style.height = "268px";
        document.getElementById("displayedImage").style.height = "268px";
       
        //Positioning the div       
        document.getElementById("displayedImageDiv").style.left = "2px";
        document.getElementById("displayedImage").style.left = "2px";
        
        //Set the width of the tab
        for (i=1; i<=5; i++)
        {
            var tabel = document.getElementById("TabTable" + i.toString());
            if (tabel)
                tabel.style.width = max_tab_width + "px";
            
            var title = document.getElementById("SSSTab" + i.toString());
            if (title)
            {
                var titlewidth = max_tab_width - 6;
                title.style.width = titlewidth + "px";
            }
            
            
        }
    }
    //end addition
    
    if (mar_maxEl > 1) {
        mar_Play();
    }
}

//Adjusted by JvL on 20110504
//Function is no longer necessary
//function mar_OpenLink() {
//    window.open(mar_imageLink[mar_currentImg - 1], mar_imageTarget[mar_currentImg - 1]);
//}
