/*
*
* TERMS OF USE - EASING EQUATIONS
* 
* Open source under the BSD License. 
* 
* Copyright � 2001 Robert Penner
* All rights reserved.
*/
// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend(jQuery.easing,
{
    def: 'easeOutExpo',
    swing: function (x, t, b, c, d) {
        //alert(jQuery.easing.default);
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
    }
});



/** "
* jQuery.ScrollTo - Easy element scrolling using jQuery.
* Copyright (c) 2007-2009 Ariel Flesler 
* Dual licensed under MIT and GPL.
* @author Ariel Flesler
* @version 1.4.2
*/
; (function (d) { var k = d.scrollTo = function (a, i, e) { d(window).scrollTo(a, i, e) }; k.defaults = { axis: 'xy', duration: parseFloat(d.fn.jquery) >= 1.3 ? 0 : 1 }; k.window = function (a) { return d(window)._scrollable() }; d.fn._scrollable = function () { return this.map(function () { var a = this, i = !a.nodeName || d.inArray(a.nodeName.toLowerCase(), ['iframe', '#document', 'html', 'body']) != -1; if (!i) return a; var e = (a.contentWindow || a).document || a.ownerDocument || a; return d.browser.safari || e.compatMode == 'BackCompat' ? e.body : e.documentElement }) }; d.fn.scrollTo = function (n, j, b) { if (typeof j == 'object') { b = j; j = 0 } if (typeof b == 'function') b = { onAfter: b }; if (n == 'max') n = 9e9; b = d.extend({}, k.defaults, b); j = j || b.speed || b.duration; b.queue = b.queue && b.axis.length > 1; if (b.queue) j /= 2; b.offset = p(b.offset); b.over = p(b.over); return this._scrollable().each(function () { var q = this, r = d(q), f = n, s, g = {}, u = r.is('html,body'); switch (typeof f) { case 'number': case 'string': if (/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)) { f = p(f); break } f = d(f, this); case 'object': if (f.is || f.style) s = (f = d(f)).offset() } d.each(b.axis.split(''), function (a, i) { var e = i == 'x' ? 'Left' : 'Top', h = e.toLowerCase(), c = 'scroll' + e, l = q[c], m = k.max(q, i); if (s) { g[c] = s[h] + (u ? 0 : l - r.offset()[h]); if (b.margin) { g[c] -= parseInt(f.css('margin' + e)) || 0; g[c] -= parseInt(f.css('border' + e + 'Width')) || 0 } g[c] += b.offset[h] || 0; if (b.over[h]) g[c] += f[i == 'x' ? 'width' : 'height']() * b.over[h] } else { var o = f[h]; g[c] = o.slice && o.slice(-1) == '%' ? parseFloat(o) / 100 * m : o } if (/^\d+$/.test(g[c])) g[c] = g[c] <= 0 ? 0 : Math.min(g[c], m); if (!a && b.queue) { if (l != g[c]) t(b.onAfterFirst); delete g[c] } }); t(b.onAfter); function t(a) { r.animate(g, j, b.easing, a && function () { a.call(this, n, b) }) } }).end() }; k.max = function (a, i) { var e = i == 'x' ? 'Width' : 'Height', h = 'scroll' + e; if (!d(a).is('html,body')) return a[h] - d(a)[e.toLowerCase()](); var c = 'client' + e, l = a.ownerDocument.documentElement, m = a.ownerDocument.body; return Math.max(l[h], m[h]) - Math.min(l[c], m[c]) }; function p(a) { return typeof a == 'object' ? a : { top: a, left: a} } })(jQuery);


// Slide Show Functions
(function ($) {
    $.fn.my_place = function (settings) {
        var config = { 'autoAnimate': 'true', 'animateDelay': 4000, 'panelToShowOnStart': 0, 'panelAnimateSpeed': 450, 'panelAnimateEasing': 'easeOutExpo', 'animateDirection': 1 };
        var panels = [];
        var panelShadeWidth = 0;
        var panelWidth = 0;
        var animatePos = 0;
        var animateTimer;

        if (settings) $.extend(config, settings);

        function movePanel(panelIndex, pos) {
            $(panels[panelIndex]).animate({ left: pos + 'px' }, { duration: config.panelAnimateSpeed, easing: config.panelAnimateEasing });
        }

        function showSpecificPanel(panelIndex) {
            // Move the panels above it to the right
            for (var i = panels.length - 1; i > panelIndex; i--) { movePanel(i, (panelWidth + panelShadeWidth * (i - 1))) }
            // Move the panels below it, to the left
            for (var i = 0; i <= panelIndex; i++) { movePanel(i, panelShadeWidth * i); }
            animatePos = panelIndex;

        }

        function animatePanel() {
            animatePos += config.animateDirection;
            if (config.autoAnimate) {
                showSpecificPanel(animatePos);
                if (animatePos <= 0 || animatePos >= panels.length - 1) {
                    config.animateDirection *= -1;
                }

                setTimeout(animatePanel, config.animateDelay)
            }
        }

        this.each(function () {
            // element-specific code here
            // Calculate the initial positions of the details and place the panels in the appropriate position
            panels = $(this).find('ul.panel>li');
            panelWidth = $(panels[0]).width();
            panelShadeWidth = ($(this).width() - panelWidth) / (panels.length - 1);

            // Set the width of the control anchors
            $(this).find('h2>a').width(panelWidth - 2);

            // Jump to the correct panel and begin animation
            showSpecificPanel(config.panelToShowOnStart);
            if (config.autoAnimate) {
                animateTimer = setTimeout(animatePanel, config.animateDelay)
            }

            // Add in a node for the shadow on the left of each panel
            $(panels).append('<span class="shadow">&nbsp;</span>')


            // Add the event handlers on to the control anchors to allow them to move
            $(this).find('h2>a').mouseover(function (e) {
                if (config.autoAnimate) {
                    config.autoAnimate = false;
                    clearTimeout(animateTimer);
                }
                // Get the index of the list item that needs to be moved
                var panelIndex = $('.panelAccordion > ul > li').index($(this).parents('li:first'));
                $(".panelAccordion > ul > li").stop(true, false)

                showSpecificPanel(panelIndex)
            });

            // Add the event handlers on to the control anchors to allow them to move
            $(this).find('span.shadow').mouseover(function (e) {
                if (config.autoAnimate) {
                    config.autoAnimate = false;
                    clearTimeout(animateTimer);
                }
                // Get the index of the list item that needs to be moved
                var panelIndex = $('.panelAccordion > ul > li').index($(this).parents('li:first'));
                $(".panelAccordion > ul > li").stop(true, false)

                showSpecificPanel(panelIndex - 1)
            });



        });

        return this;

    };
})(jQuery);

// Start Carousel v2.0

var _DisplayWidthModules;
var _ModuleSize;

var _SteppingToRight = true;
var _LeftSideModule = 0;
var _Offset = 0;
var _StepTick = 3000;
var _AutoAnimationOn = false;
var _AutoStep = 500;
var _ManualStep = 250;



// Initiate the carousel
function caro_init() {
    var StripWidth = 0;
    var ViewportWidth = parseInt($('#strp_caro').css('width'));

    _ModuleSize = (parseInt($('#strp_caro ul li:last').css('margin-left')) +
        parseInt($('#strp_caro ul li:last').css('width')) +
        parseInt($('#strp_caro ul li:last').css('margin-right')));

    _DisplayWidthModules = 0;
    $('#strp_caro ul li').each(function (index) {
        StripWidth += (parseInt($(this).css('margin-left')) +
            parseInt($(this).css('width')) +
            parseInt($(this).css('margin-right')));

        if (StripWidth <= ViewportWidth) {
            _DisplayWidthModules++;
        }
    });
    $('#strp_caro ul').css('width', StripWidth + "px");

    if ($('#strp_caro ul li').length > _DisplayWidthModules) {
        $('#strp_caro').append('<span class="prevArrow" style="display: none;">Prev</span>');
        $('#strp_caro').append('<span class="nextArrow">Next</span>');

        $('#strp_caro').click(function (e) {
            _AutoAnimationOn = false;
            if ($(e.target).hasClass('nextArrow')) {
                HandleAnimation(true, _ManualStep);
            }
            if ($(e.target).hasClass('prevArrow')) {
                HandleAnimation(false, _ManualStep);
            }
        });

        $('#strp_caro').mouseover(function (e) {
            _AutoAnimationOn = false;
        });

        if ($('#strp_caro').hasClass('autoAnimate')) {
            _AutoAnimationOn = true;
            setTimeout('HandleAnimationTick()', _StepTick);
        }
    }
}

function HandleAnimationTick() {
    if (_AutoAnimationOn) {
        HandleAnimation(_SteppingToRight, _AutoStep);
        if (_LeftSideModule < 1) {
            _SteppingToRight = true;
        }
        else if ((_LeftSideModule + _DisplayWidthModules) >= $('#strp_caro ul li').length) {
            _SteppingToRight = false;
        }
        setTimeout('HandleAnimationTick()', _StepTick);
    }
}

function HandleAnimation(MoveRight, AnimationSpeed) {
    var StepSize = 0;

    if ((MoveRight) && ((_LeftSideModule + _DisplayWidthModules) < $('#strp_caro ul li').length)) {
        _LeftSideModule++;
        StepSize = -_ModuleSize;
        if ((_LeftSideModule + _DisplayWidthModules) == $('#strp_caro ul li').length) {
            $('#strp_caro span.nextArrow').fadeOut();
        }
        if (_LeftSideModule == 1) {
            $('#strp_caro span.prevArrow').fadeIn();
        }
    }
    else if ((!MoveRight) && (_LeftSideModule > 0)) {
        _LeftSideModule--;
        StepSize = _ModuleSize;
        if (_LeftSideModule == 0) {
            $('#strp_caro span.prevArrow').fadeOut();
        }
        if ((_LeftSideModule + _DisplayWidthModules) == ($('#strp_caro ul li').length - 1)) {
            $('#strp_caro span.nextArrow').fadeIn();
        }
    }
    _Offset += StepSize;
    $('#strp_caro ul').animate({ left: (_Offset) + 'px' }, { duration: AnimationSpeed, easing: 'easeOutExpo', complete: function () { } });
}
// End Carousel

// free c function 1
(function ($) {
    $.fn.my_caro = function (settings) {
        var config = { 'positionChangeSpeed': 500, 'animateEasing': 'easeOutExpo' };
        var carousel
        var listToMove
        var widthOfContainer
        var widthOfElement
        var noElementsInCarousel
        var maxPosition

        if (settings) $.extend(config, settings);

        function fadeNavigation(newPosition) {
            var listPos = $(listToMove).position().left + newPosition
            var showNextArrow = false
            var showPrevArrow = false
            var nextArrow = carousel.find('span.nextArrow')[0]
            var prevArrow = carousel.find('span.prevArrow')[0]

            if (listPos < 0) { showPrevArrow = true }
            if (listPos > maxPosition) { showNextArrow = true }

            if (showNextArrow) { $(nextArrow).fadeIn(); } else { $(nextArrow).fadeOut() }
            if (showPrevArrow) { $(prevArrow).fadeIn(); } else { $(prevArrow).fadeOut() }

        }

        this.each(function () {
            carousel = $(this);
            widthOfContainer = carousel.width();
            widthOfElement = carousel.find('li:first').width()
            noElementsInCarousel = carousel.find('li').length
            maxPosition = (noElementsInCarousel - (widthOfContainer / widthOfElement)) * widthOfElement * -1

            listToMove = carousel.find('ul:first')

            if (noElementsInCarousel * widthOfElement > widthOfContainer) {
                $(listToMove).css('width', noElementsInCarousel * widthOfElement + "px")
                carousel.append('<span class="prevArrow" style="display: none;">Prev</span>');
                carousel.append('<span class="nextArrow">Next</span>');

                carousel.click(function (e) {
                    if (carousel.find('ul:animated').length == 0) {
                        if ($(e.target).hasClass('nextArrow')) {
                            fadeNavigation(widthOfElement * -1)
                            $(listToMove).animate({ 'left': $(listToMove).position().left - widthOfElement + "px" }, { duration: config.positionChangeSpeed, easing: config.animateEasing });
                        }
                        if ($(e.target).hasClass('prevArrow')) {
                            fadeNavigation(widthOfElement)
                            $(listToMove).animate({ 'left': $(listToMove).position().left + widthOfElement + "px" }, { duration: config.positionChangeSpeed, easing: config.animateEasing });
                        }
                    }
                })
            }
        })
    }
})(jQuery);



$(document).ready(function () {

    // Initialise the carousel (v2) if we have
    if ($('#strp_caro')) {
        caro_init();
    }

   //

    // Set up the homepage 
    if ($('#slide_show_panel').length) {
        $('#slide_show_panel').my_place();
    }

 
	// gA

});

//*/




// BEGIN Slide Show

(function ($) {
    $.fn.put_slide_show = function (Settings) {

        var ThisSlider;
        var Frames = [];
        var krant_frame = 0;
        var SlideEnabled = false;
        var SlideTimer = 0;
        var SliderWidth = 0;
        var ani_in_prog = false;

        var TimeoutController;

        var Config = {
            'SlideEnabled': false,
            'DelayOnLoad': 6900,
            'FrameHoldDuration': 5000,
            'FrameMovementDuration': 999
        };

        if (Settings) $.extend(Config, Settings);

        return this.each(function () {
            // Get our actual slider top operate within and set up the vitals
            ThisSlider = $(this)[0];
            SliderWidth = $(ThisSlider).width()

            // Initialise the frames
            frames_init();


            // Attach click event to all "next offer" links
            handle_clks();

            // Start things moving
            if (Config.SlideEnabled) setTimeout(frames_anim, Config.DelayOnLoad);
        });

        function frames_init() {
            // Get all frames as marked by the .frame class
            Frames = $('.frame', ThisSlider);

            // If we have more than zero frames, move the first one to display position
            if (Frames.length > 0) $(Frames[0]).css({ left: 0 });

            // If we have more than one frame, enable the slider
            if (Frames.length > 1) Config.SlideEnabled = true;
        }

        function frames_anim() {
            // Get our next frame index
            var nxt_frame = krant_frame + 1;
            if (nxt_frame >= Frames.length) nxt_frame = 0;

            // Set up the next frame ready to slide in
            $(Frames[nxt_frame]).css({ 'left': SliderWidth + 'px', top: '0' });

            // Set the frames moving and update current frame
            $(Frames[krant_frame]).animate({ 'left': -SliderWidth + 'px' }, Config.FrameMovementDuration, 'easeInQuint');
            $(Frames[nxt_frame]).animate({ 'left': '0' }, Config.FrameMovementDuration, 'easeInQuint');
            krant_frame = nxt_frame;

            // Handle animation in progress to prevent a raft of clicks
            ani_in_prog = true;
            setTimeout(ani_stop, Config.FrameMovementDuration);
        }

        function ani_stop() {

            ani_in_prog = false;

            if (Config.SlideEnabled) { 
                TimeoutController = setTimeout(frames_anim, Config.FrameHoldDuration) 
            };
        }


        function handle_clks() {
            $('.nxt_offer a', ThisSlider).click(function (e) {

                // Prevent default action
                e.preventDefault();

                // Stop animation
                Config.SlideEnabled = false;
                clearTimeout(TimeoutController);

                // Step to next frame
                if (!ani_in_prog) frames_anim();

            });

  
            $('.offerOpener a', ThisSlider).click(function (e) {

                // Prevent default action
                e.preventDefault();

                // Stop animation
                Config.SlideEnabled = false;
                clearTimeout(TimeoutController);

                var OfferBoxName = '#' + $(e.target).parents('.frame').attr('id') + 'Detail';
                $('#offer_block_selected').html($(OfferBoxName).html());

                $('#bg_offer_pop').css({
                    'display': 'block',
                    'z-index': '1500'
                });
                $('#bg_offer_pop').height($(window).height());
                $('#bg_offer_pop').width($(window).width());

                // Calculate the height of the box
                var BoxHeight = 190 + ($('#offer_block_selected select').length * 26);
                var BoxTop = 0;
                if ($(window).height() > BoxHeight) {
                    BoxTop = (($(window).height() - BoxHeight) / 2);
                }

                $('#offer_block_selected').css({
                    'display' : 'block',
                    'position' : 'fixed',
                    'top' : BoxTop + 'px',
                    'left' : (($(window).width() - 400) / 2) + 'px',
                    'background' : '#ffffff',
                    'border' : '2px solid #ccc',
                    'z-index' : '2001'});

                // Offer box has to reside OUTSIDE slider due to MSIE z-index bug, so set up its closer here
                $('#offer_block_selected .closer a').click(function (e) {

                    // Prevent default action
                    e.preventDefault();

                    $('#bg_offer_pop').css({ 'display': 'none' });
                    $('#offer_block_selected').css({ 'display': 'none' });
                });
            });
        }
    };
	
})(jQuery);
