﻿//preload images
function preLoad () {
    if (document.images) { //list of preloaded navi images
        img1 = new Image(); img1.src = '/images/structure/navi_frontpage_nl_act.gif';
        img2 = new Image(); img2.src = '/images/structure/navi_products_nl_act.gif';
        img3 = new Image(); img3.src = '';
        img4 = new Image(); img4.src = '/images/structure/navi_service_and_parts_nl_act.gif';
        img5 = new Image(); img5.src = '/images/structure/navi_current_nl_act.gif';
        img6 = new Image(); img6.src = '/images/structure/navi_entertainment_nl_act.gif';
        img7 = new Image(); img7.src = '/images/structure/navi_company_nl_act.gif';
        img8 = new Image(); img8.src = '/images/structure/navi_fp_tsr_main_s-series_nl_act.gif';
        img9 = new Image(); img9.src = '/images/structure/navi_fp_tsr_main_t-series_nl_act.gif';
        img10 = new Image(); img10.src = '/images/structure/navi_fp_tsr_main_n-series_nl_act.gif';
        img11 = new Image(); img11.src = '<img src="/images/structure/navi_fp_tsr_main_a-series_nl_act.gif">';
        img12 = new Image(); img12.src = '/images/structure/navi_fp_tsr_main_3000series_nl_act.gif';
        img13 = new Image(); img13.src = '';
    }
}
//toggle navi images from passive to active and vice versa
function hi (image,lang) {
    if (document.images) {
        document.images["navi_"+image].src = "/images/structure/navi_" + image + "_" + lang + "_act.gif";
    }
}
function lo (image,lang) {
    if (document.images) {
        document.images["navi_"+image].src = "/images/structure/navi_" + image + "_" + lang + ".gif";
    }
}

//other scripts
var tsrNaviOpenItem = false;
var tsrTabsCurrentTab;
var tsrTabsCurrentTabContent;
var tsrTabsCurrentItemNo;
var tsrTabsSelectedTab;
var tsrTabsSelectedTabContent;

//Additional Calendar tabs
var tsrCalTabsCurrentTab;
var tsrCalTabsCurrentTabContent;
var tsrCalTabsCurrentItemNo;
var tsrCalTabsSelectedTab;
var tsrCalTabsSelectedTabContent;
var right_now=new Date();

//Get Month from URL
var isMonth = document.URL.indexOf('?month=');
if (isMonth != -1)
{
    var month_num = document.URL.substring(isMonth+7, document.URL.length)
}
else
{
    var month_num = right_now.getMonth()+1;
}
var articleSlideCount = 0;
var articleSlideCurrent;
var articleSlideCurrentNo;
var articleSlideNext;
var articleSlidePrevious;
var tsrSlideCount = 0;
var tsrSlideCurrent;
var tsrSlideCurrentNo;
var tsrSlideNext;
var tsrSlidePrevious;
var valtra = {
    'searchKeyword' : {
        'quickSearchText': 'Zoeken'
    },
    addEvent: function(elm, evType, fn, useCapture) {
        if (! elm) return;
        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; 
        }
    },
    init: function() {
              if (!document.getElementById) return;
              var field = document.getElementById('quickSearchText');
              var keyword = valtra.searchKeyword['quickSearchText'];
              if (!field || !keyword) return;
              if (field && field.value == "") field.value = keyword; valtra.addEvent(field, "focus", valtra.clearSearchField, false);
             valtra.addEvent(field, "blur", valtra.fillSearchField, false);
              if (document.getElementById("tsrNavi")) valtra.initSidebarNavi(); //sidebarnavi functionality utilizes jquery
             if (document.getElementById("tsrTabbed")) valtra.initTsrTabs(); //tabs also utilize jquery
             if (document.getElementById("tsrTabbed2")) valtra.initTsrTabs2(); //tabs also utilize jquery
              if (document.getElementById("tsrCalTabbed")) valtra.initCalTsrTabs(); //Calendar tabs also utilize jquery (not frantic added)
              if (document.getElementById("articleSlide1")) valtra.initArticleSlideShow (); //slideshows also utilize jquery
              if (document.getElementById("tsrSlide1")) valtra.initTsrSlideShow ("tsrSlides");
     },
     clearSearchField: function(e) {
              var target = window.event ? window.event.srcElement : e ? e.target : null;
              if (!target) return;
              if (target.value ==valtra.searchKeyword[target.getAttribute("ID")]) target.value = "";
     },
     fillSearchField: function(e) {
              var target = window.event ? window.event.srcElement : e ?e.target : null;
              if (!target) return;
              if (target.value == "") target.value = valtra.searchKeyword[target.getAttribute("ID")];
     },

    initSidebarNavi: function() {
        $("#tsrNavi H3.tsrNaviTitle").each(function (i) {
            valtra.addEvent(this, "click", valtra.toggleSidebarNavi, false);
        });
        $("#tsrNavi .tsrNaviContent").hide();
        $("#tsrNaviContent1").show(); //open first item by default
        $("#tsrNaviTitle1").addClass("active"); //change first item title to active
        tsrNaviOpenItem = $("#tsrNaviTitle1"); //save default open item to a variable
    },
    
    toggleSidebarNavi: function(e) {
        var target = window.event ? window.event.srcElement : e ? e.target : null;
        if (!target) return;
        if ( $(target).next().is(":hidden") ) {
            if (tsrNaviOpenItem) {
                $(tsrNaviOpenItem).next().hide();
                $(tsrNaviOpenItem).removeClass("active");
                tsrNaviOpenItem = $(target);
            }
            $(target).addClass("active");
            $(target).next().slideDown("fast");
        }
    },
//General Tabs
    initTsrTabs: function() {
        $("#tsrTabs").find("A").each(function (i) {
            this.href = "javascript:void(0)";
            valtra.addEvent(this, "click", function () {
                    valtra.toggleTsrTabs(i+1);
            }, false);
        });
        $("#tsrTabbed").find(".tsrTabContent").hide();
        $("#tsrTabbed").find("#tsrTabContent1").show(); //open first item by default
        $("#tsrTabbed").find("#tsrTab1").addClass("active"); //change first item title to active
        tsrTabsCurrentItemNo = 1;
        tsrTabsCurrentTab = $("#tsrTabbed").find("#tsrTab"+tsrTabsCurrentItemNo);
        tsrTabsCurrentTabContent = $("#tsrTabbed").find("#tsrTabContent"+tsrTabsCurrentItemNo);
    },
    toggleTsrTabs: function(tabNo) {
        if (!tabNo) return;
        if ( tabNo != tsrTabsCurrentItemNo ) {
            $(tsrTabsCurrentTab).removeClass("active");
            $(tsrTabsCurrentTabContent).hide();
            tsrTabsSelectedTab = $("#tsrTabbed").find("#tsrTab"+tabNo);
            tsrTabsSelectedTabContent = $("#tsrTabbed").find("#tsrTabContent"+tabNo);
            $(tsrTabsSelectedTab).addClass("active");
            $(tsrTabsSelectedTabContent).show();
            tsrTabsCurrentItemNo = tabNo;
            tsrTabsCurrentTab = tsrTabsSelectedTab;
            tsrTabsCurrentTabContent = tsrTabsSelectedTabContent;
        }
    },
    initTsrTabs2: function() {
        
        $("#tsrTabs2").find("A").each(function (i) {
            this.href = "javascript:void(0)";
            valtra.addEvent(this, "click", function () {
                    valtra.toggleTsrTabs2(i+1);
            }, false);
        });
        $("#tsrTabbed2").find(".tsrTabContent").hide();
        $("#tsrTabbed2").find("#tsrTabContent1").show(); //open first item by default
        $("#tsrTabbed2").find("#tsrTab1").addClass("active"); //change first item title to active
        tsrTabsCurrentItemNo2 = 1;
        tsrTabsCurrentTab2 = $("#tsrTabbed2").find("#tsrTab"+tsrTabsCurrentItemNo2);
        tsrTabsCurrentTabContent2 = $("#tsrTabbed2").find("#tsrTabContent"+tsrTabsCurrentItemNo2);
    },
    toggleTsrTabs2: function(tabNo2) {
        if (!tabNo2) return;
        if ( tabNo2 != tsrTabsCurrentItemNo2 ) {
            $(tsrTabsCurrentTab2).removeClass("active");
            $(tsrTabsCurrentTabContent2).hide();
            tsrTabsSelectedTab2 = $("#tsrTabbed2").find("#tsrTab"+tabNo2);
            tsrTabsSelectedTabContent2 = $("#tsrTabbed2").find("#tsrTabContent"+tabNo2);
            $(tsrTabsSelectedTab2).addClass("active");
            $(tsrTabsSelectedTabContent2).show();
            tsrTabsCurrentItemNo2 = tabNo2;
            tsrTabsCurrentTab2 = tsrTabsSelectedTab2;
            tsrTabsCurrentTabContent2 = tsrTabsSelectedTabContent2;
        }
    },
//Calendar Tabs
    initCalTsrTabs: function() {
        $("#tsrCalTabs A").each(function (i) {
            this.href = "javascript:void(0)";
            valtra.addEvent(this, "click", function () {
                    valtra.toggleCalTsrTabs(i+1);
            }, false);
        });
        $("#tsrCalTabbed .tsrCalTabContent").hide();
        $("#tsrCalTabContent"+month_num).show(); //open first item by default
        $("#tsrCalTab"+month_num).addClass("active"); //change first item title to active
        tsrCalTabsCurrentItemNo = month_num;
        tsrCalTabsCurrentTab = document.getElementById("tsrCalTab"+tsrCalTabsCurrentItemNo);
        tsrCalTabsCurrentTabContent = document.getElementById("tsrCalTabContent"+tsrCalTabsCurrentItemNo);
    },
    toggleCalTsrTabs: function(tabNo) {
        if (!tabNo) return;
        if ( tabNo != tsrCalTabsCurrentItemNo ) {
            $(tsrCalTabsCurrentTab).removeClass("active");
            $(tsrCalTabsCurrentTabContent).hide();
            tsrCalTabsSelectedTab = document.getElementById("tsrCalTab"+tabNo);
            tsrCalTabsSelectedTabContent = document.getElementById("tsrCalTabContent"+tabNo);
            $(tsrCalTabsSelectedTab).addClass("active");
            $(tsrCalTabsSelectedTabContent).show();
            tsrCalTabsCurrentItemNo = tabNo;
            tsrCalTabsCurrentTab = tsrCalTabsSelectedTab;
            tsrCalTabsCurrentTabContent = tsrCalTabsSelectedTabContent;
        }
    },
    initArticleSlideShow: function () {
        var divs = document.getElementById("content").getElementsByTagName("DIV");
        for (i=0; i < divs.length; i++) {
            if ( divs[i].className.indexOf("articleSlide") > -1 ) {
                articleSlideCount++;
            }
        }
        articleSlideCurrentNo = 1;
        articleSlideCurrent = document.getElementById("articleSlide"+articleSlideCurrentNo);
    },
    nextArticleSlide: function () {
        if (articleSlideCount > 1) {
            $(articleSlideCurrent).hide();
            if (articleSlideCurrentNo < articleSlideCount) {
                articleSlideNext = document.getElementById("articleSlide"+(articleSlideCurrentNo+1));
                articleSlideCurrentNo++ ;
            } else {
                articleSlideNext = document.getElementById("articleSlide1");
                articleSlideCurrentNo = 1;
            }
            $(articleSlideNext).show();
            articleSlideCurrent = articleSlideNext;
        }
        return false;
    },
    previousArticleSlide: function () {
        if (articleSlideCount > 1) {
            $(articleSlideCurrent).hide();
            if (articleSlideCurrentNo > 1) {
                articleSlidePrevious = document.getElementById("articleSlide"+(articleSlideCurrentNo-1));
                articleSlideCurrentNo-- ;
            } else {
                articleSlidePrevious = document.getElementById("articleSlide"+(articleSlideCount));
                articleSlideCurrentNo = articleSlideCount;
            }
            $(articleSlidePrevious).show();
            articleSlideCurrent = articleSlidePrevious;
        }
        return false;
    },
    initTsrSlideShow: function (id) {
        var imgs = document.getElementById(id).getElementsByTagName("IMG");
        for (i=0; i < imgs.length; i++) {
            tsrSlideCount++;
        }
        tsrSlideCurrentNo = 1;
        tsrSlideCurrent = document.getElementById("tsrSlide"+tsrSlideCurrentNo);
    },
    nextTsrSlide: function () {
        if (tsrSlideCount > 1) {
            $(tsrSlideCurrent).hide();
            if (tsrSlideCurrentNo < tsrSlideCount) {
                tsrSlideNext = document.getElementById("tsrSlide"+(tsrSlideCurrentNo+1));
                tsrSlideCurrentNo++ ;
            } else {
                tsrSlideNext = document.getElementById("tsrSlide1");
                tsrSlideCurrentNo = 1;
            }
            $(tsrSlideNext).show();
            tsrSlideCurrent = tsrSlideNext;
        }
        return false;
    },
    previousTsrSlide: function () {
        if (tsrSlideCount > 1) {
            $(tsrSlideCurrent).hide();
            if (tsrSlideCurrentNo > 1) {
                tsrSlidePrevious = document.getElementById("tsrSlide"+(tsrSlideCurrentNo-1));
                tsrSlideCurrentNo-- ;
            } else {
                tsrSlidePrevious = document.getElementById("tsrSlide"+(tsrSlideCount));
                tsrSlideCurrentNo = tsrSlideCount;
            }
            $(tsrSlidePrevious).show();
            tsrSlideCurrent = tsrSlidePrevious;
        }
        return false;
    }
}
//hide articleslides and show "previous" and "next" arrows for browsers that have js on
//hide product series teaser's (tsrTabbed) content blocks
document.write('<sty'+'le type="text/css">.articleSlide {display:none} TABLE.slideShowContols TD.previous IMG, TABLE.slideShowContols TD.next IMG, TABLE.tsrSlideShow TD.previous IMG, TABLE.tsrSlideShow TD.next IMG {visibility:visible} .tsrTabbed .tsrTabContent {display: none;}<\/sty'+'le>');
//initialize scripts
valtra.addEvent(window, "load", valtra.init, false);

function openWindow(url, w, h, scroll) {
      window.open(url,'_blank','width='+w+',height='+h+',status=no,resizable=no,menubar=no,toolbar=no,location=no,scrollbars='+scroll+',alwaysRaised');
    }

var DDSPEED = 10;
var DDTIMER = 15;
// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}
// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}
// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}
// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}
