(function($)
{
   $.fn.buildheijmans = function(_options)
   {
      var options = {
         minHeight: 500,
         serviceOpen: false
      };

      if (_options) $.extend(options, _options);
      var minHeight = 500;
      $(".menu #ulmenu > li").each(function()
      {
         if ($('ul', this).length > 0)
         {

            var thisPos = $(this).position().left;

            var thisWidth = $(this).outerWidth();
            thisWidth /= 2;
            var ulWidth = $('ul', this).outerWidth();
            var ulWidth2 = ulWidth / 2;
            var leftPos = thisPos - ulWidth2 + thisWidth;
            if (leftPos <= 0)leftPos = 0;
            $('ul', this).css({'left':leftPos,'width':ulWidth});
         }

      });
      $(".menu #ulmenu > li").hover(
            function()
            {
               if (!$(this).hasClass('selected'))
               {
                  $(this).addClass('show-submenu');
                  $('#ulmenu li.selected ul').hide();
               }
            },
            function()
            {

               $(this).removeClass('show-submenu');
               $('#ulmenu li.selected ul').show();
            }
            );
      var ec_info = $('.rightcolumn .ecinfo').text();
      if (ec_info != "")
      {
         $("#ul_rightcolumn").show();
         $("#ul_rightcolumn > li").hover(
               function()
               {
                  $(this).addClass('show-submenu');
               },
               function()
               {
                  $(this).removeClass('show-submenu');
               }
               );
      }

      //de3 scahduwrandjes moeten goede hoogte krijgen

      function resizeContentHeight()
      {
         var h = $('.content-left').outerHeight(true);
         var hh = $('.content').outerHeight(true);
         var deHoogte = 0;
         if (h < hh)deHoogte = hh;
         else deHoogte = h;
         if (deHoogte < options.minHeight)
         {

            $('.content-right').height(options.minHeight);

         }
         else $('.content-right').height(deHoogte);


      }
      $('#service-hideshow').click(
            function()
            {
               if ($('#id_serviceblock').is(':hidden'))
               {
                  $('#id_serviceblock').slideDown("", resizeContentHeight);

                  $('#imgid_servicedicht').hide();
                  $('#imgid_serviceopen').show();
                  $('#imgid_servicedriehoekdicht').hide();
                  $('#imgid_servicedriehoekopen').show();
               }
               else
               {
                  $('#id_serviceblock').slideUp("", resizeContentHeight);
                  $('#imgid_serviceopen').hide();
                  $('#imgid_servicedicht').show();

                  $('#imgid_servicedriehoekopen').hide();
                  $('#imgid_servicedriehoekdicht').show();
               }
            }
            );
      /* zet speciale class om interesse */
      $('.menu li > a[href=/interesse]').addClass('a-interesse');
      $('.menu li ul li a[href=/interesse]').removeClass('a-interesse');
      /* als li menuItem GEEN name='servicebox' heeft , dan gaat de service box dicht */
      /* name='servicebox' voor menuItem zetten in xsl/common/serviceMenu */
      /* SERVICE menu standaard closed , dus geen check om het te verbergen */
      if(!options.serviceOpen){
         if (!$('li[name=servicebox]').hasClass('selected'))$('#id_serviceblock').hide();
      }

      $('#tweet-hideshow').toggle(
            function()
            {
               $('#id_tweet').slideUp("", resizeContentHeight);
               $('#imgid_twitteropen').hide();
               $('#imgid_twitterdicht').show();

            },
            function()
            {
               $('#id_tweet').slideDown("", resizeContentHeight);
               $('#imgid_twitteropen').show();
               $('#imgid_twitterdicht').hide();

            }
            );

      //twitter
      function tweetGeladen()
      {
         $(".tweet .tweet_text a").attr('rel', 'external');
         resizeContentHeight();
      }
      /* tweet script moet geladen zijn */
      if($.isFunction($(".tweet").tweet)){
         $(".tweet").tweet({
            username: "HeijmansNL",
            avatar_size: null,
            count: 2,
            intro_text: null,                       // [string]   do you want text BEFORE your your tweets?
            outro_text: null,                       // [string]   do you want text AFTER your tweets?
            join_text:  null,
            auto_join_text_default: "",
            auto_join_text_ed: "",
            auto_join_text_ing: "",
            auto_join_text_reply: "",
            auto_join_text_url: "",
            loading_text: "loading tweets..."
         }).bind('loaded', tweetGeladen);
      }

      resizeContentHeight();
   };
})(jQuery);

