
function megaHoverOver()
{
	$(this).find(".sub").stop().fadeTo('fast', 1).show();

	//Calculate width of all ul's
	(function ($)
	{
		jQuery.fn.calcSubWidth = function ()
		{
			rowWidth = 0;
			//Calculate row
			$(this).find("ul").each(function ()
			{
				rowWidth += $(this).width();
			});
		};
	})(jQuery);

	if ($(this).find(".row").length > 0)
	{ //If row exists...
		var biggestRow = 0;
		//Calculate each row
		$(this).find(".row").each(function ()
		{
			$(this).calcSubWidth();
			//Find biggest row
			if (rowWidth > biggestRow)
			{
				biggestRow = rowWidth;
			}
		});
		//Set width
		$(this).find(".sub").css({ 'width': biggestRow });
		$(this).find(".row:last").css({ 'margin': '0' });

	} else
	{ //If row does not exist...

		$(this).calcSubWidth();
		//Set Width
		$(this).find(".sub").css({ 'width': rowWidth });
	}
}

function megaHoverOut()
{
	$(this).find(".sub").stop().fadeTo('fast', 0, function ()
	{
		$(this).hide();
	});
}

function initMegaMenu()
{
	var config = {
		sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		interval: 10, // number = milliseconds for onMouseOver polling interval    
		over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		timeout: 10, // number = milliseconds delay before onMouseOut    
		out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({ 'opacity': '0' });
	$("ul#topnav li").hoverIntent(config);
	$("ul.level2 > li:nth-child(5)").css('clear', 'both');
	$("ul.level2 > li:nth-child(9)").css('clear', 'both');
	$("ul.level2 > li").css('margin-bottom', '15px');
}

$(document).ready(function () {


    $("#featureWrapperWarpZone .content-3-3 div:last-child").css("margin-right", "0");

    // reflections
    //$("#gallery img").reflect(options);


    // printen op contentpagina's
    $('.contentPrint').click(function () {
        window.print();
    });


    $('.lined-block p.introText a').eq(0).addClass("email");





    /*  $('.tweet span').each(function (i) {
    if ($(this).text().length > 75) {
    var truncatedText = $(this).html().substring(0, 75) + '...';
    $(this).empty().html(truncatedText);
    }
    });
    */


    $('.newsRepeaterItemHomeSimple p.ShortDescription').each(function (i) {
        if ($(this).text().length > 130) {
            var truncatedText = $(this).html().substring(0, 130) + ' ..';
            $(this).empty().html(truncatedText);
        }
    });


    // text afbreken na een bepaald punt
    $('.newsRepeaterItem p.ShortDescription').each(function (i) {
        if ($(this).text().length > 175) {
            var truncatedText = $(this).html().substring(0, 175) + ' ..';
            $(this).empty().html(truncatedText);
        }
    });



    // text afbreken na een bepaald punt
    $('.lined-block p.introText').each(function (i) {
        if ($(this).text().length > 175) {
            var truncatedText = $(this).html().substring(0, 175) + '...';
            $(this).empty().html(truncatedText);
        }
    });




    //IE7 fix for z-index stacking order        
    /*$(function () {
    var zIndexNumber = 1000;
    $('div').each(function () {
    $(this).css('zIndex', zIndexNumber);
    zIndexNumber -= 10;
    });
    $('div.footer').css("z-index", "-1");
    });
    */

    if ($('.col1').is(':empty')) {
        $('.col1').remove();
    }


    // 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;
    });

    //nieuwsblok homepage aanklikbaar maken
    $('div.newsRepeaterItemHomeSimple').click(function () {
        var i = $('div.newsRepeaterItemHomeSimple').index(this);
        var currentHref = $('div.newsRepeaterItemHomeSimple a.leesVerder').eq(i).attr('href');
        document.location = currentHref;
    });
    $('div.newsRepeaterItemHomeSimple a.leesVeder').hide();

    $('div.newsRepeaterItemHomeSimple').hover(function () {
        var i = $('div.newsRepeaterItemHomeSimple').index(this);
        $('div.newsRepeaterItemHomeSimple').eq(i).addClass("hoverState");
    }, function () {
        $(this).removeClass('hoverState');
    });


    //nieuwsblok aanklikbaar maken
    $('div.simple-block').click(function () {
        var i = $('div.simple-block').index(this);
        var currentHref = $('div.simple-block a.readMoreHide').eq(i).attr('href');
        document.location = currentHref;
    });
    $('div.simple-block a.readMoreHide').hide();

    $('div.simple-block').hover(function () {
        var i = $('div.simple-block').index(this);
        $('div.simple-block').eq(i).addClass("hoverState");
    }, function () {
        $(this).removeClass('hoverState');
    });

    //medewekers foto aanklikbaar maken
    $('div.medewerkers').click(function () {
        var i = $('div.medewerkers').index(this);
        var currentHref = $('div.medewerkers').eq(i).children('a.readMoreHide').attr('href');
        //var currentHref = $('div.medewerkers a.readMoreHide').eq(i).attr('href');
        if (currentHref) {
            document.location = currentHref;
        }
        return false;
    });
    $('div.medewerkers a.readMoreHide').hide();

    $('div.medewerkers').hover(function () {
        var i = $('div.medewerkers').index(this);
        $('div.medewerkers').eq(i).addClass("hoverState");
    }, function () {
        $(this).removeClass('hoverState');
    });


    //fotofeature aanklikbaar maken
    $('div.portfolio').click(function () {
        var i = $('div.portfolio').index(this);
        var currentHref = $('div.portfolio a.readMoreHide').eq(i).attr('href');
        var targetHref = $('div.portfolio a.readMoreHide').eq(i).attr('target');

        if (targetHref != undefined) {
            if (targetHref == '_blank' || targetHref == '_new') {
                window.open(currentHref, 'venster' + i, '', '');
                return false;
            }
        }
        document.location = currentHref;
    });
    $('div.portfolio a.readMoreHide').hide();

    $('div.portfolio').hover(function () {
        var i = $('div.portfolio').index(this);
        $('div.portfolio').eq(i).addClass("hoverState");
    }, function () {
        $(this).removeClass('hoverState');
    });


    //news
    $('div.newsRepeaterItem').click(function () {
        var i = $('div.newsRepeaterItem').index(this);
        var currentHref = $('div.newsRepeaterItem a.button').eq(i).attr('href');
        document.location = currentHref;
    });
    $('div.newsRepeaterItem a.button').hide();

    $('div.newsRepeaterItem').hover(function () {
        var i = $('div.newsRepeaterItem').index(this);
        $('div.newsRepeaterItem').eq(i).addClass("hoverState");
    }, function () {
        $(this).removeClass('hoverState');
    });


    $(".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");

    // 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 (e) {
        e.preventDefault()
        $('.TellAFriend').removeClass("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: 10000,
//            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


/* Accordion van FAQ */
$(document).ready(function () {

    //Set default open/close settings
    $('.acc_container').hide(); //Hide/close all containers
    $('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

    //On Click
    $('.acc_trigger').click(function () {
        if ($(this).next().is(':hidden')) { //If immediate next container is closed...
            $('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
            $(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
        }
        return false; //Prevent the browser jump to the link anchor
    });

});



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('');
		});
	});

	setTimeout(initMegaMenu,1000);
});


