

$(document).ready(function () {
    $('.homepage-slideshow').ready().show();
    $('.project-slideshow').ready().show();

    $("#naar-portfolio").click(function () {
        window.location = "/portfolio"
    });
});

function onBefore() {
    var introtextElement;
	if($.browser.msie && $.browser.version < 9) {
	    introtextElement = $.attr(this.firstChild, "data-introtext");
	}
	else {
	    introtextElement = $.attr(this.firstElementChild, "data-introtext");
	}

	$('#ps-content').html(introtextElement + ' <a  href="' + this.href + '"><br />Lees meer...</a>').click(function () { window.location = $('a', this).attr("href") });

}



function animate(obj, bool) {

    if (bool = true)
    {
        $('.project-slideshow a').append('<div id="pj-overlay" style="background:#ff0001"></p>');
    }
    else 
    {
        $('.project-slideshow a').remove('#pj-overlay');
    }
}

jQuery(function () {

    if ($('.homepage-slideshow')) {
        $('.homepage-slideshow').cycle({
            fx: 'fade',
            random: 1,
            timeout: 6000,
            before: onBefore

        });
    }

    if ($('.project-slideshow')) {

        $('#ps-container').hover(
		    function () { $('.project-slideshow').cycle('pause'); },
            function () { $('.project-slideshow').cycle('resume'); }
        );

        $('.project-slideshow').cycle({
            fx: 'fade',
            speed: 'fast',
            prev: '#prev',
            next: '#next',
            timeout: 6000,
            pauseOnPagerHover: 1,
            before: onBefore,
            pager: '#project-thumbnails',
            pagerEvent: 'mouseover',
            allowPagerClickBubble: true,
            // callback fn that creates a thumbnail to use as pager anchor 
            pagerAnchorBuilder: function (idx, slide) {

                var srcElement;
                var pageElement;
                if ($.browser.msie && $.browser.version < 9) {
                    srcElement = $.attr(slide.firstChild, "src");
                    pageElement = $.attr(slide.firstChild, "data-page");
                }
                else {
                    srcElement = $.attr(slide.firstElementChild, "src");
                    pageElement = $.attr(slide.firstElementChild, "data-page");
                }

                var cs = srcElement.replace("ImageCrop", "Thumbnail")

                return '<a style="background:url(' + cs + ');" href="' + pageElement + '"> </a>';
            }
        });
    }

    //function
}); 
