$(document).ready(function () {


    $('div.tabsWrapper ul li').eq(0).css("width", "107px");
    $('div.tabsWrapper ul li').eq(1).css("width", "99px");
    $('div.tabsWrapper ul li').eq(2).css("width", "98px");
    $('div.tabsWrapper ul li').eq(3).css("width", "65px");


    ///////////////////////////////////////////////////////////////////////////////////
    // preloaden van alle plaatjes die zich in de css file bevinden------------------//
    ///////////////////////////////////////////////////////////////////////////////////
    $.preloadCssImages();

    ///////////////////////////////////////////////////////////////////////////////////
    // fck tabellen zonder border krijgen geen achtergrondskleur------------------//
    ///////////////////////////////////////////////////////////////////////////////////

    //attribute border afwezig
    $('table').each(function (i) {
        var attrib = $(this).attr('border');
        if (typeof attrib == 'undefined' || attrib == false) {
            $(this).addClass('tabelZonderKader');
        }
    });
    //attribute border=0
    $('table.[border="0"]').addClass('tabelZonderKader');



    $('.col-4-3 .global p.omschrijving').eq(2).css("border", "none");



    /////////////////////////////////////////////////////////////////////////////////////////////////
    // Hier worden de input velden gevuld bij het aanmelden op de website in de header van de pagina------//
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    // vul hier de attribuutnaam in die je wil gebruiken.
    var title_attr = 'title';

    $(document).ready(function () {
        $("input[" + title_attr + "]").each(function () {
            $(this).focus(function () {
                if ($(this).is(".title")) {
                    $(this).removeClass('title').val('');
                }
            }).blur(function () {
                if ($(this).val() == '' || $(this).val() == $(this).attr(title_attr)) {

                    $(this).addClass('title').val($(this).attr(title_attr));
                }
            }).blur();
        });
        $("form").submit(function () {
            $(this).find("input[class='title']").each(function () {
                $(this).val('');
            });
        });
    });



    ///////////////////////////////////////////////////////////////////////////////////
    //IE7 fix for z-index stacking order--------------------------------------------//
    ///////////////////////////////////////////////////////////////////////////////////        
    $(function () {
        var zIndexNumber = 1000;
        $('div').each(function () {
            $(this).css('zIndex', zIndexNumber);
            zIndexNumber -= 10;
        });
    });

    ///////////////////////////////////////////////////////////////////////////////////
    // Slideshow header homepage --------------------------------------------------////
    ///////////////////////////////////////////////////////////////////////////////////
    $('.slideshow').cycle({
        fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
        speed: 6500,  // speed of the transition (any valid fx speed value)
        delay: -4000
    });


    // projecten   
    $(document).ready(function () {
        $('div.ProjectRepeaterItem:even').css("clear", "both");
    });




    // bij features de margin-top weghalen bij de eerste paragraaf

    $('.usual .contentWrapper div.body p:first-child').css("margin-top", "0");

    $('.contrast-block div.body  p:first-child').css("margin-top", "0");


    $('.zoomButtons a:first-child').addClass("little");
    $('.zoomButtons a').eq(1).addClass("biggert");


    $('.zoomButtonsContentpage a:first-child').addClass("little");
    $('.zoomButtonsContentpage a').eq(1).addClass("biggert");






    //Repeateritem projecten
    //$('div.RepeaterItem a.Leesverder').hide();
    $('div.projectRepeaterItem').hover(function () {
        var i = $('div.projectRepeaterItem').index(this);
        $('div.projectRepeaterItem').eq(i).addClass("projectRepeaterItemHover");
    }, function () {
        $(this).removeClass('projectRepeaterItemHover');
    });

    $('div.projectRepeaterItem').click(function () {
        var i = $('div.projectRepeaterItem').index(this);
        var currentHref = $('div.projectRepeaterItem .infoWrapper a.Leesverder').eq(i).attr('href');
        document.location = currentHref;
    });


    //Koppel de functie "fontresizing" in de eerste li van FontResizer
    //$('.FontResizer>li:first').fontresizing();


    //Repeateritem
    //$('div.RepeaterItem a.Leesverder').hide();
    $('div.searchResult').hover(function () {
        var i = $('div.searchResult').index(this);
        $('div.searchResult').eq(i).addClass("searchResultHover");
    }, function () {
        $(this).removeClass('searchResultHover');
    });

    $('div.searchResult').click(function () {
        var i = $('div.searchResult').index(this);
        var currentHref = $('div.searchResult a.leesVerder').eq(i).attr('href');
        document.location = currentHref;
    });


    //Repeateritem
    $('div.newsRepeaterItem a.leesVerder').hide();

    $('div.newsRepeaterItem').hover(function () {
        var i = $('div.newsRepeaterItem').index(this);
        $('div.newsRepeaterItem').eq(i).addClass("hoverState");
    }, function () {
        $(this).removeClass('hoverState');
    });

    $('div.newsRepeaterItem').click(function () {
        var i = $('div.newsRepeaterItem').index(this);
        var currentHref = $('div.newsRepeaterItem a.leesVerder').eq(i).attr('href');
        document.location = currentHref;
    });




    ///////////////////////////////////////////////////////////////////////////////////
    // Laat de header verwijzen naar de homepage ----------------------------------///
    ///////////////////////////////////////////////////////////////////////////////////
    $('#header h1').click(function () {
        window.location = "/";
        return false;
    });


    ///////////////////////////////////////////////////////////////////////////////////
    //SHOW PRINT----------------------------------------------------------------------/
    ///////////////////////////////////////////////////////////////////////////////////
    $('.print').click(function () {
        window.print();
        return false;
    });

    ///////////////////////////////////////////////////////////////////////////////////
    //fotofeature aanklikbaar maken
    ///////////////////////////////////////////////////////////////////////////////////


    $('div.usual img').click(function () {
        var i = $('div.usual img').index(this);
        var currentHref = $('div.usual a.leesverder').eq(i).attr('href');
        /*document.location = currentHref;*/

        var target = $('div.usual a.leesverder').eq(i).attr('target');
        window.open(currentHref, target);

    });


    $('div.contrast-block img').click(function () {
        var i = $('div.contrast-block img').index(this);
        var currentHref = $('div.contrast-block a.leesverder').eq(i).attr('href');
        document.location = currentHref;
    });

    // text afbreken met puntjes
    $('.ShortDescription p').each(function (i) {
        if ($(this).text().length > 150) {
            var truncatedText = $(this).html().substring(0, 150) + '...';
            $(this).empty().html(truncatedText);
        }
    });


    // In contrast block een div weghalen
    $('.contrast-block .contentWrapper').children().insertBefore('.contrast-block .contentWrapper');
    $('.contrast-block .contentWrapper').remove();


    ///////////////////////////////////////////////////////////////////////////////////
    // Geef de zoekbox de focus
    ///////////////////////////////////////////////////////////////////////////////////
    //$(".zoekBox").focus();


    ///////////////////////////////////////////////////////////////////////////////////
    // 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');
    });



    //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: 6000,
            speedOut: 4000,
            easeIn: 'easeOutExpo',
            easeOut: 'easeOutExpo',
            delay:   -2000,
            prev: '#caroussel-back',
            next: '#caroussel-forth',
            //sync: 1000,
            pager: '#slide-titles',
            timeout: 100000,
            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
