 window.aryNonactive = new Array();
 window.intInterval;
 window.intPanorama_Index = -1;

 window.aryPanorama = {
                       0 : {
                            "name"  : "ossendrecht",
                            "title" : "Foto: Perry van Kempen"
                           },
                       1 : {
                            "name"  : "hoogerheide",
                            "title" : "Foto: Piet Bout"
                           },
                       2 : {
                            "name"  : "ossendrecht2",
                            "title" : "Foto: Perry van Kempen"
                           },
                       3 : {
                            "name"  : "huijbergen",
                            "title" : "Foto: Ed Kil"
                           },
                       4 : {
                            "name"  : "hoogerheide2",
                            "title" : "Foto: Piet Bout"
                           },
                       5 : {
                            "name"  : "halsteren",
                            "title" : "Foto: Ed Kil"
                           }
                      };

 $(window).ready(function()
  {
   $("#main_menu").find("li").mouseover(function()
    {
     menu_open($(this));
    });

   $(".content_collapse h2").click(function()
    {
     $(this).parent().parent().find(".hidden").slideUp();

     if ($(this).parent().find(".hidden").css("display") != "block")
      {
       $(this).parent().find(".hidden").slideDown();
      }
    });

   $(function()
    {
   	 $("a[rel='lightbox']").lightBox(); // Select all links that contains lightbox in the attribute rel
    });

   window.intInterval = window.setInterval("$('#product_gallery').scrollTo({top: 0, left:'+=530px'}, 500);", 10000);

   if (document.getElementById("panorama"))
    {
     panorama_change(true);
    }


   var strURL  = new String(window.location).replace("#", "");

   var strMain = strURL.substring(0, strrpos(strURL, "-"));

   if (strURL.substring(strURL.length - 5, strURL.length).toLowerCase() == ".html")
    {
     if (strMain != "")
      {
       menu_open($("#main_menu li[title='" + strMain.substr(strrpos(strMain, "/") + 1) + "']"));
      }
     else
      {
       menu_open($("#main_menu li[title='home']"));
      }
    }
   else
    {
     menu_open($("#main_menu li[title='home']"));
    }
  });


 function clear_slide()
  {
   window.intInterval = window.clearInterval(window.intInterval);
  }

 function menu_open(elmElement)
  {
   elmElement = $(elmElement);

   var strMenu_Item = $(elmElement).children("a").html();

   if ($(elmElement).hasClass("active") == false)
    {
     $(elmElement).addClass("active");

     window.aryNonactive[strMenu_Item] = true;
    }

   for (strMenu in window.aryNonactive)
    {
     if (strMenu != strMenu_Item)
      {
       $("#main_menu").find("li[title='" + strMenu + "']").removeClass("active");
      }
    }

   if (strMenu_Item == "home" || strMenu_Item == "contact")
    {
     $(".submenu").fadeOut("fast");
    }
   else if ($(".submenu[title='" + strMenu_Item + "']").css("display") == "none")
    {
     $(".submenu").fadeOut("fast");
     $(".submenu").css("display", "none");
     $(".submenu[title='" + strMenu_Item + "']").fadeIn("fast");
    }
  }
  

 function panorama_change(blnFirst_Run)
  {
   if (blnFirst_Run === true)
    {
     window.intPhoto = window.setInterval("panorama_change();", 7500);
    }

   window.intPanorama_Index++;

   if (window.intPanorama_Index == 6)
    {
     window.intPanorama_Index = 0;
    }

   var strName  = window.aryPanorama[window.intPanorama_Index]["name"];
   var strTitle = window.aryPanorama[window.intPanorama_Index]["title"];

   $("#panorama").fadeOut("fast",
                          function()
                           {
                            $("#panorama").html('<a href="./image/home.' + strName + '.jpg" rel="lightbox" title="' + strTitle + '"><img src="./image/home.' + strName + '.thumb.jpg" alt="" title="' + strTitle + '" style="width: 730px;" /></a>');

                            $("#panorama").fadeIn("fast");
                            $("a[rel='lightbox']").lightBox();
                           });
  }

function strrpos (haystack, needle, offset) {
    // Finds position of last occurrence of a string within another string  
    // 
    // version: 1006.1915
    // discuss at: http://phpjs.org/functions/strrpos
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   input by: saulius
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: strrpos('Kevin van Zonneveld', 'e');
    // *     returns 1: 16
    // *     example 2: strrpos('somepage.com', '.', false);
    // *     returns 2: 8
    // *     example 3: strrpos('baa', 'a', 3);
    // *     returns 3: false
    // *     example 4: strrpos('baa', 'a', 2);
    // *     returns 4: 2
    var i = -1;
    if (offset) {
        i = (haystack+'').slice(offset).lastIndexOf(needle); // strrpos' offset indicates starting point of range till end,
        // while lastIndexOf's optional 2nd argument indicates ending point of range from the beginning
        if (i !== -1) {
            i += offset;
        }
    }
    else {
        i = (haystack+'').lastIndexOf(needle);
    }
    return i >= 0 ? i : false;
}
