$(document).ready(function () {


    //plaatsen van default zoekterm
    $('.col-3-3 .FTSHome input').val("typ zoekterm");
    $('.col-3-3 .FTSHome input').click(function () {
        $(this).val("");
    });

    // tekst afkappen na ... caracters
    $('p.websiteAdres a').each(function (i) {
        if ($(this).text().length > 21) {
            var truncatedText = $(this).html().substring(0, 21) + '...';
            $(this).empty().html(truncatedText);
        }
    });


    /***************** aanklikbaar maken van Items ****************/
    /*** nieuwsItem homepage ***/
    /* leesverder button zichtbaar gemaakt, t. 2316 */
    //$('div.newsRepeaterItemHome a.button').hide();
    $('div.newsRepeaterItemHome').hover(function () {
        var i = $('div.newsRepeaterItemHome').index(this);
        $('div.newsRepeaterItemHome').eq(i).addClass("listPageHoverHome");
    }, function () {
        $(this).removeClass('listPageHoverHome');
    });

    $('div.newsRepeaterItemHome:first').click(function () {
        var hLinkFirstNewsItemHomePage = $(this).find('a.button').attr('href');
        document.location = hLinkFirstNewsItemHomePage;
    });


    /*** nieuwsItem ***/
    /* leesverder button zichtbaar gemaakt, t. 2316 */
    //$('div.newsRepeaterItem a.button').hide();
    //$('div.newsRepeaterItem:odd').css("background-color", "#fafafa");
    $('div.newsRepeaterItem').hover(function () {
        var i = $('div.newsRepeaterItem').index(this);
        $('div.newsRepeaterItem').eq(i).addClass("listPageHover");
    }, function () {
        $(this).removeClass('listPageHover');
    });


    $('div.newsRepeaterItem').click(function () {
        var i = $('div.newsRepeaterItem').index(this);
        var currentHref = $('div.newsRepeaterItem a.button').eq(i).attr('href');
        document.location = currentHref;
    });


    /*** zoekitem ***/
    /* leesverder button zichtbaar gemaakt, t. 2316 */
    //$('div.searchResult a.button').hide();
    //$('div.searchResult:odd').css("background-color", "#fafafa");
    $('div.searchResult').hover(function () {
        var i = $('div.searchResult').index(this);
        $('div.searchResult').eq(i).addClass("listPageHover");
    }, function () {
        $(this).removeClass('listPageHover');
    });


    $('div.searchResult').click(function () {
        var i = $('div.searchResult').index(this);
        var currentHref = $('div.searchResult a.button').eq(i).attr('href');
        document.location = currentHref;
    });


    /*** home page    ***/
    //$('div.newsRepeaterItemHomeSimple:even').css("background-color", "#fafafa");


    /*** woningaanbod ***/

    /* rijen om en om een background kleur geven */
    //$('.extendedProjectRepeaterItemKoop:odd').css("background-color", "#fafafa");

    /* leesverder button zichtbaar gemaakt, t. 2316 */
    //$('div.extendedProjectRepeaterItemKoop a.button').hide();

    /* andere kleur als je met de muis hovert */
    $('div.extendedProjectRepeaterItemKoop').hover(function () {
        var i = $('div.extendedProjectRepeaterItemKoop').index(this);
        $('div.extendedProjectRepeaterItemKoop').eq(i).addClass("listPageHover");
    }, function () {
        $(this).removeClass('listPageHover');
    });

    $('div.extendedProjectRepeaterItemKoop').click(function () {
        var i = $('div.extendedProjectRepeaterItemKoop').index(this);
        var currentHref = $('div.extendedProjectRepeaterItemKoop a.button').eq(i).attr('href');
        document.location = currentHref;
    });

    //$('div#projectRepeaterControl .itemnieuwbouw:odd').css("background-color", "#fafafa");


    /*** vrije sector huur ***/

    //$('div#extendedProjectRepeaterControlVrijeSectorHuur .item:odd').css("background-color", "#fafafa");

    $('div#extendedProjectRepeaterControlVrijeSectorHuur .item').hover(function () {
        var i = $('div#extendedProjectRepeaterControlVrijeSectorHuur .item').index(this);
        $('div#extendedProjectRepeaterControlVrijeSectorHuur .item').eq(i).addClass("listPageHover");
    }, function () {
        $(this).removeClass('listPageHover');
    });

    $('div#extendedProjectRepeaterControlVrijeSectorHuur div.item').click(function (e) {
        var i = $('div#extendedProjectRepeaterControlVrijeSectorHuur div.item').index(this);

        var currentHref = $('div#extendedProjectRepeaterControlVrijeSectorHuur div.item div.textWrapper a.projectUrl').eq(i).attr('href');

        if (currentHref == undefined || currentHref == "") {
            return;
        } else {
            window.open(currentHref, 'venster' + i, '', '');
            return false;
        }
    });


    /*** projectRepeaterControl (except for Nieuwbouw repeater en Garages/Bergingen repeater) ***/

    //$('div#projectRepeaterControl .item:odd').css("background-color", "#fafafa");


    $('div#projectRepeaterControl div.item').hover(function () {
        var i = $('div#projectRepeaterControl div.item').index(this);
        $('div#projectRepeaterControl div.item').eq(i).addClass("listPageHover");
    }, function () {
        $(this).removeClass('listPageHover');
    });


    $('div#projectRepeaterControl div.item').click(function (e) {
        var i = $('div#projectRepeaterControl div.item').index(this);
        var currentHref = $('div#projectRepeaterControl div.item p.websiteAdres a').eq(i).attr('href');

        if (currentHref == undefined) {
            currentHref = $('div#projectRepeaterControl div.item div.links a').eq(i).attr('href');
        }

        window.open(currentHref, 'venster' + i, '', '');
        return false;
    });


    /*** projectRepeaterControl Nieuwbouw  ***/


    $('div#projectRepeaterControl div.itemnieuwbouw').hover(function () {
        var i = $('div#projectRepeaterControl div.itemnieuwbouw').index(this);
        $('div#projectRepeaterControl div.itemnieuwbouw').eq(i).addClass("listPageHover");
    }, function () {
        $(this).removeClass('listPageHover');
    });

    $('div#projectRepeaterControl div.itemnieuwbouw').click(function (e) {
        var i = $('div#projectRepeaterControl div.itemnieuwbouw').index(this);
        var currentHref = $('div#projectRepeaterControl div.itemnieuwbouw p.websiteAdres a').eq(i).attr('href');
        if (currentHref == undefined || currentHref == '') {
            return;
        } else {
            window.open(currentHref, 'venster' + i, '', '');
            return false;
        }
    });


    /*
    $('div#projectRepeaterControl div.textWrapper div.textClickable').click(function (e) {
    var i = $('div#projectRepeaterControl div.textWrapper div.textClickable').index(this);
    var currentHref = $('div#projectRepeaterControl div.textWrapper p.websiteAdres a').eq(i).attr('href');
    if (currentHref == undefined || currentHref == '') {
    currentHref = $('div#projectRepeaterControl div.itemnieuwbouw div.links a').eq(i).attr('href');
    }
    window.open(currentHref, 'venster' + i, '', '');
    return false;
    });

    $('div#projectRepeaterControl div.imageWrapper').click(function (e) {
    var i = $('div#projectRepeaterControl div.imageWrapper').index(this);
    var currentHref = $('div#projectRepeaterControl div.textWrapper p.websiteAdres a').eq(i).attr('href');
    if (currentHref == undefined || currentHref == '') {
    currentHref = $('div#projectRepeaterControl div.itemnieuwbouw div.links a').eq(i).attr('href');
    }
    window.open(currentHref, 'venster' + i, '', '');
    return false;
    });

    $('div#projectRepeaterControl div.itemnieuwbouw h2').click(function (e) {
    var i = $('div#projectRepeaterControl div.itemnieuwbouw h2').index(this);
    var currentHref = $('div#projectRepeaterControl div.textWrapper p.websiteAdres a').eq(i).attr('href');
    if (currentHref == undefined || currentHref == '') {
    currentHref = $('div#projectRepeaterControl div.itemnieuwbouw div.links a').eq(i).attr('href');
    }
    window.open(currentHref, 'venster' + i, '', '');
    return false;
    });

    */



    /*** projectRepeaterControl Garages/bergingen  ***************/


    //$('div#projectRepeaterControlGarages .item:odd').css("background-color", "#fafafa");

    $('div#projectRepeaterControlGarages div.item').hover(function () {
        var i = $('div#projectRepeaterControlGarages div.item').index(this);
        $('div#projectRepeaterControlGarages div.item').eq(i).addClass("listPageHover");
    }, function () {
        $(this).removeClass('listPageHover');
    });


    $('div#projectRepeaterControlGarages div.item').click(function (e) {
        var i = $('div#projectRepeaterControlGarages div.item').index(this);
        var currentHref = $('div#projectRepeaterControlGarages div.item p.websiteAdres a').eq(i).attr('href');

        if (currentHref == undefined) {
            currentHref = $('div#projectRepeaterControlGarages div.item div.links a').eq(i).attr('href');
        }

        window.location = currentHref;
        return false;
    });



    //.................

    /***************** einde aanklikbaar maken van tems ****************/

    $('.statusBeschikbaarheid').each(function () {
        var status = $(this).text();

        if (status && !/^\s*verkocht($|\s)/i.test(status)) {
            $(this).hide();
        }
        else {
            $("a.reageerTop").hide();
            $("a.reageer").hide();
        }
    });

    $('.zoekBox .woonplaats label').each(function () {
        var text = ($(this).text() || "").replace(/^\s+|\s+$/g, "").split(/\s+/g);

        if (text.length > 0) {
            for (var index = 0; index < text.length; index++) {
                text[index] = (text[index].substring(0, 1).toUpperCase() + text[index].substring(1).toLowerCase());
            }
        }

        $(this).text(text.join(' '));
    });

    //added 22.08.2011
    //VERWIJDER LEGE SUBTITEL VOOR NIEUWSOVERZICHT
    if ($('#nieuws h2.subTitle').text() == "") {
        $('#nieuws h2.subTitle').remove();
    }

    //added 22.08.2011
    //changed RB-2011-09-08
    //KOPIEER VOOR KOPEN > WONINGAANBOD OVERZICHT DE HYPERLINK VAN DE LEESVERDER BUTTON NAAR DE AFBEELDING
    $('.extendedProjectRepeaterItemKoop').each(function (index, element) {
        var url = $('.textWrapper a.button', element).attr('href');

        $('img', element).wrap("<a class='leesverderLink' href='" + url + "'></a>");
    });

    //added 22.08.2011
    //FORMATTEER WONINGPRIJS ZONDER DECIMALEN
    $('.extendedProjectRepeaterItemKoop p.verkoopprijs').each(function () {
        prijsStr = $(this).text();
        split_prijsStr = prijsStr.split(',');
        $(this).text(split_prijsStr[0]);
    });
    $('#koopwoningDetail div.containerLeft h2').each(function () {
        var prijsStr = $(this).text();
        prijsStr = prijsStr.replace(',00', '');
        $(this).text(prijsStr);
    });
    $('div.topAanbod').each(function () {
        var topAanbodStr = $(this).html();
        topAanbodStr = topAanbodStr.replace(',00', '');
        $(this).html(topAanbodStr);
    });

    // aanpassing voor hoofdmenu: toevoeging onderste border bij laatste listitem
    $(".header .nav li ul li:last-child").addClass("extraBorder");

    //vrije sector Huurwoningen: verwijder video/wijk links, indien leeg
    $('.vrijeSecctorHuurW .links a.buurtInfo,.vrijeSecctorHuurW .links a.video').each(function () {
        var lnk = $(this).attr("href");
        if (lnk.length == 1 || (lnk.length > 1 && lnk[lnk.length - 1] == "/")) {
            lnk = "";
        }
        if (lnk == "") {
            $(this).remove();
        }
        else if (/\%20|\s/.test(lnk)) {
            $(this).attr("href", lnk.replace(/\%20|\s/g, ""));
        }
    });

    if ($('.vrijeSecctorHuurW .links').is(':empty')) {
        $(this).css("margin-top", "-6px");
        $(this).css("margin-bottom", 0);
    }

    if ($('.col1').is(':empty')) {
        $('.col1').remove();
    }

    $("a[href='#']").each(function (index, element) {
        $(element).attr("href", $(element).text());
    });

    // bij hoofdmenu-item de margin weghalen bij laatste item
    $("ul.nav li:last-child").css("margin-right", "0");

    // streepje bij de sitemap items
    $("ul.subMenu li").append("<span>-</span>");

    $('#header h1').click(function () {
        window.location = "/";
        return false;
    });

    //SHOW PRINT-------------------------------------------------------------------------/
    $('.print').click(function () {
        window.print();
        return false;
    });

    //fotofeature aanklikbaar maken
    $('div.simple-block > img.featureImage').removeAttr('onclick');
    $('div.simple-block').click(function (evt) {
        evt.preventDefault();
        var i = $('div.simple-block').index(this);

        var target = $('div.simple-block > a.leesVerder').eq(i).attr('target');

        var currentHref = $('div.simple-block > a.leesVerder').eq(i).attr('navUrl');
        if (currentHref == null) {
            currentHref = $('div.simple-block > a.leesVerder').eq(i).attr('href');
        }
        if (currentHref == null) {
            currentHref = $('div.simple-block').eq(i).attr('href');
        }

        window.open(currentHref, target);
    });

    //Koppel de functie "fontresizing" in de eerste li van FontResizer
    $('.FontResizer>li:first').fontresizing();

    $(".lined-block ul li:last-child").css("border", "none");

    $(".col-3-1 .Nav li:first").css("margin-top", "0px");

    $("#projectRepeaterControl div:odd").css("margin-right", "0px");


    // Sitemap aanpassing
    //$("ul.Sitemap li.primary-nav_li_1:eq(2)").css("margin-right", "0px");
    //$("ul.Sitemap li.primary-nav_li_1:eq(3)").css("margin-right", "0px");

    $(".zoekBox").focus();


    // count the number of characters in the textbox -------------------------------------*/
    // This method is part of the jquery.counter-1.0.min.js package
    //$(".persoonlijkBericht").counter();

    $(".persoonlijkBericht").counter({
        count: 'up',
        goal: 500
    });

    $("textarea.reactie").counter({
        count: 'up',
        goal: 500
    });


    // Remove dotted border on the blogRepeater Skin -------------------------------------*/
    $("div.blogWrapper:last").removeClass("borderBottom");


    // add an extra dotted border on the last blogitem on the Homepage -------------------*/
    //$("div.newsRepeaterItemHomeSimple:last").addClass("borderBottom");
    $('.newsRepeaterItemHomeSimple a:last').addClass("borderBottom");

    // add an extra dotted border on the last li -----------------------------------------*/
    $(".recentItem:last").addClass("borderBottom");



    // FAQ ---------------------------------------------------------------------------/
    $('.Toggler').hover(function () { $(this).addClass('hover'); }, function () { $(this).removeClass('hover'); });
    //$('.Toggler .faqAntwoord:first').show();
    $('.Toggler').click(function () {
        var i = $('.Toggler').index(this);
        $('.Toggler .faqAntwoord').hide();
        $('.Toggler .faqAntwoord').eq(i).show();
        $('.Toggler').removeClass('active');
        $(this).addClass('active');
    });

    // Plaats reactie -----------------------------------------------------------------/
    $('.geefReactie').click(function (e) {
        e.preventDefault();
        $('#reactiesModalContent').show();
    });

    // Tell a friend -----------------------------------------------------------------/
    $(".tellAFriend").click(function () {
        $('.TellAFriend').removeClass("hidden");
        $('.TellAFriendMsg').addClass("hidden");
    });


    //CAROUSEL  ----------------------------------------------------------------------/
    FunctCaroussel.init();
    $('#header-caroussel').css('visibility', 'visible');
    $('.caroussel-nav').css('display', 'none');



});




//	:::::::::::::::::::::::::::::: Start Caroussel
FunctCaroussel = {
    first: 0,
    last: 2,
    current: 0,
    all: 0,
    beforeAfterClicked: false,
    beforeAfterNr: false,
    init: function() {
        if ($('#header-caroussel').length <= 0) return;
        FunctCaroussel.all = $('#slide-titles a').length - 1;

        $('#header-caroussel').cycle({
            fx: 'scrollHorz',
            speedIn: 2000,
            speedOut: 2000,
            easeIn: 'easeOutExpo',
            easeOut: 'easeOutExpo',
            //delay:   -2000,
            prev: '#caroussel-back',
            next: '#caroussel-forth',
            //sync: 1000,
            pager: '#slide-titles',
            timeout: 4000,
            //timeout: 10000000,
            before: FunctCaroussel.onBefore,
            after: FunctCaroussel.onAfter,
            pagerAnchorBuilder: function(idx, slide) {
                // return selector string for existing anchor 
                return '#slide-titles a:eq(' + idx + ')';
            }
        });
        FunctCaroussel.update();
    },
    update: function() {
        for (var i = 0; i <= FunctCaroussel.all; i++) {
            if (i < FunctCaroussel.first || i > FunctCaroussel.last) $('#slide-titles a:eq(' + i + ')').hide();
            else $('#slide-titles a:eq(' + i + ')').show();
        }
        if (FunctCaroussel.first > 0) $('#slide-titles').prev().show();
        else $('#slide-titles').prev().hide();
        if (FunctCaroussel.last < FunctCaroussel.all) $('#slide-titles').next().show();
        else $('#slide-titles').next().hide();
        var w = 0;
        $('.slide-titles a').each(function() {
            if ($(this).css('display') != 'none') w += 12 + $(this).width();
        });
        $('.caroussel-nav .slide-titles').css({ width: w + 'px' });
    },
    onAfter: function(curr, next, opts, forw) {
        //if(FunctCaroussel.notInited) FunctCaroussel.notInited = false;		
    },
    onBefore: function(curr, next, opts, forw) {
        if ($('#slide-titles a:eq(' + $('.caroussel-item').index(next) + ')').attr('class') == 'activeSlide') return false;
        FunctCaroussel.current = $('.caroussel-item').index(curr);
        var n = forw ? FunctCaroussel.current + 1 : FunctCaroussel.current - 1;
        var f = FunctCaroussel.first;
        var l = FunctCaroussel.last;

        if (n > f && n < l) return;
        else if (n <= f) {
            if (n < 0) {
                FunctCaroussel.first = FunctCaroussel.all - 2;
                FunctCaroussel.last = FunctCaroussel.all;
            } else if (n == 0) {
                //
            } else {
                FunctCaroussel.first--;
                FunctCaroussel.last--;
            }
        } else if (n >= l) {
            if (n > FunctCaroussel.all) {
                FunctCaroussel.first = 0;
                FunctCaroussel.last = 2;
            } else if (n == FunctCaroussel.all) {
                //
            } else {
                FunctCaroussel.first++;
                FunctCaroussel.last++;
            }
        }
        FunctCaroussel.update();
    }
}
//	:::::::::::::::::::::::::::::: End Caroussel

//	:::::::::::::::::::::::::::::: Woningaanbod

/* 
    FO: Voorwaarde minimum prijs moet lager zijn dan maximum gekozen waarde, anders wordt het 
        automatisch in het zoekvenster opgehoogd naar de volgende staffel.
*/
function ChangePriceDropDownBox(min_price_id, max_price_id, lower) {            
    if (lower) {
        if ($(max_price_id).val() == '') {
            return;
        }
        else {
            if (parseInt($(min_price_id).val()) >= parseInt($(max_price_id).val())) {
                var selItem = $(min_price_id)[0].selectedIndex;
                if (selItem == $(min_price_id)[0].options.length - 1)
                    $(max_price_id).val('');
                else {
                    var newVal = $(min_price_id)[0].options[selItem + 1].value;
                    $(max_price_id).val(newVal);
                }
            }
        }
    }
    else {
        if ($(min_price_id).val() == '0') {
            return;
        }
        else {
            if (parseInt($(max_price_id).val()) <= parseInt($(min_price_id).val())) {
                var selItem = $(max_price_id)[0].selectedIndex;
                if (selItem == 0)
                    $(min_price_id).val('0');
                else {
                    var newVal = $(max_price_id)[0].options[selItem - 1].value;
                    $(min_price_id).val(newVal);
                }
            }
        }
    }
}
//	:::::::::::::::::::::::::::::: End Woningaanbod
