function RegisterCufon() {
    Cufon.replace('h2', { fontFamily: 'NotesSoft-Medium' });
    Cufon.replace('h3', { fontFamily: 'NotesSoft-Medium' });
    Cufon.replace('h4', { fontFamily: 'NotesSoft-Regular' });
    Cufon.replace('h6', { hover: true, hoverables: { h6: true, a: true} });
    Cufon.replace('h5', { hover: true, hoverables: { a: true} });
}

$(document).ready(function() {

    ClearInput();

    InitSliders();


    SimpleSlider(
      $("div.work div.slider"),
      $("div.work div.slider a.arrow_left"),
      $("div.work div.slider a.arrow_right")
   );


    InitFix();

    InitTeam();


    // KLANTEN HOVER
    if ($("div.customers").length > 0) {
        var ti = "<h3>" + $("div.customers div.bird_text h3").text() + "</h3>";
        $("div.customers div.bird_text h3").remove();
        var def_cust_html = ti + $("div.customers div.bird_text").html();
        $("div.customers div.bird_text").html(def_cust_html);

        $("div.logos_slider li .cont .info").hide();

        $("div.logos_slider li .cont .sub").mouseover(function() {
            var title = "<h3>" + $(this).parent().find("div.header").text() + "</h3>";
            var teaser = $(this).parent().find("div.teaser").html();
            //var img = $(this).find("img");
            var img = $(this).parent().find("div.secondimage img").attr("src");
            
            //$("div.customers div.blue_bird_text div.bird img").attr("src", img.attr("src"));
            $("div.customers div.blue_bird_text div.bird img").attr("src", img);
            $("div.customers div.bird_text").html(title + teaser);

            RegisterCufon();
        });

        $("div.logos_slider li .cont .sub").mouseout(function() {
            $("div.customers div.bird img").attr("src", "/img/transparent_gif.gif");
            $("div.customers div.bird_text").html(def_cust_html);

            RegisterCufon();
        });
    }

    RegisterCufon();

    // fix for klients slider at the right side (werk.aspx page)
    if ($("div.absolute_arrows div.slider ul li").length > 0)
            $("div.absolute_arrows div.slider ul li").css("display", "block");
            
            
    $("#commentsDiv").hide();
    $(".commentsHeader").click(function() {
        if ( $("#commentsDiv").css("display") == "none")
            $("#commentsDiv").show();
        else
            $("#commentsDiv").hide();
        
        return false;
    });        
    
    
    $("#commentsDivContent").hide();
    $(".commentsHeader").click(function() {
        if ( $("#commentsDivContent").css("display") == "none")
            $("#commentsDivContent").show();
        else
            $("#commentsDivContent").hide();
        
        return false;
    });      
   
});
 
 
 
 
 function ClearInput() 
 {
    // Call back form
     $("div.call_back input[type='text']").focus(function() {

         $(this).css("color", "#58585A");         

         if ($(this).val().indexOf('naam ...') != -1 ||
            $(this).val().indexOf('e-mail ...') != -1 ||
            $(this).val().indexOf('telefoonnummer ...') != -1) {
             $(this).val('');
         }
     });
     
    
    // Contact form
    $("div.contact_form div.form input[type='text'], div.contact_form div.form textarea").focus(function() 
    {
        if ($(this).val().indexOf('naam ...') != -1 ||
            $(this).val().indexOf('bedrijf ...') != -1 ||
            $(this).val().indexOf('e-mail ...') != -1 ||
            $(this).val().indexOf('type hier een bericht ...') != -1) 
            {
                $(this).val('');
            }
    });    
    
    // Search form
    $("div.search input[type='text']").focus(function() {
        if ($(this).val().indexOf('zoeken ...') != -1) {
            $(this).val('');
        }
    });    
 } 
 
 
 
 function SimpleSlider(slider, prev, next) {     
 
    var len = slider.find("ul li").length;
    
    if (len > 1) {

        var fadeAll = true;

        $("div.team div.about_team ul li").each(function() {
            if ($(this).hasClass("active")) {          
            //    $(this).removeClass("active");
                fadeAll = false;
            }
        });

        if (fadeAll) { 
           slider.find("ul li").not(":first").fadeOut("normal");
        }            

        next.click(function() {
            var idShow = -1;
            // get index of el to show
            slider.find("ul li").each(function() {
                if ($(this).css("display") != 'none') {
                    idShow = slider.find("ul li").index($(this));
                    // reset id if current element is last item
                    if (idShow == len - 1) idShow = 0;
                    else idShow = idShow + 1;
                }
            }); // end each            

            // hide all except index
            slider.find("ul li").not(":eq(" + idShow + ")").hide();
            // show index
            slider.find("ul li").eq(idShow).show();

        });  // end next click
        
        
        prev.click(function() {
            var idShow = -1;
            slider.find("ul li").each(function() {                  
              if ($(this).css("display") != 'none') {                            
                idShow = slider.find("ul li").index($(this));
                if (idShow == 0) idShow = len - 1;
                else idShow = idShow - 1;
              }
          }); // end each          
            slider.find("ul li").not(":eq(" + idShow + ")").hide();            
            slider.find("ul li").eq(idShow).show();
        }); // end prev click

    } // end len if
 }
 
 
 
 
function InitSliders() 
{
   if ($("div.team div.people_slider").length > 0)
   {
      $("div.team div.people_slider").scrollable({ 
          api: true,
          size: 5,
          disabledClass: 'inactive'                          
      });


      $("div.team div.people_slider ul.items li").click(function() {

          ind = $("div.team div.people_slider ul.items li").index(this);

          if ($("div.team div.about_team ul li").eq(ind).length > 0) {
              $("div.team div.about_team ul li").hide();
              $("div.team div.about_team ul li").eq(ind).show();

              var name = $("div.team div.about_team ul li").eq(ind).find(".description b").eq(0).text();
              $("ul.breadcrumb li:last-child").text(name);
          }

          ShowPersonBlogLinks();
      });

      
      

      SimpleSlider(
          $("div.team div.about_team"),
          $("div.team div.arrows a.arrow_green_left"),
          $("div.team div.arrows a.arrow_green_right")
        );



      // about_team personal blog archvie
      $("div.team div.about_team ul li").not(".active").hide();
      var currName = $("div.team div.about_team ul li.active div.description b").text();


      if ($("div.archive").find("ul." + currName).length == 0) {
          $("h4.archive, div.archive").hide();
      }
      else {
          $("h4.archive, div.archive").show();
          $("div.archive ul").each(function() {
              if ($(this).attr("class") != currName) {
                  $(this).hide();
              }
          });
      }



      // update breadcrumb
      $("div.team .arrow_green_left, div.team .arrow_green_right").click(function() {
          $("div.team div.about_team ul li").each(function() {
              if ($(this).css("display") != 'none') {
                  var name = $(this).find(".description b").eq(0).text();
                  $("ul.breadcrumb li:last-child").text(name);
              }
          });
          ShowPersonBlogLinks();
      });
      
      
    }    
    
    if ($("div.logos_slider").length > 0) {
        $("div.logos_slider").scrollable({ 
              api: true,
              size: 4,
              disabledClass: 'inactive'    
        });
    }
}


function ShowPersonBlogLinks() 
{
    $("div.team div.about_team ul li").each(function() {
        if ($(this).css("display") != 'none') {
            var currname = trim($(this).find("div.description b").text(), " ");

            if ($("div.archive").find("ul." + currname).length == 0) {
                $("h4.archive, div.archive").hide();
            }
            else {
                $("h4.archive, div.archive").show();

                $("div.archive ul").each(function() {
                    if ($(this).attr("class") != currname) {
                        $(this).hide();
                    }
                    else {
                        $(this).show();
                    }
                });
            }
        }
    });
}


function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function InitFix() {

    $("div.newslist ul:first li:last, div.werklist ul:first li:last").addClass("last");

}


function InitTeam() 
{
    // team.aspx gallery
    /*$("div.team div.hardships ul li img.kaart").hide();

    $("div.team div.hardships ul li img").click(function() {
        if ($(this).parent().find("img.kaart").length > 0) {
            $(this).hide();
            $(this).parent().find("img").not($(this)).show();
        }
    });

    // if some li item has class active, click it
    $("div.team div.about_team ul li").each(function() {
        if ($(this).hasClass("active")) {            
            var indx = $("div.team div.about_team ul li").index(this);
            $("div.team div.people_slider ul.items li").eq(indx).click();
        }
    }); */

    $("div.team div.hardships ul li div.inf").hide();
    
    var kaart_data = $("div.team div.hardships ul li.kaart_data");

    $("div.team div.hardships ul li img.photo").mouseover(function() {
        var title = $(this).parent().parent().find("div.inf b").text();
        var role = $(this).parent().parent().find("div.inf span").text();
        kaart_data.find("td strong").text(title);        
        kaart_data.find("td span").text(role);

    });

    $("div.team div.hardships ul li img.photo").mouseout(function() {
        var title = $("div.hardships ul li").not(".kaart_data").eq(0).find("div.inf b").text();
        var role = $("div.hardships ul li").not(".kaart_data").eq(0).find("div.inf span").text();
        kaart_data.find("td strong").text(title);
        kaart_data.find("td span").text(role);

    });
}
