 window.intSlide_Index = 1;
 window.intSlideshow;

 $(window).bind("focus", function()
  {
   if (!window.intSlideshow)
    {
     window.intSlideshow  = null;
     window.intHome       = null;

     window.intSlideshow = window.setInterval('slideshow(1);', 7500);
     window.intHome      = window.setTimeout('itemswitch();', 7500);
    }
  });

 $(window).bind("blur", function()
  {
   window.clearInterval(window.intSlideshow);
   window.clearTimeout(window.intHome);

   window.intSlideshow  = null;
   window.intHome       = null;
  });

 function slideshow(intIncrement, intIndex)
  {
   if (Math.abs(intIncrement) == 1)
    {
     var strSign = intIncrement > 0 ? "+" : "-";

     $("#slideshow").scrollTo({left: strSign + "=720", top: 0}, 300);

     eval('window.intSlide_Index' + strSign + strSign + ';');

     if (window.intSlide_Index > $("#slides > div").length)
      {
       window.intSlide_Index = 1;

       $("#slideshow").scrollTo(0, 300);
      }
     else if (window.intSlide_Index < 1)
      {
       window.intSlide_Index = $("#slides > div").length;

       $("#slideshow").scrollTo({left:720*$("#slides > div").length, top: 0}, 300);
      }
    }
   else if (intIndex > 0)
    {
     window.clearInterval(window.intSlideshow);

     //delete window.intSlideshow;

     if ($("#slides > div").length >= intIndex)
      {
       $("#slideshow").scrollTo({left: (intIndex-1) * 720, top:0}, 300);
       
       window.intSlide_Index = intIndex;
      }

     window.intSlideshow = window.setInterval('slideshow(1);', 7500);
    }

   if ($("#slides > div").length >= window.intSlide_Index)
    {
     $(".headeroverlay").animate({opacity:0});
     $($(".headeroverlay")[window.intSlide_Index-1]).animate({opacity:.33});
    }
  }

 window.intItem = 1;

 function itemswitch()
  {
   if (!window.intItem || window.intItem >= window.intItem_Total)
    {
     window.intItem = 0;
    }

   window.intTest = 1;

   window.clearTimeout(window.intHome);
   window.intHome = null;

   $.post(window.strPostURL + "/home",
          {
           action: "item.request",
           index:  window.intItem,
           ajax:   true
          },
          function (strHTML)
           {
            if (window.intTest === 1)
             {
              $("#home_top > div").animate({opacity:0}, function()
               {
                $("#home_top").html(strHTML);

                $("#home_icon > div").attr("style", "background-position: left;");
                $($("#home_icon > div")[window.intItem]).attr("style", "background-position: right;");
                $(".items a, .itemtable a").attr("style", "color:white;");


                updateIcon();

                $("#home_top > div").animate({opacity:1});

                window.intItem++;
                
                window.intHome = window.setTimeout('itemswitch();', 7500);
               });
             }
             window.intTest++;
           });
     }

 function updateIcon()
  {
   if ($.browser.msie && parseInt($.browser.version, 10) <= 7)
    {
     $("#home_icon").css("margin-top", 59);
    }   
  }

 $(window).ready(function()
  {
   if (document.all)
    {
     $(".slidesubtitle").parent().attr("style", "margin-top: 10px;margin-left:-5px;");
    }
    
   var objImg = $("img");

   for (var intImage = 0; intImage < objImg.length; intImage++)
    {
     if ($(objImg[intImage]).attr("src"))
      {
       $(objImg[intImage]).attr("src", $(objImg[intImage]).attr("src").replace("../../../.", ""));
      } 
    }

   var objA = $("a");

   for (var intA = 0; intA < objA.length; intA++)
    {
     if ($(objA[intA]).attr("href"))
      {
       $(objA[intA]).attr("href", $(objA[intA]).attr("href").replace("../../../.", ""));
      }
    }
    
   updateIcon();

   $("#home_top").hover(function()
    {
     window.clearInterval(window.intHome);
    },
    function()
     {
      window.intHome      = window.setTimeout('itemswitch();', 7500);
     });

   $(".items a").parent().click(function()
    {
     window.location = $("a", this).attr("href");
    });

   if ($("#slideshow").length == 1)
    {
     window.intSlideshow = setInterval('slideshow(1)', 7500);
    }

   updateContentHeight();
   updateContentHeight(true);

/*    $("#advies, #promotie, #organiseren").hover(function()
    {
     $("div[name='" + this.id + "']").attr("style", "background-position: right;");
    },
    function()
     {
      $("div[name='" + this.id + "']").attr("style", "background-position: left;");
     }); */

   if ($.browser.msie)
    {
     if (parseInt($.browser.version) == 7) /* browser corrections... */
      {
       $("#home_top .image").attr("style", "position: inline; margin-left: 0;");
       
       $("#template .icon").attr("style", "margin-top: -34px;");
       
       $("#template .main").attr("style", "width: 750px;");
      }
    }

   $(".information > div").mouseover(function()
    {
     $("#home_icon div[name='" + $(this).attr("id") + "']").addClass("active");
    });

   $(".information > div").mouseout(function()
    {
     $("#home_icon div[name='" + $(this).attr("id") + "']").removeClass("active");
    });

   $("#home_middle .text").click(function()
    {
     window.location = $(this).parent().children(".readon").attr("href");
    });

    updateSlider();

    $("#news .left").click(function()
     {
      var intPage = parseInt($("#news").attr("firstitem"));

      if (intPage && intPage > 1)
       {
        $.post(window.strPostURL + "/ajax",
               {
                action: "news.item.previous",
                page:   intPage - 1,
                ajax:   true
               },
               function (strHTML)
                {
                 if (strHTML != "false")
                  {
                   $("#news .content > div").fadeOut("fast", function()
                    {
                     $("#news .content").html($($(strHTML).find(".content").html()).fadeIn("fast"));
                     
                     updateSlider();                   
                    });

                   if (intPage)
                    {
                     $("#news").attr("firstitem", intPage - 1);
                    }
                  }
                });
        }
     });
     
    $("#news .right").click(function()
     {
      var intPage = parseInt($("#news").attr("firstitem"));

      if (!intPage)
       {
        intPage = 1;
       }

      $.post(window.strPostURL + "/ajax",
             {
              action: "news.item.next" ,
              page:   intPage + 1,
              ajax:   true
             },
               function (strHTML)
                {
                 if (strHTML != "false")
                  {
                   $("#news .content > div").fadeOut("fast", function()
                    {
                     $("#news .content").html($($(strHTML).find(".content").html()).fadeIn("fast"));
                     
                     updateSlider();
                    });
  
                   if (intPage)
                    {
                     $("#news").attr("firstitem", intPage + 1);
                    }
                  }
              });
     });



   if ($("#template[name='home']").length > 0)
    {
     $.post(window.strPostURL + "/ajax",
            {
             action: "item.request",
             ajax:   true
            },
            function (strHTML)
             {
              window.intItem_Total = parseInt(strHTML);

              if (window.intItem_Total > 1)
               {
                window.intHome = window.setInterval('itemswitch();', 7500);
               }
             }); 
    }
    
   var objTextblock = $(".textblock, .text_container");
   var intHeight    = 440;
   var intBuffer    = 0;

   for (var intTextblock = 0; intTextblock < objTextblock.length; intTextblock++)
    {
     intBuffer = $(objTextblock[intTextblock]).height() + 20;
     
     if (intBuffer > intHeight)
      {
       intHeight = intBuffer;
      }
    }

   objTextblock.css("height", intHeight + "px");

   if ($("#twitterfeed")[0])
    {
     $.getScript('http://api.twitter.com/1/statuses/user_timeline.json?include_rts=true&user_id=293914775&count=2&callback=twitterCallback2');
    }
  });

 window.intAddition = 0;

 function updateSlider()
  {
   $("#news .item").hover(function() /*#template .main .slider, .text_container, */
     {
      var elmElement = $(this).find(".text");

      if (window.intNews_Timeout && window.intNews_Timeout > 0)
       {
        updateContentHeight(true, parseInt(parseInt(elmElement[0].scrollHeight) - 100) - 50);

        $("#news .text").animate({height:100});
       }
      else
       {
        updateContentHeight(true, parseInt(parseInt(elmElement[0].scrollHeight) - 100) - 50);
       }

      window.intNews_Timeout = window.clearTimeout(window.intNews_Timeout);

      elmElement.animate({
                          height: elmElement[0].scrollHeight
                         });
     },
    function()
     {
      window.intNews_Timeout = window.setTimeout("News_Item_Restore(" + $(this).attr("name") + ");", 1000);
     });
  }

 function News_Item_Restore(intIndex)
  {
   var elmElement = $("#news .item[name='" + intIndex + "']");

   $(".text", elmElement).animate({
                                   height: 100
                                  }, "fast");

   updateContentHeight(true, -100);
   window.intAddition = 0;

   window.intNews_Timeout = window.clearTimeout(window.intNews_Timeout);
  }

 function updateContentHeight(blnAnimate, intExtra, blnHeight)
  {
   switch ($("#template").attr("name"))
    {
     case "1":
      var intText = Math.max($(".main > div")[0].clientHeight, $(".main > div")[1].clientHeight, $(".main > div")[2].clientHeight);

      var intHeight = $(".header").height() + 100 + intText + 110;
      break;

     case "2":
      var intHeight = $(".header").height() + $("#template .main > div:last-child")[0].clientHeight;

      if ($("#slides").length > 0)
       {
        intHeight += 460;
       }
      break;

     case "3":
     case "algemeen":
      var intHeight = $(".header").height() + $("#template .main > div:first-child")[0].clientHeight + 160;
      break;

     case "home":
      var intHeight = $("#home").height() + 50;
      break;

     case "news":
      var intHeight = $("#template").height() + 150;
      break;

     default:
      var intHeight = $("#template").height() + 30;
      break;
    }

   if (blnAnimate)
    {
     if (intExtra)
      {
       intHeight = intHeight + intExtra;
      }

     if (intHeight < 830)
      {
       intHeight = 830;
      }

     $("#content").animate({
                            height: intHeight + "px"
                           });
    }
   else
    {
     if (blnHeight)
      {
       if (intExtra)
        {
         return blnHeight + intExtra;
        }

       return intHeight;
      }
     else
      {
       $("#content").height(intHeight);
      }
    }
  }

 function info_show(intMain_ID, intSub_ID)
  {
   if (window.intInfo)
    {
     clearTimeout(window.intInfo);
    }

   var strID = "#extra_" + intMain_ID + "_" + intSub_ID;

   var intHeight = updateContentHeight(false, 0, true);
   intHeight -= 100 + 68 + 42;
   $("#sidebar_overlay").height(intHeight);

   $("#sidebar_arrow").fadeOut("fast");
   $("#sidebar_overlay").fadeOut("fast");

   setTimeout('info_show_view("' + strID + '", ' + (window.event.clientY + document.body.scrollTop - 10) + ');', 100);
  }
  
 function info_show_view(strID, intY)
  {
   $("#sidebar_overlay").html($(strID).html());

   $("#sidebar_overlay").fadeIn("fast");

   $("#sidebar_arrow").attr("style", "display: block; top: " + intY + "px");
   $("#sidebar_arrow").fadeIn("fast");
  }

 function info_hide(intMain_ID, intSub_ID)
  {
   window.intInfo = setTimeout('$("#sidebar_overlay").fadeOut("slow"); $("#sidebar_arrow").fadeOut("fast");', 3000);
  }

/*
 Twitter
*/
function twitterCallback2(twitters)
 {
  if (twitters[0])
   {
    var i = 0;
    var strExtra = "";

    for (var i = 0; i < 2; i++)
     {
      var username   = twitters[i].user.screen_name;
      var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
        return '<a href="'+url+'">'+url+'</a>';
      }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
        return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
      });

      if (i > 0)
       {
        strExtra = ' style="margin-left:60px; margin-top:-15px;"';
       }

      $("#twitterfeed").append('<div'+strExtra+'><span>'+status+'</span><br /><a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+relative_time(twitters[i].created_at)+'</a></div>');
     }
   }
}

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return 'minder dan een minuut geleden';
  } else if(delta < 120) {
    return 'ongeveer een minuut geleden';
  } else if(delta < (60*60)) {
    return (parseInt(delta / 60)).toString() + ' minuten geleden';
  } else if(delta < (120*60)) {
    return 'ongeveer 1 uur geleden';
  } else if(delta < (24*60*60)) {
    return 'ongeveer ' + (parseInt(delta / 3600)).toString() + ' uur geleden';
  } else if(delta < (48*60*60)) {
    return '1 dag geleden';
  } else {
    return (parseInt(delta / 86400)).toString() + ' dagen geleden';
  }
}
