Cufon.replace('#navigation li a',       { fontFamily: 'franklin', hover: true });
Cufon.replace('#subnavigation li a',    { fontFamily: 'franklin', hover: true });
Cufon.replace('#sidebar .name',         { fontFamily: 'franklin' }); 
Cufon.replace('.login-search .tabs a',       { fontFamily: 'SegoePrint' });
Cufon.replace('.quote .txt',            { fontFamily: 'SegoePrint' });  
Cufon.replace('.quote .quote-content-top a',       { fontFamily: 'SegoePrint' });  
Cufon.replace('.quote .quote-content-bottom a',       { fontFamily: 'SegoePrint' });  
Cufon.replace('.login-search .tabs a',       { fontFamily: 'SegoePrint' });  
Cufon.replace('h1.sf',                  { fontFamily: 'SegoePrint' });  
Cufon.replace('.btn_send',                  { fontFamily: 'SegoePrint' });  

$(window).load(function() { 
    if($.browser.msie && $.browser.version < 7){
        //$("#site-container").pngFix();
    }
});

$(document).ready(function() {
	//$(window).trigger("resize");
    
            //var a = "http://www.youtube.com/watch?v=kgVEScrhldI";
            //alert(a.replace(new RegExp("watch\\?v=", "i"), 'v/'));
   
    
	$(".hide").hide();

    if($('img.tooltip').length > 0) {
        $('img.tooltip').tooltip({
                track: true,
                delay: 0,
                showURL: false,
                bodyHandler: function() {
                    return $($(this).prev('.tooltipTxt')).html();
            }
        });
    }
    
    if($("ul.subsubsubnavigation").find("li").length == 0) {
        $("ul.subsubsubnavigation").hide();    
    }
 
    
    $("a.lightbox-youtube").click(function() {
        $.fancybox({
            'overlayOpacity'  :  0.7,
            'overlayColor'    :  '#000',
            'zoomSpeedIn'     :  500,
            'zoomSpeedOut'    :  500,
            'centerOnScroll'  :  true,
            'hideOnContentClick' : false,   
            'padding'        : 0,
            'autoScale'        : false,
            'transitionIn'    : 'none',
            'transitionOut'    : 'none',
            'title'            : this.title,
            'width'        : 680,
            'height'        : 495,
            'href'            : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'            : 'swf',
            'swf'            : {
                    'wmode'        : 'transparent',
                'allowfullscreen'    : 'true'
            }
        });

        return false;
    });  
    


    if($('ul.image-block li').length > 0){
      $('ul.image-block li').each(function(){
        $('ul.image-block').append($(this));
      });

      $('ul.image-block a').each(function(){
        if(!$(this).hasClass('lightbox')){
          $(this).remove();
        }
      });
    }

    $('.item-form').css({'height':'0px','overflow':'hidden'});
    $('.item-form').prev('div.name').css('cursor','pointer');
    $('.item-form').prev('div.name').click(function(){
        showBlock();
    });
    $('#form_container').css('visibility','hidden');

    $(".sb-block").each(function(){

        var Items = $(this).find(".item");
        var bSubSubNavigationBlock = false;
        var bFormBlock             = false;

        if($(this).find("#subsubnavigation").length > 0) {
            bSubSubNavigationBlock = true;
        }

        if($(this).find(".item-form").length > 0) {
            bFormBlock = true;
        }

        // check for SubSubnavigation
        if(!bSubSubNavigationBlock && !bFormBlock)
        {
            // check if downloads available
            if(Items.length == 0) {
                $(this).remove();
            } else {
                // check if images available
                if(Items.find("ul").length > 0) {
                    if(Items.find("ul li").length == 0){
                        $(this).remove();
                    }
                }
            }
        }
    }); 
    
    setLightbox();   

});


function setLightbox() {
    $("a.lightbox").fancybox({
        'overlayOpacity'  :  0.7,
        'overlayColor'    :  '#000',
        'zoomSpeedIn'     :  500,
        'zoomSpeedOut'    :  500,
        'centerOnScroll'  :  true,
        'hideOnContentClick' : false
    });    
}

function setTooltip(oSelector) {     
    oSelector.tooltip({
      track: true,
      delay: 0,
      showURL: false,
      bodyHandler: function() {     
        return $($(this).prev(".spanTooltip")).html(); 
      }
   });
} 

/**
*    vCenterContent              - center content vertical inside container
*    @param: 'Selector'          - Selector of content that has to be centered
*    @param: 'ContainerHeight'   - Height of selector container
*/
function vCenterContent(Selector, ContainerHeight)
{
    var ContainerHeight = ContainerHeight;
    var oElement = $(Selector);

    oElement.each(function(){
        var PaddingVal = (ContainerHeight - $(this).height()) / 2 + "px 0px";
        $(this).attr("style", "padding: " +  PaddingVal);
    });
}

/**
*    moveFirstItemToLastPosition - eg. put first li to the last position
*    @param: 'oElement'          - Current element
*/
function moveFirstItemToLastPosition(oElement) {
    oElement.parent().append(oElement);
}

function setContentLiElements(oContainer, Action) {
    
    var LiCount = oContainer.find("ul li").length;
    
    if(LiCount > 0) {
    
        var activeElement = oContainer.find("ul li.active");
        var PreviousCount = activeElement.prev().length;
        var NextCount     = activeElement.next().length;
        
        if(activeElement.length > 0) {
            switch(Action)
            {
                case "prev" : 
                {
                    activeElement.removeClass("active"); 
                    if(PreviousCount != 0) {
                        activeElement.prev().addClass("active");        
                    }
                } 
                break;
                
                default : //next
                {
                    activeElement.removeClass("active"); 
                    if(NextCount == 0) {
                        oContainer.find("ul li:first").addClass("active");        
                    } else {
                        activeElement.next().addClass("active");  
                    }
                } 
                break;   
            }
            
            setControlLiElements(oContainer);  
            
        } else {
            oContainer.find("ul li:first").addClass("active");    
        }
    }
} 

function setControlLiElements(oContainer) {       
    activeElement = oContainer.find("ul li.active");
    PreviousCount = activeElement.prev().length;
    NextCount     = activeElement.next().length;        

    PrevElement   = oContainer.find("a.prev");
    NextElement   = oContainer.find("a.next");

    if(PreviousCount == 0) {
        PrevElement.hide();    
    } else {
        PrevElement.show();
        PrevElement.unbind("click"); //reset click
        PrevElement.click(function(){
            setContentLiElements(oContainer, "prev");   
        });
    }

    if(NextCount == 0) {
        NextElement.hide();    
    } else {
        NextElement.show();
        NextElement.unbind("click"); //reset click 
        NextElement.click(function(){
            setContentLiElements(oContainer, "next"); 
        });    
    }
}


function showLiElement(oContainer, Action) {
    var activeElement = oContainer.find("ul li.active");
    
    switch(Action)
    {
        case "prev" :
        {       
            oContainer.find("ul li").removeClass("active");   
            activeElement.prev().addClass("active");         
        }
        break;
        
        default : //next
        {
            oContainer.find("ul li").removeClass("active");     
            activeElement.next().addClass("active"); 
        }
        break;
    }    
}


/**
*    SetActiveSubSubNavigation  - Function for setting the subsubnavigation active based on the url (weggebruikers, hot issues)
*/
function SetActiveSubSubNavigation() {
    if($("#subsubnavigation li").length > 0)
    {
        var documentUrl = document.URL;
        var aUrlParts   = documentUrl.split("/");

        if(aUrlParts[aUrlParts.length-1] == "") {
            aUrlParts.pop();
        }

        var CurrentItem = aUrlParts[aUrlParts.length-1];
        var CurrentItemLength = CurrentItem.length;

        $("#subsubnavigation li a").each(function() {           
            var HrefLength = $(this).attr("href").length;
            var Str = $(this).attr("href").substr(HrefLength-CurrentItemLength,HrefLength);
            if(Str == CurrentItem) {
                $(this).parent().addClass("current");
            }
        });
    }
}

/**
* showSubsidyForm   - slideIn subsidy form, hides the others
*	@param: 'Element' - the current element
*	@param: 'DivId'   - this DivId slides in
*/
function showSubsidyForm(ElementId, DivId) {
	var SlideDiv       = $("#" + DivId);
	var ElementDiv     = $("#" + ElementId);
	var AnimatingClass = "animating";

	if(!ElementDiv.hasClass(AnimatingClass)) {
		ElementDiv.addClass(AnimatingClass);
		SlideDiv.slideToggle(300, function(){ ElementDiv.removeClass(AnimatingClass); });

        var ImgArrow = ElementDiv.find("img.icon.arrow");
        if(ImgArrow.attr("src") == WebUrl + "pics/icons/icon_arrow_up.png") {
            ImgArrow.attr("src", WebUrl + "pics/icons/icon_arrow_down.png");    
            
            //$("#list .errorMsg.subsidy img").fadeIn("100");
        } else {
            //$("#list .errorMsg.subsidy img").fadeOut("0");
            ImgArrow.attr("src", WebUrl + "pics/icons/icon_arrow_up.png"); 
        }
	}
}

/**
* SetRowColors, function for setting the background color of even and uneven rows in form
*/

function SetRowColors(ContainerElement) {
    var EvenClassName = "even";
    var OddClassName = "uneven";

    $(".rowcolors").each(function(){
        $(this).find(".row:even").addClass(EvenClassName);
        $(this).find(".row:odd").addClass(OddClassName);
    });
}

function SetRowHighlight() {
    var HightlightClassName = "hover";


    $(".highlight .row").each(function(){
        /*
        var _this = $(this);

        $(this).mouseover(function(){
            _this.addClass(HightlightClassName);
        });

        $(this).mouseout(function(){
            _this.removeClass(HightlightClassName);
        });
        */


        $(this).hover(
            function(e) {
                $(this).addClass(HightlightClassName);
                //e.preventDefault();
            },
            function(e) {
                $(this).removeClass(HightlightClassName);
                //e.preventDefault();
            }
        );

    });
}


function showBlock(){
  var FormContainer = $('.item-form');
  var FormContainerDiv = $('#form_container');
  var ArrowContainer = $('.name .arrow');
  if(FormContainer.css('height') == '0px'){
    FormContainer.css({'border': '1px solid #bfbfbf'});
    var Height = FormContainerDiv[0].scrollHeight;
    FormContainer.animate({
      height: Height
    }, function(){
      FormContainerDiv.css('display','none');
      FormContainerDiv.css('visibility','visible');
      FormContainerDiv.fadeIn("slow");
      ArrowContainer.html('<img src="/pics/arrow-up.gif" alt="" />');
      return true;
    });
  } else {
    var Height = FormContainerDiv[0].scrollHeight;
    FormContainerDiv.fadeOut("slow",function(){
      FormContainerDiv.css('display','block');
      FormContainerDiv.css('visibility','hidden');
      FormContainer.animate({
        height: '0px'
      }, function(){
        ArrowContainer.html('<img src="/pics/arrow-down.gif" alt="" />');
        FormContainer.css({'border': '0px solid #bfbfbf'});
        return true;
      });

    });
  }
}

function actieplan_hidePlanning(Element) { 
    Element.css("display","none");
}

function actieplan_showPlanning(Element) { 
    Element.css("display","block"); 
}

function CheckfollowUpQuestion(ElementValue, ChildNumber, TriggerValue) { 

    if(ElementValue == TriggerValue) {
        $("#fu" + ChildNumber).show();
    } else {
        $("#fu" + ChildNumber).hide();
    }    
}




function clear_inputfield(Selector, defaultVal, bPasswordField) {
    if($(Selector).length > 0) {
        if($(Selector).val() == defaultVal) {
            $(Selector).val("");
            
            if(bPasswordField) {
                $(Selector).next("input[type=password]").show();    
                $(Selector).hide(); 
                $(Selector).next("input[type=password]").focus();
                   
                
                $(Selector).next("input[type=password]").bind("blur", function() {
                    if($(this).val() == "") {
                        $(this).prev("input[type=text]").show();    
                        $(this).hide();
                    }
                });
            }
        } else {
            if($(Selector).val() == "") {
                $(Selector).val(defaultVal);        
            }    
        }        
    }        
}

function switchHeaderTabs(Element, Type) {
    $("#header .login-search .tabs li").removeClass("active");
    $(Element).parent().addClass("active");
    
    var bAnimate = false;
    
    switch(Type)
    {
        case "login" : 
        {
            if($("#header .tab-content.login").css("display") == "block") {
                var bAnimate = true;    
            }
            $("#header .login-search").css("background-image", "url(" + WebUrl + "pics/tab_login_active.png)");
            $("#header .tab-content.search").hide();
            $("#header .tab-content.login").show();
        } break;
        
        case "search" : 
        {   
            if($("#header .tab-content.search").css("display") == "block") {
                var bAnimate = true;    
            }
            
            $("#header .login-search").css("background-image", "url(" + WebUrl + "pics/tab_search_active.png)");
            $("#header .tab-content.login").hide();
            $("#header .tab-content.search").show();         
        } break;
    }
    
    var innerHeight = $('#header .login-search').innerHeight();
    
    if(bAnimate || innerHeight < 73) {
        if(innerHeight < 73){
            $('#header .login-search').animate({ height : '73px' }, function(){});
        } else {
            $('#header .login-search').animate({ height : '22px' }, function(){});
        }
    }
    
    Cufon.refresh();
}

var bFirstYoutube = true;

function FetchYouTubeMovie ( VideoId, DivForYouTube, Autoplay ){
  if(VideoId != ''){
    var UrlCheckResult;
    if(bFirstYoutube) {
      Autoplay = '0';
      bFirstYoutube = false;
    }
    
    var CorrectUrl = "http://www.youtube.com/v/"+VideoId+"&autoplay=" + Autoplay + "&rel=0"; 
  
    if(VideoId.search('youtube.com') == -1){
      $(DivForYouTube).html('<object width="300" height="210"> \
                            <param name="movie" value="' + CorrectUrl + '"></param> \
                            <param name="wmode" value="transparent"></param> \
                            <embed src="' + CorrectUrl + '" type="application/x-shockwave-flash" wmode="transparent" width="300" height="210"></embed> \
                          </object> \
                          ');
    }
                                
  }
}

function GetYouTubeScreen( Url, Title ) {
  if(Url === null){ 
    return ""; 
  }
  
  var VideoId;
  var Results;

  Results = Url.match("[\\?&]v=([^&#]*)");

  VideoId = ( Results === null ) ? Url : Results[1];
  
  return '<a href="javascript:void(0);" class="youtube-link" title="' + Title + '" onclick="FetchYouTubeMovie(\'' + VideoId + '\', \'#youtube-movie\', \'1\');"><img src="http://img.youtube.com/vi/' + VideoId + '/2.jpg" alt="' + Title + '" title="' + Title + '" /></a>';
}

function ShowYoutube( VideoId ) {
  
}


function loadNavigationFromImanager(AElement, NavigationUrl) {
    $("#navigation li").removeClass("current");
    $(AElement).parent().addClass("current");
    
    $.ajax({
      url: NavigationUrl,
      success: function(data) {
        $('#subnavigation').html(data);
        $('#subnavigation a:first').trigger("click");
        Cufon.refresh();
      }
    });     
}

function loadContentFromImanager(AElement, ContentUrl) {
    $("#subnavigation li").removeClass("current");
    $(AElement).parent().addClass("current");
    
    $('#content').html(
            "<div class='blocks'>"
        +       "<div class='round_top'><div class='white'>&nbsp;</div></div>"
        +       "<div class='block_content white'><img src='/v2/pics/ajax-loader.gif' alt='loading...' /></div>"
        +       "<div class='round_bottom'><div class='white'>&nbsp;</div></div>"
        +   "</div>"
    );
    
    $.ajax({
      url: ContentUrl,
      success: function(data) {
        $('#content').find(".block_content").html(data);
      }
    });    
}   
