window.addEvent('domready', function() {

//array.shuffle functie voor mootools
Array.implement({
shuffle:function() {
this.sort(function (x,y) { return Math.floor(Math.random()*3)-1; });
return this;
} 
});

//load mootools compatible stylesheet
//var myCSS = new Asset.css('/css/mooEnabled.css', {id: 'myStyle', title: 'myStyle'});


/* var accordion = new Accordion($$('.toggler'),$$('.element'), { pre-MooTools More */
var accordion = new Fx.Accordion($$('.CollapsiblePanelTab'),$$('.CollapsiblePanelContent'), {
	opacity: 0
    //onActive: function(toggler) { toggler.setStyle('color', '#f30'); },
    //onBackground: function(toggler) { toggler.setStyle('color', '#000'); }
  });

$$('.rounded').each(function(el){
							 var wrapper = new Element('span', {'class':'inputwrap'});
							 var c1 = new Element('div', {'class':'corner1'});
							 var c2 = new Element('div', {'class':'corner2'});
							 var c3 = new Element('div', {'class':'corner3'});
							 var c4 = new Element('div', {'class':'corner4'});
							 wrapper.wraps(el);
							 c1.inject(el,'after');c2.inject(el,'after');c3.inject(el,'after');c4.inject(el,'after');
							 });

if ($('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_aDefaultSmall')) {
    $('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_aDefaultSmall').addEvent(
											 'click',function(){
											     $('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset').set('src', this.get('mediumfoto'));
//											     $('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset').set('data-magnifysrc', this.get('grotefoto'));												 
//												 	MojoMagnify.makeMagnifiable(
//													    document.getElementById("ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset"),    
//													    this.get('grotefoto')  
//													);  
											 }
											 )
}
if ($('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_aRelatedSmall')){
	$('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_aRelatedSmall').addEvent(
											 'click',function(){
											     $('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset').set('src', this.get('mediumfoto'));
//											     $('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset').set('data-magnifysrc', this.get('grotefoto'));	
//												 	MojoMagnify.makeMagnifiable(
//													    document.getElementById("ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset"),    
//													    this.get('grotefoto')  
//													);  
											 }
											 )
}
if ($('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_aVariantSmall')) {
    $('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_aVariantSmall').addEvent(
											 'click',function(){
											     $('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset').set('src', this.get('mediumfoto'));
//											     $('ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset').set('data-magnifysrc', this.get('grotefoto'));	
//												 	MojoMagnify.makeMagnifiable(
//													    document.getElementById("ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset"),    
//													    this.get('grotefoto')  
//													);  
											 }
											 )
}

//MojoMagnify.addEvent(window, "load", MojoMagnify.init);
		});

jQuery.noConflict();
jQuery(document).ready(function ($) {

    (function ($) {
        $.extend($.fn, { magnify: function (options) {
            return this.each(function () {
                var magnifier = { defaults: { lensWidth: 160, lensHeight: 160, link: true, delay: 0 }, a: null, $img: null, $largeImage: null, $lens: null, $sensor: null, $loader: null, timeOut: null, largeWidth: 0, largeHeight: 0, init: function (options)
                { magnifier.options = $.extend({}, magnifier.defaults, options); magnifier.a = this; magnifier.$img = $('img', this); magnifier.setLargeImage(); magnifier.setLens(); magnifier.setSensor(); magnifier.setLoader(); magnifier.loadImage(); magnifier.addHandles(); }, setLargeImage: function ()
                { magnifier.$largeImage = $(new Image()); magnifier.$largeImage.attr('src', magnifier.a.href).css('display', 'none'); }, setLens: function ()
                { magnifier.$lens = $("<div id='dio-lens'></div>"); magnifier.$lens.css({ width: magnifier.options.lensWidth, height: magnifier.options.lensHeight, visibility: 'hidden', overflow: 'hidden', position: 'absolute', left: 0, top: 0 }).appendTo('body'); }, setSensor: function () {
                    magnifier.$sensor = $("<div id='dio-sensor' style='position:absolute;'></div>"); $('body').append(magnifier.$sensor); if (magnifier.options.link)
                    { magnifier.$sensor.click(function () { window.location = magnifier.a.href }); }
                }, setLoader: function ()
                { magnifier.$loader = $("<div id='dio-loader'>loading</div>").css({ width: magnifier.options.lensWidth, height: magnifier.options.lensHeight }); magnifier.$lens.append(magnifier.$loader); }, loadImage: function () {
                    magnifier.$largeImage.load(function (e)
                    { magnifier.imgLoadCheck(magnifier.$largeImage[0], magnifier.loadCallback, magnifier.errorCallback, e); });
                }, imgLoadCheck: function (img, loadCallback, errorCallback) {
                    if (img != null) {
                        function imgWatch() {
                            if (img.complete)
                            { clearInterval(loadWatch); loadCallback(); }
                        }
                        var loadWatch = setInterval(imgWatch, 100);
                    }
                    else
                    { errorCallback(); }
                }, loadCallback: function () {
                    magnifier.$lens.append(magnifier.$largeImage); function moveWatch() {
                        if (magnifier.$largeImage.width())
                        { magnifier.largeWidth = magnifier.$largeImage.width(); magnifier.largeHeight = magnifier.$largeImage.height(); }
                        if (magnifier.largeWidth) { magnifier.$loader.remove(); clearInterval(moveID); }
                    }
                    var moveID = setInterval(moveWatch, 100);
                }, errorCallback: function ()
                { alert("large image could not be loaded"); }, addHandles: function ()
                { magnifier.$sensor.css({ width: magnifier.$img.width() + "px", height: magnifier.$img.height() + "px", top: magnifier.$img.offset().top + "px", left: magnifier.$img.offset().left + "px", backgroundColor: "#fff", opacity: "0" }).mousemove(function (e) { magnifier.handleMouseMove(e); }).mouseout(function (e) { magnifier.handleMouseOut(e); }); }, handleMouseMove: function (e) {
                    magnifier.$lens.css({ left: parseInt(e.pageX - (magnifier.options.lensWidth * .5)) + "px", top: parseInt(e.pageY - (magnifier.options.lensHeight * .5)) + "px" }); if (magnifier.options.delay)
                    { if (!magnifier.timeOut) { magnifier.timeOut = setTimeout(function () { magnifier.$lens.css('visibility', 'visible'); }, magnifier.options.delay); } }
                    else { magnifier.$lens.css('visibility', 'visible'); }
                    if (magnifier.largeWidth) { magnifier.positionLargeImage(e); }
                    magnifier.$lens.css('display', 'block');
                }, positionLargeImage: function (e)
                { var scale = {}; scale.x = magnifier.largeWidth / magnifier.$img.width(); scale.y = magnifier.largeHeight / magnifier.$img.height(); var left = -scale.x * Math.abs((e.pageX - magnifier.$img.offset().left)) + magnifier.options.lensWidth / 2 + "px"; var top = -scale.y * Math.abs((e.pageY - magnifier.$img.offset().top)) + magnifier.options.lensHeight / 2 + "px"; magnifier.$largeImage.css({ position: 'absolute', left: left, top: top, display: 'block' }); }, handleMouseOut: function (e) {
                    if (magnifier.timeOut) { clearTimeout(magnifier.timeOut); magnifier.timeOut = null; }
                    magnifier.$lens.css({ visibility: 'hidden', display: 'none' });
                }
                }; magnifier.init.call(this, options);
            });
        }
        });
    })(jQuery);

    //magnify
    //ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset
    $('#ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset').wrap('<a class="bigA" href="' + $('#ctl00_cpContent_pContent_ctl03_ctl00_ctl00_imgDefaultAsset').attr('data-magnifysrc') + '" rel="magnify"/>');
    function mag() {
        $('a[rel*=magnify]').magnify({ lensWidth: 200, lensHeight: 200, link: false, delay: 100 });
    }

    $('.adefaultsmall, .arelatedsmall, .aalternativesmall').click(function () {
        vBig = $(this).attr('grotefoto');
        $('.bigA').attr('href', vBig);
        mag();
    });
    setTimeout(function () { mag(); }, 500);
    $(function () {
        // check login form..
        var is_bybox = $.getUrlVar('loginbox');
        if (is_bybox != null) {
            if (is_bybox == "true") {
                $('.clientlogin').fadeIn();
            }
        }

        var $mybook = $('#mybook');
        var $bttn_next = $('#next_page_button');
        var $bttn_prev = $('#prev_page_button');
        var $loading = $('#loading');
        var $mybook_images = $mybook.find('img');
        var cnt_images = $mybook_images.length;
        var loaded = 0;
        //preload all the images in the book,
        //and then call the booklet plugin

        $mybook_images.each(function () {
            var $img = $(this);
            var source = $img.attr('src');
            $('<img/>').load(function () {
                ++loaded;
                if (loaded == cnt_images) {
                    $loading.hide();
                    $bttn_next.show();
                    $bttn_prev.show();
                    $mybook.show().booklet({
                        name: null,                            // name of the booklet to display in the document title bar
                        width: 798,                             // container width
                        height: 485,                             // container height
                        speed: 600,                             // speed of the transition between pages
                        direction: 'LTR',                           // direction of the overall content organization, default LTR, left to right, can be RTL for languages which read right to left
                        startingPage: 0,                               // index of the first page to be displayed
                        easing: 'easeInOutQuad',                 // easing method for complete transition
                        easeIn: 'easeInQuad',                    // easing method for first half of transition
                        easeOut: 'easeOutQuad',                   // easing method for second half of transition

                        closed: false,                           // start with the book "closed", will add empty pages to beginning and end of book
                        closedFrontTitle: null,                            // used with "closed", "menu" and "pageSelector", determines title of blank starting page
                        closedFrontChapter: null,                            // used with "closed", "menu" and "chapterSelector", determines chapter name of blank starting page
                        closedBackTitle: null,                            // used with "closed", "menu" and "pageSelector", determines chapter name of blank ending page
                        closedBackChapter: null,                            // used with "closed", "menu" and "chapterSelector", determines chapter name of blank ending page
                        covers: false,                           // used with  "closed", makes first and last pages into covers, without page numbers (if enabled)

                        pagePadding: 0,                              // padding for each page wrapper
                        pageNumbers: false,                            // display page numbers on each page

                        hovers: false,                            // enables preview pageturn hover animation, shows a small preview of previous or next page on hover
                        overlays: false,                            // enables navigation using a page sized overlay, when enabled links inside the content will not be clickable
                        tabs: false,                           // adds tabs along the top of the pages
                        tabWidth: 60,                              // set the width of the tabs
                        tabHeight: 20,                              // set the height of the tabs
                        arrows: false,                           // adds arrows overlayed over the book edges
                        cursor: 'pointer',                       // cursor css setting for side bar areas

                        hash: false,                           // enables navigation using a hash string, ex: #/page/1 for page 1, will affect all booklets with 'hash' enabled
                        keyboard: true,                            // enables navigation with arrow keys (left: previous, right: next)
                        next: $bttn_next,          			// selector for element to use as click trigger for next page
                        prev: $bttn_prev,          			// selector for element to use as click trigger for previous page

                        menu: null,                            // selector for element to use as the menu area, required for 'pageSelector'
                        pageSelector: false,                           // enables navigation with a dropdown menu of pages, requires 'menu'
                        chapterSelector: false,                           // enables navigation with a dropdown menu of chapters, determined by the "rel" attribute, requires 'menu'

                        shadows: true,                            // display shadows on page animations
                        shadowTopFwdWidth: 166,                             // shadow width for top forward anim
                        shadowTopBackWidth: 166,                             // shadow width for top back anim
                        shadowBtmWidth: 50,                              // shadow width for bottom shadow

                        before: function () { },                    // callback invoked before each page turn animation
                        after: function () { }                     // callback invoked after each page turn animation
                    });
                }
            }).attr('src', source);
        });

    });

    //klanten login
    $('.topclient .button').bind('click', function () {
        $('.clientlogin').fadeIn();
    });
    var mouse_is_inside = false;
    $('.clientlogin').hover(function () {
        mouse_is_inside = true;
    }, function () {
        mouse_is_inside = false;
    });

    $("body").mouseup(function () {
        if (!mouse_is_inside) $('.clientlogin').fadeOut();
    });

    //folderslider
    if ($('#slider').length) {
        var folders = $('#slider a').size();
        var slidePos = $('#slider').css('left').replace('px', '') * 1;
        var slideOffset = $('#sliderWrap').offset();
        var slideOffsetLeft = slideOffset.left;
        var slideW = $('#sliderWrap').width();
        var leftA = $('#slider a:nth-child(' + 1 + ')')
        var offset = leftA.offset();
        var curPos = (offset.left - slideOffsetLeft);
        var curA = 1;
        var steps = 5;
        $('#slideLeft img').attr('src', $('#slideLeft img').attr('src').replace('.png', '_false.png'));
        $('#slideLeft').addClass('off');
        if (folders <= steps) {
            $('#slideRight img').attr('src', $('#slideRight img').attr('src').replace('.png', '_false.png'));
            $('#slideRight').addClass('off');
        }
        $('#slideRight, #slideLeft').hover(function () {
            slidePlayPause();
            copyspeed = pausespeed;
        }, function () {
            copyspeed = marqueespeed;
        });
        $('#slideRight:not(.off)').live('mouseup', function () {

            tmpA = curA;
            curA = curA + steps;
            if (curA <= folders) {
                leftA = $('#slider a:nth-child(' + (curA) + ')');
                tmp = leftA.offset();
                curPos = (tmp.left - slideOffsetLeft - $('#slider').css('left').replace('px', '') * 1) - 5;
                $('#slideLeft img').attr('src', $('#slideLeft img').attr('src').replace('_false.png', '.png'));
                $('#slideLeft').removeClass('off');
                if ((curA + steps) > folders) {
                    $('#slideRight img').attr('src', $('#slideRight img').attr('src').replace('.png', '_false.png'));
                    $('#slideRight').addClass('off');
                }
                $('#slider').animate({ 'left': -curPos + 'px' }, 1000);
            } else {
                curA = tmpA;
            }
            $(this).blur();
            return false;
        });
        $('#slideLeft:not(.off)').live('mouseup', function () {
            tmpA = curA;
            curA = curA - steps;
            if (curA >= 1) {
                leftA = $('#slider a:nth-child(' + (curA) + ')');
                tmp = leftA.offset();
                curPos = (tmp.left - slideOffsetLeft - $('#slider').css('left').replace('px', '') * 1) - 5;
                $('#slideRight img').attr('src', $('#slideRight img').attr('src').replace('_false.png', '.png'));
                $('#slideRight').removeClass('off');
                if ((curA - steps) < 1) {
                    $('#slideLeft img').attr('src', $('#slideLeft img').attr('src').replace('.png', '_false.png'));
                    $('#slideLeft').addClass('off');
                }
                $('#slider').animate({ 'left': -curPos + 'px' }, 1000);
            } else {
                curA = tmpA;
            }
            $(this).blur();
            return false;
        });

    }

    $.extend({
        getUrlVars: function () {
            var vars = [], hash;
            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
            return vars;
        },
        getUrlVar: function (name) {
            return $.getUrlVars()[name];
        }
    });

});

