
(function($) {
    Bokd.initSlideshows = function(swfBase) {

        Bokd.SlideShow_header.slideshow('.headerphoto1 img', swfBase, { imageRotation: -1 });

        Bokd.SlideShow.slideshow('.home_image1 img', swfBase, { imageRotation: 3 });
        Bokd.SlideShow.slideshow('.home_image2 img', swfBase, { imageRotation: -3 });
        /*
        $('.homeImages img').each(function(i) {
        var srcImage = $(this).attr('src');
        if(srcImage.lastIndexOf('id=') == -1) {
        return;
        }
        var imageId = srcImage.substring(srcImage.lastIndexOf('id=')+3);
        var rotation = (i % 2 == 0)?3:-3;
           
        var square =  $.ajax({
        url: "Controls/ImageRatio.ashx?id="+imageId,
        cache: false,
        async: false
        }).responseText;

            if(square == 'True'){
        Bokd.SlideShow.slideshow($(this), swfBase, { imageRotation: rotation});
        } else{
        Bokd.SlideShow_content.slideshow($(this), swfBase, { imageRotation: rotation});
        }
        
        });
        */
        $('.contentLeftContent img').each(function(i) {
            var srcImage = $(this).attr('src');
            var imageId = srcImage.substring(srcImage.lastIndexOf('id=') + 3);

            var square = $.ajax({
                url: "Controls/ImageRatio.ashx?id=" + imageId,
                cache: false,
                async: false
            }).responseText;

            if (square == 'True') {
                Bokd.SlideShow.slideshow($(this), swfBase, { imageRotation: -3 });
            } else {
                Bokd.SlideShow_content.slideshow($(this), swfBase, { imageRotation: -3 });
            }



        });


        Bokd.SlideShow.kader('.kader img', swfBase, { imageRotation: -3 });

        var pos = $('.headerphoto2').position();
        var leftMarg = pos.left;
        $('.headerphoto1').css('left', leftMarg + 'px');
        $('.headerphoto1').css('top', '75px');
    };


    Bokd.SlideShow_header = {
        slideshow: replaceImages_header,
        kader: addKader_header
    };

    Bokd.SlideShow_content = {
        slideshow: replaceImages_content,
        kader: addKader_content
    };

    Bokd.SlideShow = {
        slideshow: replaceImages,
        kader: addKader
    };
    function replaceImages(selector, swfUrlPrefix, options) {
        replaceImagesImpl($(selector), swfUrlPrefix, options);
    }
    function addKader(selector, swfUrlPrefix, options) {

        $(selector).each(function() {
            replaceImagesImpl($(this), swfUrlPrefix, options);
        });
    }
    function replaceImagesImpl(jqList, swfUrlPrefix, options) {
        if (jqList.length == 0) return;
        if (!swfUrlPrefix) swfUrlPrefix = '';
        //var width = '100%', height = '100%';
        //var width = '350px', height = '260px';
        var width = '160px', height = '160px', align = 'center';



        var slideshowIdNr = Math.floor(Math.random() * 1000000 + 10000);
        var slideshowId = 'slideshow' + slideshowIdNr;
        var images = new Array();
        jqList.each(function() {
            images.push(this.src);
        }).hide();
        var first = jqList.get(0);
        //alert($(first).parent().get(0));
        $(first).before('<div id="' + slideshowId + '"></div>');

        var flashvars = {
            type: 1, //klein vierkant
            imageRotation: 3,
            offsetX: 10,
            offsetY: 17,
            aniDelay: 2.1,
            aniDuration: 2,
            aniTransition: 'easeInOutQuint'

        };
        if (options) {
            for (var xx in options) { flashvars[xx] = options[xx]; }
            if (flashvars.imageRotation < 0 && !options.offsetX) {
                flashvars.offsetX -= 10;
            }
        }
        for (var i = 0; i < images.length; i++) {
            flashvars['url' + i] = encodeURIComponent(images[i]);
        }
        var params = {
            menu: "false",
            scale: "noScale",
            allowFullscreen: "true",
            allowScriptAccess: "always",
            bgcolor: "#FFFFFF",
            align: 'br',
            wmode: 'transparent'
        };
        var attributes = {
            id: "slideshowswf" + slideshowIdNr
        };

        $.swfobject.embedSWF(swfUrlPrefix + "slideshow_multi.swf", slideshowId, width, height, "9.0.0", swfUrlPrefix + "expressInstall.swf", flashvars, params, attributes);

    }

    /////////////
    function replaceImages_header(selector, swfUrlPrefix, options) {
        replaceImagesImpl_header($(selector), swfUrlPrefix, options);
    }
    function addKader_header(selector, swfUrlPrefix, options) {

        $(selector).each(function() {
            replaceImagesImpl_header($(this), swfUrlPrefix, options);
        });
    }
    function replaceImagesImpl_header(jqList, swfUrlPrefix, options) {
        if (jqList.length == 0) return;
        if (!swfUrlPrefix) swfUrlPrefix = '';
        var width = '100%', height = '100%';
        var width = '417px', height = '265px';
        //var width = '160px', height = '160px', align = 'center';



        var slideshowIdNr = Math.floor(Math.random() * 1000000 + 10000);
        var slideshowId = 'slideshow' + slideshowIdNr;
        var images = new Array();
        jqList.each(function() {
            images.push(this.src);
        }).hide();
        var first = jqList.get(0);
        //alert($(first).parent().get(0));
        $(first).before('<div id="' + slideshowId + '"></div>');

        var flashvars = {
            type: 2, //grote rechthoek
            imageRotation: 3,
            offsetX: 10,
            offsetY: 17,
            aniDelay: 2.1,
            aniDuration: 2,
            aniTransition: 'easeInOutQuint'

        };
        if (options) {
            for (var xx in options) { flashvars[xx] = options[xx]; }
            if (flashvars.imageRotation < 0 && !options.offsetX) {
                flashvars.offsetX -= 10;
            }
        }
        for (var i = 0; i < images.length; i++) {
            flashvars['url' + i] = encodeURIComponent(images[i]);
        }
        var params = {
            menu: "false",
            scale: "noScale",
            allowFullscreen: "true",
            allowScriptAccess: "always",
            bgcolor: "#FFFFFF",
            align: 'br',
            wmode: 'transparent'
        };
        var attributes = {
            id: "slideshowswf" + slideshowIdNr
        };
        $.swfobject.embedSWF(swfUrlPrefix + "slideshow_header.swf", slideshowId, width, height, "9.0.0", swfUrlPrefix + "expressInstall.swf", flashvars, params, attributes);

    }


    ////////

    function replaceImages_content(selector, swfUrlPrefix, options) {
        replaceImagesImpl_content($(selector), swfUrlPrefix, options);
    }
    function addKader_content(selector, swfUrlPrefix, options) {

        $(selector).each(function() {
            replaceImagesImpl_content($(this), swfUrlPrefix, options);
        });
    }
    function replaceImagesImpl_content(jqList, swfUrlPrefix, options) {
        if (jqList.length == 0) return;
        
        if (!swfUrlPrefix) swfUrlPrefix = '';
        var width = '100%', height = '100%';
        var width = '230px', height = '170px';
        //var width = '160px', height = '160px', align = 'center';



        var slideshowIdNr = Math.floor(Math.random() * 1000000 + 10000);
        var slideshowId = 'slideshow' + slideshowIdNr;
        var images = new Array();
        jqList.each(function() {
            images.push(this.src);
        }).hide();
        var first = jqList.get(0);
        //alert($(first).parent().get(0));
        $(first).before('<div id="' + slideshowId + '"></div>');

        var flashvars = {
            type: 3, //klein vierkant
            imageRotation: 3,
            offsetX: 10,
            offsetY: 17,
            aniDelay: 2.1,
            aniDuration: 2,
            aniTransition: 'easeInOutQuint'

        };
        if (options) {
            for (var xx in options) { flashvars[xx] = options[xx]; }
            if (flashvars.imageRotation < 0 && !options.offsetX) {
                flashvars.offsetX -= 10;
            }
        }
        for (var i = 0; i < images.length; i++) {
            flashvars['url' + i] = encodeURIComponent(images[i]);
        }
        var params = {
            menu: "false",
            scale: "noScale",
            allowFullscreen: "true",
            allowScriptAccess: "always",
            bgcolor: "#FFFFFF",
            align: 'br',
            wmode: 'transparent'
        };
        var attributes = {
            id: "slideshowswf" + slideshowIdNr
        };
        $.swfobject.embedSWF(swfUrlPrefix + "slideshow_multi.swf", slideshowId, width, height, "9.0.0", swfUrlPrefix + "expressInstall.swf", flashvars, params, attributes);

    }

})(jQuery);
