
function mycarousel_initCallback(carousel) {

    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });


    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function eventListeners() {




    $('#filterButton').click(function() {
        $('#categoryList').slideToggle(500);
        $('#filterButton').toggleClass('filterButtonUp', 'filterButtonDown');
        $('#borderBottom').slideToggle();
    });


    $(".toLightbox").click(function() {
        
        // simuleer click :-)
        $(".firstImg").click();
        
    });

    $("#primaryNav span").hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });

    // corrigeer menu positie eerste element
    $("#primaryNav li:nth-child(2)").css('padding-left', '0px');



    /* mouseOvers social media menu */
    var returnTo;
    $("#sflickr").hover(function() {
        returnTo = this.src;
        this.src = 'img/icons/flickrActive.png';
    }, function() {
        this.src = returnTo;
    });
    $("#slinkedIn").hover(function() {
        returnTo = this.src;
        this.src = 'img/icons/linkedInActive.png';
    }, function() {
        this.src = returnTo;
    });
    $("#syouTube").hover(function() {
        returnTo = this.src;
        this.src = 'img/icons/youTubeActive.png';
    }, function() {
        this.src = returnTo;
    });
    $("#stwitter").hover(function() {
        returnTo = this.src;
        this.src = 'img/icons/twitterActive.png';
    }, function() {
        this.src = returnTo;
    });

    /* magic carousel rollover */

    function doResetTimeout(object, returnTo) {

        alert('reset');
        $(object).attr('src', returnTo);
        pendingTimeout = false;
    }

    var returnTo;

    var carouselRegister = new Array();


    $("#carousel img.cNormal").each(function(index) {

        $(this).attr('index', index);
        carouselRegister[index] = $(this).attr('src');


    });

    $("#carousel img.cNormal").mouseenter(function() {

        $(this).attr('src', $(this).next('.cHover').attr('src'));

    });
    $("#carousel img.cNormal").mouseleave(function() {

        $(this).attr('src', carouselRegister[$(this).attr('index')]);

    });


}
jQuery(document).ready(function() {

    jQuery('#carousel').jcarousel({
        auto: 3,
        wrap: 'circular',
        initCallback: mycarousel_initCallback
    });


//    $(function() {
//        if ($('#images a').length > 0) {
//            $('#images a').lightBox({ fixedNavigation: true });
//        }
//        if ($('#nieuwsImage li a').length > 0) {
//            $('#nieuwsImage li a').lightBox({ fixedNavigation: true });
//        }
//    });




    /* magische portfolio enchanger */
    var img;

    $(".portfolioImages img").each(function(index, element) {


        $(element).parents('.portfolioBlock').css("background-image", "url(" + element.src + ")");

        $(element).parents('.portfolioBlock').click(function() {
            document.location.href = $('a', this).attr('href');
        });

        $(element).css('display', 'none');


        $(element).parents('.portfolioBlock').hover(function() {

            $(".info", this).slideDown();
        }, function() {
            $(".info", this).slideUp();
        });

    });

    /* de nog even wat magischer border animator voor de deurmat nav en de blokken bij een info overview */
//    $("#content div.blocks div.blockNav img").each(function(index, element) {


//        $(element).parents('.overlay').css("background-image", "url(" + element.src + ")");

//        $(element).parents('.blockNav').click(function() {
//            document.location.href = $('a', this).attr('href');
//        });

//        $(element).parents('.blockNav').hover(function() {
//            $(element).css('display', 'block');
//            returnTo = element.src;
//            $(element).css('display', 'none');
//            element.src = '/common/img/animatedBorder.gif';
//            $(element).fadeIn();

//            //$(this).addClass('border');

//        }, function() {
//            $(element).fadeOut();
//            //element.src = 'img/animatedBorderEmpty.gif';
//            //$(this).removeClass('border');
//        });

    //    });

    $('.watermarked').each(function() {
        $(this).watermark('watermark', $(this).attr('title'));
    });

    $(".infoPageBlocks img").each(function(index, element) {


        $(element).parents('.overlay').css("background-image", "url(" + element.src + ")");

        $(element).parents('.infoPageBlock').click(function() {
            document.location.href = $('a', this).attr('href');
        });

        $(element).parents('.infoPageBlock').hover(function() {
            $(element).css('display', 'block');
            returnTo = element.src;
            $(element).css('display', 'none');
            element.src = '/common/img/animatedBorder.gif';
            $(element).fadeIn();

        }, function() {
            $(element).fadeOut();

        });

    });

    /* tel het aantal porfolio items, geef daarna een class aan de ul met die het aantal rijen vertegenwoordigd */
    var catCount = $("#categoryList li").length;
    var catRows = Math.ceil(catCount / 4);
    $("#categoryList").addClass('rows_' + catRows);


    /* preload alle mouseovers en overige afbeeldingen */
    var cache = [];
    $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
    jQuery.preLoadImages("/common/img/buttons/portfolioFilterDownBlue.gif", "/common/img/buttons/portfolioFilterUpBlue.gif", "/common/img/portfolioHover.png", "/common/img/animatedBorder.gif");


    eventListeners();
});


(function($) {
    $.fn.watermark = function(css, text) {
        return this.each(function() {
            var i = $(this), w;
            i.focus(function() {
                w && !(w = 0) && i.removeClass(css).data('w', 0).val('');
            })
			.blur(function() {
			    !i.val() && (w = 1) && i.addClass(css).data('w', 1).val(text);
			})
			.closest('form').submit(function() {
			    w && i.val('');
			});
            i.blur();
        });
    };
    $.fn.removeWatermark = function() {
        return this.each(function() {
            $(this).data('w') && $(this).val('');
        });
    };
})(jQuery);


function pageLoad(sender, args) {
    if (args.get_isPartialLoad()) {
        $('.watermarked').each(function() {
            $(this).watermark('watermark', $(this).attr('title'));
        });
    }
}

