
var muteClick = false;

(function () {




    var aw = {
        helper: {},
        canvas: {},
        settings: {
			sound: true,
            rotate: false,
            animationLevel: 3,
            slideAnimationSpeedLow: 1.5, // The lowest speed people will come down the slides
            slideAnimationSpeedHigh: 2, // The fastest speed people will come down the slides
			pauseAnimation: false
        }
    };
    var blankImage = "data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7";


    var contentVisible = false;

    var pagePos = [{
        x: 1600,
        y: 1050
    }, {
        x: 2200,
        y: 1200
    }, {
        x: 2200,
        y: 1900
    }, {
        x: 1500,
        y: 2350
    }, {
        x: 930,
        y: 1900
    }, {
        x: 800,
        y: 1100
    }
  ];

    (function () {
        var totalRotateAmount = 0;
		var pufferSound = "";

        aw.helper.populateContent = function (url) {
            _gaq.push(['_trackPageview', url]);

            document.body.style.cursor = 'default';

            // Try to stop any memory leaks
            $('#populateContent img').attr("src", blankImage);
            $("#populateContent a").unbind('click');
            $("#populateSocialMedia a").unbind('click');


            $('#populateContent').html('<div class="loader"/>');



            if (!contentVisible) {
                $('.content-wrapper-outer').css('visibility', 'visible');
                $('.content-wrapper-outer').hide();
                $('.content-wrapper-outer').fadeIn(1500);
                contentVisible = true;
            }


            $('#populateContent').load(url, function (data) {

                $(".content-wrapper-outer a").click(linkClick);


        $('#populateContent table:not(.special)').wrap("<div class='table-outer'></div>");
        $('#populateContent .download-link a').append("<br/><span>Download</span>");
        
            

                $(".subForm").submit(function () {

                    var form = $(this);
                    $.ajax({
                        type: "POST",
                        url: "WebService.asmx/subscribe",
                        data: '{ name: "' + $('.name', form).val() + '", email: "' + $('.email', form).val() + '" }',
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (msg) {

                            if (msg.d.success == 'false') {
                                $('.errorMsg', form).html("Error: " + msg.d.msg);
                            }
                            else {
                                form.html("<div>Thank your for subscribing</div>");
                            }

                        }
                    });


                    return false;
                });



                var imgCount = $('#photogallery img').length;
                if (imgCount > 0) {

                    //initialize counter
                    var next = 0;
                    var current = 0;
                    $('#photogallery img').each(function () {
                        $(this).hide();
                    });

                    //show the first image
                    $('#photogallery img:first').show();

                    if (imgCount > 1) {
                        //set the prev button
                        $("a.left").click(function () {
                            //check the index
                            next = current - 1;
                            if (next < 0) {
                                next = imgCount - 1; //reset the count
                            }

                            //hide the current item and show the next item
                            $("#photogallery img:eq(" + next + ")").fadeIn(500);
                            $("#photogallery img:eq(" + current + ")").fadeOut(500);

                            //set current to be the next
                            current = next;
                        });

                        //set the nextbutton
                        $("a.right").click(function () {
                            //check the index
                            next = current + 1;
                            if (next > (imgCount - 1)) {
                                next = 0; //reset the count
                            }

                            //hide the current item and show the next item
                            $("#photogallery img:eq(" + next + ")").fadeIn(500);
                            $("#photogallery img:eq(" + current + ")").fadeOut(500);

                            //set current to be the next
                            current = next;
                        });
                    }
                    else {
                        $("a.left").hide();
                        $("a.right").hide();
                    }
                }



                $("#photoTab").click(function () {
                    toggleGallery("photo");
                });

                $("#videoTab").click(function () {
                    toggleGallery("video");
                });

                if ($("#photoTab").length > 0) {
                    if ($("#photoTab").hasClass("active")) {
                        toggleGallery("photo");
                    }
                };

                if ($("#videoTab").length > 0) {
                    if ($("#videoTab").hasClass("active")) {
                        toggleGallery("video");
                    }
                };


            });

            //hide the social media panel initially
            var socialMediaPanel = $('#populateSocialMedia');
            socialMediaPanel.hide();
            if (url.indexOf("/rides-attractions") != -1 && $("h2.landing").length == 0 && url.indexOf("?fear") == -1 && url != "/rides-attractions/") {
                $.ajax({
                    url: '/socialmedia',
                    data: { url: url },
                    success: function (data) {
                        socialMediaPanel.html(data);
                        socialMediaPanel.show();
                        FB.XFBML.parse(socialMediaPanel[0]);
                    },
                    dataType: 'html',
                    cache: false
                });
            }

            var urlToUse = url;
            if (url.indexOf("?fear") != -1) {
                urlToUse = "/rides-attractions/";
            }

            $('#footer-links-nav').load('/test', { url: urlToUse }, function () {
                $("#footer-links-nav a").click(linkClick);
            });
        };

        aw.helper.scrollToWorld = function (animate) {
            var elem = $('html');
            if ($.browser.webkit) {
                elem = $('body');
            }

            if (animate) {
                elem.stop(true).animate({
                    scrollTop: 4500
                }, 1500, function () {
                    if (mobi.mobile == "True") {
                        $("nav").css("top", ($(document).scrollTop()) + "px");
                    }
                });
            }
            else {
                elem.scrollTop(4500);
            }


            return false;
        }

        aw.helper.scrollToContent = function (animate) {
            var elem = $('html');
            if ($.browser.webkit) {
                elem = $('body');
            }

            if (elem.scrollTop() != 0) {
                if (animate) {
                    elem.stop(true).animate({
                        scrollTop: 0
                    }, 1500, function () {
                        if (mobi.mobile == "True") {
                            $("nav").css("top", ($(document).scrollTop()) + "px");
                        }
                    });
                }
                else {
                    elem.scrollTop(0);
                }
            }

            return false;
        };

        aw.helper.rotateToPage = function (pageNumber) {

            _gaq.push(['_trackEvent', 'World', 'Page View', pageNumber]);

            pageNumber = parseFloat(pageNumber);
            rotateAmount = (currentPage - pageNumber) * 60
            currentPage = pageNumber;
            pageDetails = pagePos[currentPage - 1];

            rotate(rotateAmount);

            return false;
        };

        aw.helper.refresh = function () {
            drawAllFrames(false);
        };

        aw.models = [
    {
        page: [5],
		sound: "Picnic",
        layer2: 'picnicArea',
        hitArea: 'parentClick',
        hoverText: 'Parents',
        clickUrl: '/visitor-info/parents/'
    }, {
        page: [1],
		sound: "Tickets",
        layer1: 'homeTickets',
        onOff: [homeTicketsFlash1, homeTicketsFlash2],
        animations: {
            list: {}
        }
    }, {
        page: [4],
		sound: "Helicopter",
        hitArea: 'buyWhaleClick',
        hoverText: 'Buy Tickets',
        clickUrl: '/tickets/',
        animations: {
            list: {
                "whale": {
                    animation: new whalePath,
                    ctx: 'whale',
                    lvl: 3
                }
            }
        }
    }, {
        page: [5],
		sound: "Monkey",
        hitArea: 'ticketMonkeyClick',
        hoverText: 'Buy Tickets',
        clickUrl: '/tickets/',
        animations: {
            list: {
                "ticketMonkey": {
                    animation: new ticketMonkeyPath,
                    ctx: 'ticketMonkey',
                    lvl: 3
                }
            }
        }
    }, {
        page: [6],
        hitArea: 'hotdogClick',
        hoverText: 'Eats and<br/>Drinks',
        clickUrl: '/visitor-info/eats-and-drinks/',
        layer1: 'hotdogMan'
    }, {
        page: [2],
        hitArea: 'dominoesClick',
        hoverText: 'Domino\'s 2Go!',
        clickUrl: '/visitor-info/eats-and-drinks/domino\'s-2go!/'
    }, {
        page: [1],
		sound: "Tickets",
        hitArea: 'homeTicketsClick',
        hoverText: 'Buy Tickets',
        clickUrl: '/tickets/'
    }, {
        page: [1, 2],
		sound: "Dragon",
        ctx: 'dragonExpress',
        hitArea: 'dragonExpressClick',
        hoverText: 'Dragon<br/>Express',
        clickUrl: '/rides-attractions/dragon-express/',
        onOff: [dragonExpressFire]
    }, {
        page: [1],
		sound: "Kahuna",
        ctx: 'kahunaFalls',
        layer1: 'kahunaFallsLayer1',
        layer2: 'kahunaFallsLayer2',
        hitArea: 'kahunaFallsClick',
        hoverText: 'Kahuna<br/>Falls',
        clickUrl: '/rides-attractions/kahuna-falls/',
        animations: {
            alt1: function (ctx) {
                if (aw.settings.animationLevel < 2) {
                    doAlt1List(this, ctx);
                    var smokePos = new smokePath();
                    smokePos.update();
                    ctx.save();
                    ctx.translate(smokePos.x, smokePos.y);
                    smoke(ctx);
                    ctx.restore();
                }
            },
            add: function () {
                var list = this.list;

                function finished(name) {
                    addSlideAnimation(name, list[name], finished, true);
                }

                addSlideAnimation('kahunaFallsTopSlide', this.list['kahunaFallsTopSlide'], finished);
                addSlideAnimation('kahunaFallsSlideRight', this.list['kahunaFallsSlideRight'], finished, true);
                addSlideAnimation('kahunaFallsSlideLeft', this.list['kahunaFallsSlideLeft'], finished);
                addSlideAnimation('kahunaFallsSlideBottomLeft', this.list['kahunaFallsSlideBottomLeft'], finished, true);
                addSlideAnimation('kahunaFallsSlideBottomRight', this.list['kahunaFallsSlideBottomRight'], finished);
                addSlideAnimation('kahunaFallsSlideBottom', this.list['kahunaFallsSlideBottom'], finished);


                var smokeLevel = 1;
                var smokePos = new smokePath();

                smokePos.update();
                clearInterval(smokeInterval);
                smokeInterval = setInterval(function () {
                    smokeLevel++;
                    if (smokeLevel > 4) {
                        smokeLevel = 1;
                    }
                }, 750);

                addAnimation('smoke', {
                    lvl: 2,
                    type: 'function',
                    animation: function (ctx) {
                        ctx.save();
                        ctx.translate(smokePos.x, smokePos.y);

                        switch (smokeLevel) {
                            case 1:
                                ctx.scale(0.25, 0.25);
                                ctx.translate(50, 150);
                                break;

                            case 2:
                                ctx.scale(0.5, 0.5);
                                ctx.translate(17, 50);
                                break;

                            case 3:
                                ctx.scale(0.75, 0.75);
                                ctx.translate(6, 17);
                                break;
                        }

                        smoke(ctx);


                        ctx.restore();
                    }
                });

            },
            list: {
                "kahunaFallsTopSlide": {
                    animation: new kahunaFallsTopSlidePath(),
                    ctx: 'kahunaFallsTopSlideBoy',
                    lvl: 2,
                    altOffset: 0.4
                },
                "kahunaFallsSlideRight": {
                    animation: new kahunaFallsSlideRightPath(),
                    ctx: 'kahunaFallsSlideRightPerson',
                    lvl: 2,
                    altOffset: 0.4
                },
                "kahunaFallsSlideLeft": {
                    animation: new kahunaFallsSlideLeftPath(),
                    ctx: 'kahunaFallsSlideLeftPerson',
                    lvl: 2
                },
                "kahunaFallsSlideBottomLeft": {
                    animation: new kahunaFallsSlideBottomLeftPath(),
                    ctx: 'kahunaFallsSlideBottomLeftPerson',
                    lvl: 2,
                    altOffset: 2
                },
                "kahunaFallsSlideBottomRight": {
                    animation: new kahunaFallsSlideBottomRightPath(),
                    ctx: 'kahunaFallsSlideBottomRightPerson',
                    lvl: 2,
                    altOffset: 2
                },
                "kahunaFallsSlideBottom": {
                    animation: new kahunaFallsSlideBottomMiddlePath(),
                    ctx: 'kahunaFallsSlideBottomMiddlePerson',
                    lvl: 2,
                    layer: 2,
                    altOffset: 1
                }
            }
        },
        onOff: [kahunaFallsGun1, kahunaFallsGun2, kahunaFallsSplash]
    }, {
        page: [1, 6],
		sound: "Shotgun",
        ctx: 'theShotgun',
        layer1: 'shotGunLayer',
        hitArea: 'theShotgunClick',
        hoverText: 'Shotgun',
        clickUrl: '/rides-attractions/the-shotgun/',
        animations: {
            add: function () {
                var list = this.list;

                function finished(name) {
                    addSlideAnimation(name, list[name], finished, true);
                };

                addSlideAnimation('theShotgunLeft', this.list['theShotgunLeft'], finished);
                addSlideAnimation('theShotgunRight', this.list['theShotgunRight'], finished, true);
            },
            amount: 2,
            list: {
                "theShotgunLeft": {
                    animation: new theShotgunLeftPersonPath(),
                    ctx: 'theShotgunLeftPerson',
                    lvl: 3,
                    altOffset: 0.7
                },
                "theShotgunRight": {
                    animation: new theShotgunRightPersonPath(),
                    ctx: 'theShotgunRightPerson',
                    lvl: 3,
                    altOffset: 0.3
                }
            }
        }
    }, {
        page: [4, 5],
        layer2: 'burger',
        hitArea: 'burgerClick',
        hoverText: 'Burger Bar',
        clickUrl: '/visitor-info/eats-and-drinks/'
    }, {
        page: [6],
		sound: "Flying_Ship",
        hitArea: 'galleonClick',
        hoverText: 'Buy Tickets',
        clickUrl: '/tickets/',
        animations: {
            list: {
                "galleon": {
                    animation: new galleonPath,
                    ctx: 'galleon',
                    lvl: 3,
                    altOffset: 5
                }
            }
        }
    }, {
        page: [6],
		sound: "Powersurge",
        ctx: 'powerSurge',
        hitArea: 'powerSurgeClick',
        hoverText: 'Power<br/>Surge',
        clickUrl: '/rides-attractions/power-surge/',
        animations: {
            alt1: function (ctx) {
                if (aw.settings.animationLevel < 2) {
                    ctx.save();
                    ctx.translate(1350, 1678);
                    powerSurgeWheel(ctx);
                    ctx.restore();

                    doAlt1List(this, ctx);
                }
            },
            add: function () {
                powerSurgeWheel.rotateClock = new clock(3.00, 0.00, -1, false, 0, linear, 2.0 * Math.PI, 1.00, 0.0000);
                powerSurgeWheel.rotateClock.start();

                addAnimation('powerSurgeWheel', {
                    lvl: 2,
                    type: 'function',
                    animation: function (ctx) {
                        ctx.save();
                        ctx.translate(1350, 1678);
                        ctx.rotate(powerSurgeWheel.rotateClock.value);
                        powerSurgeWheel(ctx);
                        ctx.restore();
                    }
                });

                addAnimationList(this);

            },
            list: {
                "powerSurgePerson1": {
                    animation: new psPath1(),
                    ctx: 'powerSurgePerson1',
                    rotateClock: new clock(1.50, 0.00, 1, false, 0, linear, 2.0 * Math.PI, 1.00, 0.0000),
                    lvl: 2
                },
                "powerSurgePerson2": {
                    animation: new psPath2(),
                    ctx: 'powerSurgePerson2',
                    rotateClock: new clock(1.50, 0.00, -1, false, 0, linear, 2.0 * Math.PI, 1.00, 0.0000),
                    lvl: 2
                },
                "powerSurgePerson3": {
                    animation: new psPath3(),
                    ctx: 'powerSurgePerson3',
                    rotateClock: new clock(1.50, 0.00, -1, false, 0, linear, 2.0 * Math.PI, 1.00, 0.0000),
                    lvl: 2
                },
                "powerSurgePerson4": {
                    animation: new psPath4(),
                    ctx: 'powerSurgePerson4',
                    rotateClock: new clock(1.50, 0.00, 1, false, 0, linear, 2.0 * Math.PI, 1.00, 0.0000),
                    lvl: 2
                },
                "powerSurgePerson5": {
                    animation: new psPath5(),
                    ctx: 'powerSurgePerson5',
                    rotateClock: new clock(1.50, 0.00, 1, false, 0, linear, 2.0 * Math.PI, 1.00, 0.0000),
                    lvl: 2
                },
                "powerSurgePerson6": {
                    animation: new psPath6(),
                    ctx: 'powerSurgePerson6',
                    rotateClock: new clock(1.50, 0.00, -1, false, 0, linear, 2.0 * Math.PI, 1.00, 0.0000),
                    lvl: 2
                }
            }
        }
    }, {
        page: [6],
        layer1: 'castleLayer',
        ctx: 'castle',
		sound: "Castle",
        hitArea: 'castleClick',
        hoverText: 'Castle<br/>Lookout',
        clickUrl: '/rides-attractions/castle-lookout/',
        animations: {
            list: {
                "castleKnight": {
                    animation: new castleKnightPath(),
                    ctx: 'castleKnight',
                    lvl: 3,
                    altOffset: 0.8
                }
            }
        }
    }, {
        page: [6],
		sound: "Paddle_Bumper_Boats",
        ctx: 'paddleBoats',
        hitArea: 'paddleBoatClick',
        hoverText: 'Paddle<br/>Boats',
        clickUrl: '/rides-attractions/paddle-boats/',
        animations: {
            list: {
                "paddleBoat1": {
                    animation: new paddleBoat1Path(),
                    ctx: 'paddleBoat1',
                    lvl: 3
                }
            }
        }
    }, {
        page: [6],
		sound: "Paddle_Bumper_Boats",
        ctx: 'bumperBoats',
        hitArea: 'bumperBoatClick',
        hoverText: 'Bumper<br/>Boats',
        clickUrl: '/rides-attractions/bumper-boats/',
        animations: {
            add: function () {
                var waterOn = false;

                addAnimation('bumperBoatOrange', this.list['bumperBoatOrange'], null, function () {
                    waterOn = true;
                    setTimeout(function () { waterOn = false }, 200);
                });
                addAnimation('bumperBoatYellowGun', this.list['bumperBoatYellowGun']);
                addAnimation('bumperBoatYellow', this.list['bumperBoatYellow']);
                addAnimation('bumperBoatSplash', {
                    animation: function (ctx) {
                        if (waterOn) {
                            bumperBoatSplash(ctx);
                        }
                    },
                    ctx: bumperBoatSplash,
                    type: 'function',
                    lvl: 3
                });
                addAnimation('bumperBoatPink', this.list['bumperBoatPink']);

            },
            list: {
                "bumperBoatYellow": {
                    animation: new bumperBoatYellowPath(),
                    ctx: 'bumperBoatYellow',
                    lvl: 3
                },
                "bumperBoatOrange": {
                    animation: new bumperBoatOrangePath(),
                    ctx: 'bumperBoatOrange',
                    lvl: 3
                },
                "bumperBoatYellowGun": {
                    animation: new bumperBoatYellowPath(),
                    ctx: 'bumperBoatYellowGun',
                    lvl: 3
                },
                "bumperBoatPink": {
                    animation: new bumperBoatPinkPath(),
                    ctx: 'bumperBoatPink',
                    lvl: 3
                }

            }
        }
    }, {
        page: [2],
		sound: "Balloon_Boy",
        hitArea: 'boyClick',
        hoverText: 'Birthday<br/>Parties',
        clickUrl: '/group-functions/birthday-parties/',
        animations: {
            list: {
                "boy": {
                    animation: new boyPath,
                    ctx: 'boy',
                    lvl: 3,
                    altOffset: 5
                }
            }
        }
    }, {
        page: [3, 4, 5],
		sound: "Rail_Ride",
        hitArea: 'railRiderClick2',
        hoverText: 'Rail<br/>Rider',
        clickUrl: '/rides-attractions/rail-rider/'
    }, {
        page: [3, 4, 5],
        layer1: 'railRiderLayer',
        hitArea: 'railRiderClick',
        hoverText: 'Rail<br/>Rider',
        clickUrl: '/rides-attractions/rail-rider/',
        ctx: railRider,
        animations: {
            list: {
                "railRider1": {
                    animation: new railRiderPath1,
                    ctx: 'railRider1',
                    followOrientation: 0,
                    lvl: 3,
                    altOffset: 5
                },
                "railRider2": {
                    animation: new railRiderPath2,
                    ctx: 'railRider2',
                    followOrientation: 0,
                    lvl: 3,
                    altOffset: 1
                }
            }
        }
    }, {
        page: [4],
		sound: "Bounty",
        hitArea: 'bountysRevengeClick',
        hoverText: 'Bounty\'s<br/>Revenge',
        clickUrl: '/rides-attractions/bounty\'s-revenge/',
        layer1: 'bountysRevenge',
        layer2: 'bountysTopLayer',
        animations: {
            alt2: function (ctx) {
                if (aw.settings.animationLevel < 2) {
                    ctx.save();
                    ctx.translate(1839.2, 2757.2);
                    ctx.rotate(0.7);

                    bountysBoat(ctx);
                    ctx.restore();
                }
            },
            add: function () {
                var doRotate = false;
                var forward = false;

                bountysBoat.rotateClock = new clock(3.5, 0.00, -1, false, 0, linear, 2.0 * Math.PI, 1.00, 0.0000);

                bountysBoat.rotateClock.start();
                addAnimation('bountysBoat', {
                    type: 'function',
                    ctx: bountysBoat,
                    lvl: 2,
                    animation: function (ctx) {
                        ctx = aw.canvas.animation2;

                        ctx.save();
                        ctx.translate(1839.2, 2757.2);

                        if (!forward && bountysBoat.rotateClock.value < 4.7 && bountysBoat.rotateClock.value > 2) {
                            bountysBoat.rotateClock.reverse();
                            forward = true;
                        }

                        if (forward && bountysBoat.rotateClock.value > 1.2 && bountysBoat.rotateClock.value < 3) {
                            bountysBoat.rotateClock.reverse();
                            forward = false;
                        }

                        ctx.rotate(bountysBoat.rotateClock.value);

                        bountysBoat(ctx);
                        ctx.restore();
                    }
                });

            },
            list: {

            }
        }
    }, {
        page: [4],
		sound: "Skull",
        layer1: 'skullRock',
        hitArea: 'skullRockClick',
        hoverText: 'Skull<br/>Rock',
        clickUrl: '/rides-attractions/skull-rock/'
    }, {

        page: [4],
		sound: "Tunnel",
        hitArea: 'tunnelTerrorClick',
        hoverText: 'Tunnel Of Terror',
        clickUrl: '/rides-attractions/tunnel-of-terror/',
        layer1: 'tunnelOfTerror',
        layer2: 'page4Layer',
        animations: {
            add: function () {
                var list = this.list;
                function finished() {
                    addSlideAnimation('tunnelOfTerrorPerson', list['tunnelOfTerrorPerson'], finished, true);
                }

                finished();
            },
            list: {
                "tunnelOfTerrorPerson": {
                    animation: new tunnelOfTerrorPath,
                    ctx: 'tunnelOfTerrorPerson',
                    lvl: 2,
                    layer: 2,
                    altOffset: 1
                }
            }
        }
    }, {
        page: [4],
		sound: "Grand_Prix",
        hitArea: 'grandPrixClick',
        hoverText: 'Grand Prix<br/>Race Track',
        clickUrl: '/rides-attractions/grand-prix-race-track/',
        layer2: 'gradPrixRacewayLayer1',
        ctx: 'grandPrixRaceway',
        animations: {
            add: function () {
                var list = this.list;

                function startCars() {
                    setTimeout(function () {
                        addSlideAnimation('cartBlue', list['cartBlue'], startCars);
                        addSlideAnimation('cartYellow', list['cartYellow']);
                    }, 1000);
                }

                startCars();


            },
            list: {
                "cartBlue": {
                    animation: new cartBluePath,
                    ctx: 'cartBlue',
                    lvl: 2,
                    layer: 2,
                    altOffset: 4
                },
                "cartYellow": {
                    animation: new cartYellowPath,
                    ctx: 'cartYellow',
                    lvl: 2,
                    layer: 2,
                    altOffset: 3
                }
            }
        }
    }, {
        page: [3],
		sound: "Rocky_Mt",
        hitArea: 'matSlidesClick',
        hoverText: 'Water Mountain<br/>Mat Slides',
        clickUrl: '/rides-attractions/water-mountain-mat-slides/'
    }, {
        page: [3],
		sound: "Rocky_Mt",
        hitArea: 'rockyMountainClick',
        hoverText: 'Rocky Mountain<br/>Rapids',
        clickUrl: '/rides-attractions/rocky-mountain-rapids/',
        layer1: 'rockyLayer1',
        layer2: 'rockyLayer2',
        ctx: 'waterMountain',
        animations: {
            add: function () {
                var animation1 = new rocky1Path();
                var doRotate1 = false;
                var animation1UseLayer2 = false;
                animation1.pathClock.timingFunction = function (t) {

                    if (t > 0.2 && t < 0.55) {
                        doRotate = true;
                    }
                    else {
                        doRotate = false;
                    }

                    if (t < 0.61) {
                        animation1UseLayer2 = false;
                    }
                    else {
                        animation1UseLayer2 = true;
                    }

                    return linear(t);
                };
                animation1.pathClock.start();

                var animation2 = new rocky2Path();
                var doScale2 = true;
                var doRotate2 = false;
                var animation2UseLayer2 = false;


                animation2.pathClock.timingFunction = function (t) {

                    if (t < 0.15) {

                        doScale2 = true;
                    }
                    else {

                    }

                    if (t < 0.2) {
                        animation2UseLayer2 = false;
                    }
                    else {
                        animation2UseLayer2 = true;
                    }


                    if (t > 0.12 && t < 0.55) {

                        doRotate2 = true;
                    }
                    else {
                        doRotate2 = false;
                    }

                    if (t > 0.55) {
                        doScale2 = false;
                    }
                    return linear(t);
                };
                animation2.pathClock.start();



                addAnimation('rocky2', {
                    type: 'function',
                    lvl: 2,
                    animation: function (ctx) {
                        animation2.update();


                        if (animation2UseLayer2) {
                            ctx = aw.canvas.animation2;
                        }
                        else {
                            ctx = aw.canvas.animation1;
                        }

                        ctx.save();



                        ctx.translate(animation2.x, animation2.y);

                        if (doScale2) {
                            ctx.scale(0.8, 0.8);
                        }
                        else {
                            ctx.scale(0.9, 0.9);
                        }

                        if (doRotate2) {
                            ctx.rotate(240.00 * Math.PI / 180.0);
                            ctx.scale(-1, 1);
                        }

                        rocky2(ctx);

                        ctx.restore();
                    }
                });



                addAnimation('rocky1', {
                    type: 'function',
                    lvl: 2,
                    animation: function (ctx) {
                        animation1.update();

                        if (animation1UseLayer2) {
                            ctx = aw.canvas.animation2;
                        }
                        else {
                            ctx = aw.canvas.animation1;
                        }


                        ctx.save();


                        ctx.translate(animation1.x, animation1.y);
                        if (doRotate) {
                            ctx.rotate(250.00 * Math.PI / 180.0);
                            ctx.scale(-1, 1);
                        }

                        rocky1(ctx);

                        ctx.restore();
                    }
                });



                var animation3 = new rocky3Path();
                var doScale3 = true;
                var doRotate3 = false;
                var animation3UseLayer2 = false;

                animation3.pathClock.timingFunction = function (t) {

                    if (t > 0.3 && t < 0.45) {
                        animation3UseLayer2 = true;
                    }
                    else {
                        animation3UseLayer2 = false;
                    }

                    if (t > 0.22 && t < 0.55) {
                        doRotate3 = true;
                    }
                    else {
                        doRotate3 = false;
                    }
                    return linear(t);
                };

                animation3.pathClock.start();


                addAnimation('rocky3', {
                    type: 'function',
                    lvl: 2,
                    animation: function (ctx) {
                        animation3.update();
                        if (animation3UseLayer2) {
                            ctx = aw.canvas.animation2;
                        }
                        else {
                            ctx = aw.canvas.animation1;
                        }
                        ctx.save();
                        ctx.translate(animation3.x, animation3.y);

                        if (doRotate3) {
                            ctx.rotate(230.00 * Math.PI / 180.0);
                            ctx.scale(-1, 1);
                        }

                        rocky3(ctx);
                        ctx.restore();
                    }
                });

            },
            list: {
                "rocky1": {
                    animation: new rocky1Path,
                    ctx: 'rocky1',
                    lvl: 2,
                    altOffset: 40
                },
                "rocky2": {
                    animation: new rocky2Path,
                    ctx: 'rocky2',
                    lvl: 2,
                    altOffset: 65
                },
                "rocky3": {
                    animation: new rocky3Path,
                    ctx: 'rocky3',
                    lvl: 2,
                    altOffset: 0.4
                }
            }
        }
    }, {
        page: [3],
		sound: "Donuts",
        hitArea: 'doughnutClick',
        hoverText: 'Eats and<br/>Drinks',
        clickUrl: '/visitor-info/eats-and-drinks/',
        animations: {
            list: {
                "doughnut": {
                    animation: new doughnutPath,
                    ctx: 'doughnut',
                    lvl: 3,
                    layer: 2,
                    altOffset: 9
                }
            }
        }
    }, {
        page: [3],
		sound: "Wildlife",
        hitArea: 'aussieWildlifeClick',
        hoverText: 'Aussie Wildlife<br/>Experience',
        clickUrl: '/rides-attractions/aussie-wildlife-experience/',
        ctx: 'wildlife',
        animations: {
            alt1: function (ctx) {
                if (aw.settings.animationLevel < 3) {
                    rooRope1(ctx);
                    doAlt1List(this, ctx);
                }
            },
            add: function () {
                var ropeUp = false;
                addAnimation('roo', this.list['roo']);
                addAnimation('rooRope', {
                    type: 'function',
                    lvl: 3,
                    animation: function (ctx) {
                        if (ropeUp) {
                            rooRope1(ctx);
                        }
                        else {
                            rooRope2(ctx);
                        }
                    }
                });

                clearInterval(ropeInterval);
                ropeInterval = setInterval(function () {
                    if (ropeUp) {
                        ropeUp = false;
                    }
                    else {
                        ropeUp = true;
                    }
                }, 150);
            },
            list: {
                "roo": {
                    animation: new rooPath,
                    ctx: 'roo',
                    lvl: 3,
                    altOffset: 0.7
                }
            }
        }
    }, {
        page: [2, 3],
        ctx: 'ticketBooth',
		sound: "Tickets",
        hitArea: 'ticketsClick',
        hoverText: 'Buy Tickets',
        clickUrl: '/tickets/',
        onOff: [ticketSwitch1, ticketSwitch2]
    }, {
        page: [5],
        hitArea: 'superSixClick',
		sound: "Alpine",
        hoverText: 'Aqua Super<br/>6 Racer',
        clickUrl: '/rides-attractions/aqua-super-6-racer/'
    }, {
        page: [5],
		sound: "Alpine",
        hitArea: 'speedSlidesClick',
        hoverText: 'Speed Slides',
        clickUrl: '/rides-attractions/speed-slides/',
        layer1: 'slides',
        layer2: 'slideLayer',
        animations: {
            add: function () {
                addAnimation('speed1', this.list['speed1']);
                addAnimation('speed2', this.list['speed2']);
                var list = this.list
                function startAqua() {
                    addSlideAnimation('aqua1', list['aqua1'], function () {
                        setTimeout(startAqua, 1500);
                    });
                    addSlideAnimation('aqua2', list['aqua2']);
                    addSlideAnimation('aqua3', list['aqua3']);
                    addSlideAnimation('aqua4', list['aqua4']);
                    addSlideAnimation('aqua5', list['aqua5']);
                    addSlideAnimation('aqua6', list['aqua6']);
                }
                startAqua();
            },
            list: {
                "speed1": {
                    animation: new speed1Path,
                    ctx: 'speed1',
                    lvl: 2,
                    layer: 2,
                    altOffset: 7.5
                },
                "speed2": {
                    animation: new speed2Path,
                    ctx: 'speed2',
                    lvl: 2,
                    layer: 2,
                    altOffset: 12
                },
                "aqua1": {
                    animation: new aqua1Path,
                    ctx: 'aqua1',
                    lvl: 2,
                    layer: 2,
                    altOffset: 5
                },
                "aqua2": {
                    animation: new aqua2Path,
                    ctx: 'aqua2',
                    lvl: 2,
                    layer: 2,
                    altOffset: 17
                },
                "aqua3": {
                    animation: new aqua3Path,
                    ctx: 'aqua3',
                    lvl: 2,
                    layer: 2,
                    altOffset: 8
                },
                "aqua4": {
                    animation: new aqua4Path,
                    ctx: 'aqua4',
                    lvl: 2,
                    layer: 2,
                    altOffset: 6
                },
                "aqua5": {
                    animation: new aqua5Path,
                    ctx: 'aqua5',
                    lvl: 2,
                    layer: 2,
                    altOffset: 20
                },
                "aqua6": {
                    animation: new aqua6Path,
                    ctx: 'aqua6',
                    lvl: 2,
                    layer: 2,
                    altOffset: 9
                }
            }
        }
    }, {
        page: [4, 5, 6],
        hitArea: 'skyLiftClick3',
        hoverText: 'Sky Lift',
        clickUrl: '/rides-attractions/sky-lift/'
    }, {
        page: [4, 5, 6],
        hitArea: 'skyLiftClick2',
        hoverText: 'Sky Lift',
        clickUrl: '/rides-attractions/sky-lift/'
    }, {
        page: [4, 5, 6],
        ctx: chairLift,
        hitArea: 'skyLiftClick',
        hoverText: 'Sky Lift',
        clickUrl: '/rides-attractions/sky-lift/',
        layer1: 'chairLayer',
        animations: {
            add: function () {
                var animation1 = new chair1Path(),
        animation2 = new chair2Path(),
          scaleClock1 = new clock(15.00, 0.00, 1, false, 1, linear, 1.0, 1, 0),
          scaleClock1Part2 = new clock(15.00, 45.00, -1, false, 1, linear, 1.0, 1, 0),
          scaleClock2 = new clock(15.00, 0.00, 1, false, 1, linear, 1.0, 1, 0),
          scaleClock2Part2 = new clock(15.00, 45.00, -1, false, 1, linear, 1.0, 1, 0),
          orientation = 160.00 * Math.PI / 180.0,
          orientation2 = 280.00 * Math.PI / 180.0;

                animation1.pathClock.iterated.subscribe(function () {
                    scaleClock1.restart();
                    scaleClock1Part2.restart();
                });

                animation2.pathClock.iterated.subscribe(function () {
                    scaleClock2.restart();
                    scaleClock2Part2.restart();
                });

                animation1.pathClock.start();
                animation2.pathClock.start();
                scaleClock1.start();
                scaleClock1Part2.start();
                scaleClock2.start();
                scaleClock2Part2.start();

                addAnimation('chair1', {
                    type: 'function',
                    ctx: chair1,
                    lvl: 3,
                    animation: function (ctx) {
                        animation1.update();
                        ctx.save();
                        ctx.translate(animation1.x, animation1.y);
                        ctx.rotate(orientation + animation1.orientation);

                        if (scaleClock1.value > 0) {
                            ctx.scale(scaleClock1.value, scaleClock1.value);
                        }

                        if (scaleClock1Part2.value > 0) {
                            ctx.scale(scaleClock1Part2.value, scaleClock1Part2.value);
                        }

                        if (scaleClock1Part2.value != 0 && scaleClock1.value != 0) {
                            chair1(ctx);
                        }
                        ctx.restore();
                    }
                });

                addAnimation('chair2', {
                    type: 'function',
                    ctx: 'chair2',
                    lvl: 3,
                    animation: function (ctx) {
                        animation2.update();
                        ctx.save();
                        ctx.translate(animation2.x, animation2.y);
                        ctx.rotate(orientation2 + animation2.orientation);
                        if (scaleClock2.value > 0) {
                            ctx.scale(scaleClock2.value, scaleClock2.value);
                        }

                        if (scaleClock2Part2.value > 0) {
                            ctx.scale(scaleClock2Part2.value, scaleClock2Part2.value);
                        }
                        if (scaleClock2Part2.value != 0 && scaleClock2.value != 0) {
                            chair2(ctx);
                        }
                        ctx.restore();
                    }
                });
            },
            list: {
                "chair1": {
                    animation: new chair1Path,
                    ctx: chair1,
                    lvl: 3,
                    altOffset: 4
                }
            }
        }
    }, {
        page: [5, 6],
		sound: "Dragon_Flyer",
        ctx: 'dragonRider',
        hitArea: 'dragonRiderClick',
        hoverText: 'Dragon Flyer',
        clickUrl: '/rides-attractions/dragon-flyer/',
        onOff: [dragonRiderFire]
    }, {
        page: [4, 5],
		sound: "Leaper",
        hitArea: 'littleLeaperClick',
        hoverText: 'Little Leaper',
        clickUrl: '/rides-attractions/little-leaper/',
        layer1: 'leaper',
        animations: {
            list: {
                "leaperChair": {
                    animation: new leaperPath,
                    ctx: 'leaperSeat',
                    lvl: 2,
                    layer: 2,
                    altOffset: 80
                }
            }
        }
    }, {
        page: [1, 2],
		sound: "Splash_Zone",
        hitArea: 'splashZoneClick',
        hoverText: 'Kids Splash<br/>Zone',
        clickUrl: '/rides-attractions/kids-splash-zone/',
        ctx: 'splashZone',
        layer1: 'splashZoneLayer',
        onOff: [splashZoneSplash],
        animations: {
            add: function () {
                var list = this.list
                function startAqua() {
                    addSlideAnimation('splashZone', list['splashZone'], startAqua, true);
                }
                addSlideAnimation('splashZone', list['splashZone'], startAqua);
            },
            list: {
                "splashZone": {
                    animation: new splashZonePersonPath,
                    ctx: 'splashZonePerson',
                    lvl: 2,
                    altOffset: 1.7
                }
            }
        }
    }, {
        page: [2],
		sound: "Free_Fall",
        hitArea: 'freeFallClick',
        hoverText: 'Freefall',
        clickUrl: '/rides-attractions/freefall/',
        layer1: 'freefall',
        animations: {
            add: function () {
                var animation = new freeFallChairPath();
                var animation2 = new freeFallChairPath2();
                var pause = false;
                var goingUp = true;
                animation.pathClock.finished.subscribe(function () {
                    pause = true;
                    goingUp = false;
                    setTimeout(function () {
                        pause = false;

                        animation2.pathClock.restart();

                    }, 1000);
                });
                animation2.pathClock.finished.subscribe(function () {
                    goingUp = true;
                    animation.pathClock.restart();
                });
                animation.pathClock.start();
                addAnimation('freeFallChair', {
                    type: 'function',
                    ctx: freeFallChair,
                    lvl: 2,
                    animation: function (ctx) {
                        animation.update();
                        animation2.update();
                        aw.canvas.animation2.save();
                        if (animation.pathClock.isRunning && goingUp) {
                            aw.canvas.animation2.translate(animation.x, animation.y);
                        }
                        else if (animation2.pathClock.isRunning && !goingUp) {
                            aw.canvas.animation2.translate(animation2.x, animation2.y);
                        }
                        else if (pause && !goingUp) {
                            aw.canvas.animation2.translate(animation.x, animation.y);
                        }
                        freeFallChair(aw.canvas.animation2);
                        aw.canvas.animation2.restore();
                    }
                });
            },
            list: {
                "freeFallChair": {
                    animation: new freeFallChairPath,
                    ctx: 'freeFallChair',
                    lvl: 2,
                    altOffset: 3,
                    layer: 2
                }
            }
        }
    }, {
        page: [2, 3],
		sound: "Rampage",
        hitArea: 'theRampageClick',
        hoverText: 'The Rampage',
        clickUrl: '/rides-attractions/the-rampage/',
        ctx: 'rampage',
        layer1: 'rampageLayer',
        animations: {
            alt1: function (ctx) {
                if (aw.settings.animationLevel < 2) {
                    ctx.save();
                    ctx.translate(2716.2, 1864.7);
                    rampageBar(ctx);
                    ctx.restore();
                    doAlt1List(this, ctx);
                }
            },
            add: function () {

                rampageBar.rotateClock = new clock(4.00, 0.00, -1, false, 0, linear, 2.0 * Math.PI, 1.00, 0.0000);
                rampageBar.rotateClock.start();

                addAnimation('rampageBar', {
                    type: 'function',
                    lvl: 2,
                    animation: function (ctx) {
                        ctx.save();
                        ctx.translate(2716.2, 1864.7);
                        ctx.rotate(rampageBar.rotateClock.value);
                        rampageBar(ctx);
                        ctx.restore();
                    }
                });

                addAnimation('rampageChair', this.list['rampageChair']);

                var rotateClock = this.list['rampageChair'].rotateClock;
                rotateClock.iterated.subscribe(function () {
                    if (getRandomArbitary(0, 1) > .8) {
                        rotateClock.reverse();
                    }
                });
            },
            list: {
                "rampageChair": {
                    animation: new rampageChairPath(),
                    ctx: rampageChair,
                    rotateClock: new clock(1.50, 0.00, 1, false, 0, linear, 2.0 * Math.PI, 1.00, 0.0000),
                    lvl: 2
                }
            }
        }
    }, {
        page: [2],
		sound: "Loch_Ness",
        layer2: 'lagoon',
        hitArea: 'lagoonClick',
        hoverText: 'The Lagoon',
        clickUrl: '/rides-attractions/the-lagoon/'
    }, {
        page: [3, 4],
		sound: "Barnacle",
        hoverText: 'The Barnacle',
        clickUrl: '/rides-attractions/the-barnacle/',
        hitArea: 'theBarnacleClick',
        layer1: 'theBarnacle',
        animations: {
            alt2: function (ctx) {
                if (aw.settings.animationLevel < 2) {
                    var animation = new theBarnacleBoatPath();
                    animation.pathClock.value = 0.8;
                    animation.update();
                    ctx.save();
                    ctx.translate(animation.x, animation.y);
                    ctx.rotate((20.00 * Math.PI / 180.0) + animation.orientation);
                    theBarnacleBoat(ctx);
                    ctx.restore();
                }
            },
            add: function () {

                var animation = new theBarnacleBoatPath();
                var animation2 = new theBarnacleBoatPath2();

                animation.pathClock.reverses = true;

                animation.pathClock.finished.subscribe(function () {
                    animation2.pathClock.restart();
                });
                animation2.pathClock.finished.subscribe(function () {
                    animation.pathClock.restart();
                });


                animation.pathClock.start();
                addAnimation('barnacle', {
                    type: 'function',
                    ctx: 'theBarnacleBoat',
                    lvl: 2,
                    animation: function (ctx) {
                        animation.update();
                        animation2.update();

                        ctx = aw.canvas.animation2;
                        ctx.save();


                        if (animation.pathClock.isRunning) {
                            ctx.translate(animation.x, animation.y);
                            ctx.rotate((20.00 * Math.PI / 180.0) + animation.orientation);
                            theBarnacleBoat(ctx);
                        }

                        if (animation2.pathClock.isRunning) {
                            ctx.translate(animation2.x, animation2.y);
                            ctx.rotate((200.00 * Math.PI / 180.0) + animation2.orientation);
                            theBarnacleBoat(ctx);
                        }


                        ctx.restore();
                    }
                });
            },
            list: {
                "barnacle": {
                    animation: new theBarnacleBoatPath,
                    ctx: 'theBarnacleBoat',
                    lvl: 3,
                    layer: 2,
                    followOrientation: 170
                }
            }
        }
    }
];



        var canvasWidth = 1024,
        canvasHeight = 768,
        viewPortX = 0,
        viewPortY = 0,
        hitAreaArray = [],
        currentMouseOver = null,
        currentPage = 1,
        body = $('body'),
        fishPathAnim,
        sunPathAnim,
        animations = {},
        onOffAnimations = [],
        currentPageModels = [],
        bountyRotateInterval,
        smokeInterval,
        ropeInterval,
        pageDetails = pagePos[currentPage - 1];


        /**
        * Draw every frame
        */
        function drawAllFrames(updateModels) {
            if (updateModels === undefined || updateModels === true) {

                updateCurrentModels();
                updateCurrentAnimations();
            }

            drawGlobeFrame();
            //  drawAnimationFrame();
			
			
				drawLayer1();
				drawLayer2();
        }

        function drawLayer1() {
            var ctx = aw.canvas.layer1
            if (ctx == undefined) {
                ctx = aw.canvas.globe;
            }
			
			if( aw.settings.pauseAnimation )
			{
				 ctx = aw.canvas.globe;
			}

            // Draw any animations that have been disabled
            for (var i = 0; i < currentPageModels.length; i++) {
                if (currentPageModels[i].animations != undefined) {
                    var model = currentPageModels[i].animations;

                    if (model.alt1) {
                        model.alt1(ctx);
                    }
                    else {
                        doAlt1List(model, ctx);
                    }
                }
            }

            for (var i = 0; i < currentPageModels.length; i++) {

                if (currentPageModels[i].layer1 != undefined) {
                    eval(currentPageModels[i].layer1)(ctx);
                }
            }
        }


        function drawLayer2() {
            var ctx = aw.canvas.layer2
            if (ctx == undefined) {
                ctx = aw.canvas.globe;
            }
			
			if( aw.settings.pauseAnimation )
			{
				 ctx = aw.canvas.globe;
			}

            // Draw any animations that have been disabled
            for (var i = 0; i < currentPageModels.length; i++) {
                if (currentPageModels[i].animations != undefined) {
                    var model = currentPageModels[i].animations;

                    if (model.alt2) {
                        model.alt2(ctx);
                    }
                    else {
                        doAlt2List(model, ctx);
                    }
                }

            }

            for (var i = 0; i < currentPageModels.length; i++) {
                if (currentPageModels[i].layer2 != undefined) {
                    eval(currentPageModels[i].layer2)(ctx);
                }
            }

            if (aw.settings.animationLevel == 0  ) {
                for (var name in onOffAnimations) {

                    var obj = onOffAnimations[name];
                    if (obj.draw) {
                        obj.draw(ctx);
                    }
                }

                ctx.save();
                floatingTv(ctx);

                fishPathAnim.update();
                ctx.translate(2169, 1283);
                ctx.rotate(-35 * Math.PI / 180);
                bannerImage(ctx);
                ctx.restore();
            }

        }

        function drawGlobeFrame() {
            // Clear canvas
            aw.canvas.globe.clearRect(viewPortX, viewPortY, canvasWidth, canvasHeight);
            base(aw.canvas.globe);

            for (var i = 0; i < currentPageModels.length; i++) {
                if (currentPageModels[i].ctx != undefined) {
                    eval(currentPageModels[i].ctx)(aw.canvas.globe);
                }
            }



            if (aw.settings.animationLevel < 3 ) {
                aw.canvas.globe.save();

                aw.canvas.globe.translate(sunPathAnim.x, sunPathAnim.y);
                sun(aw.canvas.globe);
                aw.canvas.globe.restore();
            }
        }




        function drawAnimationFrame() {
            updateAnimations();

            if (aw.settings.animationLevel > 0 && aw.settings.pauseAnimation === false) {
                // Clear canvas

                aw.canvas.animation1.clearRect(pageDetails.x, pageDetails.y, 1200, 1200);
                aw.canvas.animation2.clearRect(pageDetails.x, pageDetails.y, 1200, 1200);

                var now = new Date().getTime();

                if (aw.settings.animationLevel >= 3) {
                    aw.canvas.animation1.save();
                    sunPathAnim.update();
                    aw.canvas.animation1.translate(sunPathAnim.x, sunPathAnim.y);
                    aw.canvas.animation1.rotate(145.00 * Math.PI / 180 + sunPathAnim.orientation);
                    sun(aw.canvas.animation1);
                    aw.canvas.animation1.restore();
                }

                for (var name in animations) {

                    // Update animations
                    if (animations[name].layer && animations[name].layer > 1) {
                        ctx = aw.canvas.animation2;
                    }
                    else {
                        ctx = aw.canvas.animation1;
                    }

                    if (animations[name].type != 'function' && animations[name].animation.pathClock.isRunning && ((now - animations[name].animation.pathClock.startTime) > (animations[name].animation.pathClock.delay * 1000))) {
                        ctx.save();
                        ctx.translate(animations[name].animation.x, animations[name].animation.y);

                        if (animations[name].rotateClock) {
                            ctx.rotate(animations[name].rotateClock.value);
                        }

                        if (!animations[name].disableDraw) {
                            if (animations[name].followOrientation !== undefined) {
                                ctx.rotate(animations[name].followOrientation + animations[name].animation.orientation);
                            }
                            eval(animations[name].ctx)(ctx);
                        }
                        ctx.restore();
                    }
                    else if (animations[name].type == 'function') {
                        animations[name].animation(ctx);
                    }
                }



                for (var name in onOffAnimations) {
                    var obj = onOffAnimations[name];
                    var timeFrame = getRandomArbitary(500, 1500);

                    if (obj.on) {
                        obj.draw(aw.canvas.animation2);

                        if ((now - obj.lastUpdated) > timeFrame) {
                            obj.lastUpdated = now;
                            obj.on = false;
                        }
                    }
                    else {
                        if ((now - obj.lastUpdated) > timeFrame) {
                            obj.lastUpdated = now;
                            obj.on = true;
                        }
                    }
                }


                aw.canvas.animation2.save();
                fishPathAnim.update();
                aw.canvas.animation2.translate(fishPathAnim.x, fishPathAnim.y);
                aw.canvas.animation2.rotate(145.00 * Math.PI / 180 + fishPathAnim.orientation);
                fish(aw.canvas.animation2);

                bannerImage(aw.canvas.animation2);
                aw.canvas.animation2.restore();



                aw.canvas.animation2.save();
                aw.canvas.animation2.translate(2039.4, 2661.1);
                aw.canvas.animation2.globalAlpha = eye1.alphaClock.value;
                eye1(aw.canvas.animation2);
                aw.canvas.animation2.restore();

                aw.canvas.animation2.save();
                aw.canvas.animation2.translate(2010.0, 2661.7);
                aw.canvas.animation2.globalAlpha = eye2.alphaClock.value;
                eye2(aw.canvas.animation2);
                aw.canvas.animation2.restore();
            }
			else
			{
				// Don't animate
			
			}
        }

        function rotate(rotateAmount) {

            totalRotateAmount += rotateAmount;

            if( aw.settings.rotate )
            {
				var amountLeft = rotateAmount;
				
				updateCurrentModels(-1);
				
				aw.settings.pauseAnimation = true;
				drawAllFrames(false);
				aw.canvas.layer1.clearRect(0,0,4000,4000);
				aw.canvas.layer2.clearRect(0,0,4000,4000);
				aw.canvas.animation1.clearRect(0,0,4000,4000);
				aw.canvas.animation2.clearRect(0,0,4000,4000);
				setTimeout(doMinorRotate, 1);
				
				var interval = setInterval(doMinorRotate, 1000 / 60);
				
				function doMinorRotate()
				{
					var r = 0;
					if( rotateAmount > 0 )
					{
						
					}
					else
					{
						var speed = -3
						if( amountLeft > speed )
						{
							r = amountLeft;
							amountLeft = 0;
						}
						else
						{
							r = speed;
							amountLeft+=-(speed);
						}

						
					}
				  
					applyRotate(r, false);

					if( amountLeft == 0 )
					{
						clearInterval(interval);
						aw.settings.pauseAnimation = false;
						drawAllFrames(true);
						resize();

					}
				}
            }
            else
            {
				applyRotate(rotateAmount, true);
            }


            function applyRotate(rotateAmount, update) {
				 applyToAllCanvas(function (canvas) {
                    canvas.clearRect(0, 0, 4000, 4000);

                    // Move registration point to the center of the canvas
                    canvas.translate(2000, 2000);

                    canvas.rotate((rotateAmount * Math.PI) / 180);

                    // Move registration point back to the top left corner of canvas
                    canvas.translate(-2000, -2000);
                });

                if (mobi.mobile == "True") {
                    setTimeout(function () { drawAllFrames(update); }, 50);
                }
                else {
                    drawAllFrames(update);
                }
			
				/*var canvas = aw.canvas.globe;

				canvas.clearRect(0, 0, 4000, 4000);

				// Move registration point to the center of the canvas
				canvas.translate(2000, 2000);

				canvas.rotate((rotateAmount * Math.PI) / 180);

				// Move registration point back to the top left corner of canvas
				canvas.translate(-2000, -2000);
          

                if (mobi.mobile == "True") {
                    setTimeout(function () { drawAllFrames(update); }, 50);
                }
                else {
                    drawAllFrames(update);
                }*/
            }
        }

        function updateAnimations() {
            updateAllClocks();

            for (var name in animations) {
                if (animations[name].type != 'function') {
                    animations[name].animation.update();
                }
            }
        }

        /**
        *  Setup the canvas contexts
        */
        function initialiseContexts() {
            var earth = document.getElementById("earth"),
            animation1 = document.getElementById("animation1"),
            layer1 = document.getElementById("layer1"),
            animation2 = document.getElementById("animation2"),
            layer2 = document.getElementById("layer2");

            aw.canvas.globe = earth.getContext("2d");

            if (!window.FlashCanvas) {
                aw.canvas.animation1 = animation1.getContext("2d");
                aw.canvas.layer1 = layer1.getContext("2d");
                aw.canvas.animation2 = animation2.getContext("2d");
                aw.canvas.layer2 = layer2.getContext("2d");
            }
        }

        function applyToAllCanvas(callback) {
            for (var canvas in aw.canvas) {
                callback(aw.canvas[canvas]);
            }
        }

        function clickEvent(e) {
            var x = e.pageX - $('#canvasContainer')[0].offsetLeft;
            var y = e.pageY - $('#canvasContainer')[0].offsetTop;
            var hitArea = getHitArea(x, y);
            if (hitArea) {
				if( muteClick )
				{
					muteClick= false;
				}
				else
				{
					if (hitArea.type == 'fish') {
						doFishClick();
					}
					else {
						_gaq.push(['_trackEvent', 'World', 'Ride Click', hitArea.clickUrl]);
						window.location.hash = hitArea.clickUrl;
					}
				}
            }
        }

        function mouseOver(hitArea) {
            $("#mouseOver").show();
            $("#mouseOver > span.c").html(hitArea.hoverText);
			if( hitArea.sound && aw.settings.sound )
			{
					if( hitArea.sound.currentTime === undefined )
					{
						hitArea.sound.setPosition(0);
					}
					else
					{
						if( (hitArea.sound.duration - hitArea.sound.currentTime) < 2 )
						{
						  hitArea.sound.currentTime = 0;
						}
					}

					if( hitArea.sound.unmute )
					{
						hitArea.sound.unmute();
					}
					hitArea.sound.play();
		
			}
            document.body.style.cursor = 'pointer';
        }

        function mouseOut(hitArea) {
            $("#mouseOver").hide();
			
			if( hitArea && hitArea.sound && aw.settings.sound )
			{
				  if( hitArea && hitArea.sound )
				  {
					hitArea.sound.pause();
				  }
			}
			
            document.body.style.cursor = 'default';
        }

        function mousemoveEvent(e) {
            var x = e.pageX - $('#canvasContainer')[0].offsetLeft;
            var y = e.pageY - $('#canvasContainer')[0].offsetTop;

            var hitArea = getHitArea(x, y);

            if (hitArea) {
                $("#mouseOver").css({
                    top: y - 80,
                    left: x - 30
                });

                if (hitArea != currentMouseOver) {
                    mouseOut(currentMouseOver);
                    mouseOver(hitArea);
                }

                if (currentMouseOver == null) {
                    mouseOver(hitArea);
                }
                currentMouseOver = hitArea;
            }
            else {
                if (currentMouseOver != null) {
                    mouseOut(currentMouseOver);
                }

                currentMouseOver = null;
            }
        }

        function getHitArea(x, y) {
            var length = hitAreaArray.length;

            if (aw.settings.animationLevel == 0) {
                aw.canvas.globe.save();
                floatingTvClick(aw.canvas.globe);
                if (aw.canvas.globe.isPointInPath(x, y)) {
                    aw.canvas.globe.restore();
                    return { hoverText: 'Click to find out more', type: 'fish' };
                }
                aw.canvas.globe.restore();
            }
            else {
                aw.canvas.globe.save();
                aw.canvas.globe.translate(fishPathAnim.x, fishPathAnim.y);
                aw.canvas.globe.rotate(150.00 * Math.PI / 180 + fishPathAnim.orientation);
                aw.canvas.globe.translate(50, 37);
                fishClick(aw.canvas.globe);
                if (aw.canvas.globe.isPointInPath(x, y)) {
                    aw.canvas.globe.restore();
                    return { hoverText: 'Click to find out more', type: 'fish', sound: pufferSound };
                }
                aw.canvas.globe.restore();
            }

            for (var i = 0; i < length; i++) {
                eval(hitAreaArray[i].hitArea)(aw.canvas.globe);
                if (aw.canvas.globe.isPointInPath(x, y)) {
                    return hitAreaArray[i];
                }
            }
            return null;
        }

        function resize() {
            canvasWidth = $('#canvasContainer').width();
            canvasHeight = $('#canvasContainer').height();
            var bodyWidth = $('body').width();
            if (bodyWidth < 930) {
                bodyWidth = 930;
            }

            var defaultCanvas = 4000,
      defaultWidth = 813,
      defaultHeight = 457;

            viewPortX = (defaultCanvas - canvasWidth) / 2;
            viewPortY = ((defaultCanvas / 2) - (320 + canvasHeight));

            var scale = bodyWidth / defaultWidth;
            var scaledCanvas = defaultCanvas * scale;

            $('#canvasContainer > canvas').attr({
                width: defaultWidth * scale,
                height: defaultHeight * scale
            });

            $('#canvasContainer').css({
                width: defaultWidth * scale,
                height: defaultHeight * scale
            });

            applyToAllCanvas(function (canvas) {
                canvas.clearRect(0, 0, defaultCanvas, defaultCanvas);
                canvas.scale(scale, scale);
                canvas.translate(-(4000 / 2), -(4000 / 2));
                canvas.translate(393, 946);
                canvas.translate(defaultCanvas / 2, defaultCanvas / 2);
                canvas.rotate((totalRotateAmount * Math.PI) / 180);
                canvas.translate(-defaultCanvas / 2, -defaultCanvas / 2);
            });

            drawAllFrames(false);
        }

        var lastLoadedHash = ' ';

        function hashChange() {
            var hash = window.location.hash.substr(1);

            if (hash != lastLoadedHash) {

                lastLoadedHash = hash;
                if (hash.length > 0) {
                    var start = hash.substr(0, 1);
                    if (start == '/') {
                        // Hash is a url load it
                        aw.helper.populateContent(hash);

                        aw.helper.scrollToContent(true);
                    }
                    else {
                        // The ipad sometimes crashed when loading the world and rotating to quickly, give it some time to catch up
                        if (mobi.mobile == "True") {
                            setTimeout(function () { aw.helper.rotateToPage(hash.substr(5, 1)) }, 50);
                        }
                        else {
                            aw.helper.rotateToPage(hash.substr(5, 1));
                        }


                        setTimeout(function () {
                            aw.helper.scrollToWorld(true);
                        }, 750);

                    }
                }
                else {
                    setTimeout(function () {
                        aw.helper.scrollToWorld(true);
                    }, 750);
                }
            }

        }



        function updateCurrentModels(withOffest) {
            currentPageModels = [];
            hitAreaArray = [];
			


            for (var i = 0; i < aw.models.length; i++) {
                if ($.inArray(currentPage, aw.models[i].page) > -1) {
                    currentPageModels.push(aw.models[i]);

                    if (aw.models[i].hitArea) {
                        hitAreaArray.push(aw.models[i]);
                    }
                }
				
				if( withOffest ) 
				{
					if ($.inArray(currentPage+withOffest, aw.models[i].page) > -1) {
						currentPageModels.push(aw.models[i]);

						if (aw.models[i].hitArea) {
							hitAreaArray.push(aw.models[i]);
						}
					}
				}
            }
        }

        function updateCurrentAnimations() {
            animations = {};
            onOffAnimations = [];

            var initDate = new Date();
            for (var i = 0; i < currentPageModels.length; i++) {
                if (currentPageModels[i].animations != undefined) {
                    var model = currentPageModels[i].animations;

                    if (model.add) {
                        model.add();
                    }
                    else {
                        addAnimationList(model);
                    }
                }

                if (currentPageModels[i].onOff != undefined) {
                    for (var j = 0; j < currentPageModels[i].onOff.length; j++) {
                        onOffAnimations.push({
                            on: false,
                            draw: currentPageModels[i].onOff[j],
                            lastUpdated: initDate.getTime()
                        });
                    }
                }
            }
        }

        aw.init = function () {
			$(".mutebutton").click(function(){
				muteClick = true;
				if( aw.settings.sound === false )
				{
					aw.settings.sound = true;
					$(".mutebutton").removeClass("off");
				}else
				{
					aw.settings.sound = false;
					$(".mutebutton").addClass("off");
				}
			});
		
            eye1.alphaClock = new clock(1.50, 0.00, 1, false, 0, linear, 1.0, 1.00, 0.0000);
            eye2.alphaClock = new clock(1.50, 0.00, 1, false, 0, linear, 1.0, 1.00, 0.0000);
            eye1.alphaClock.start();
            eye2.alphaClock.start();

            initialiseContexts();
			
			if( Modernizr.audio.mp3 || Modernizr.audio.ogg )
			{
				$.each(aw.models, function(index){
				

						var sound = this.sound;
					
						if( sound !== undefined )
						{
							if( Modernizr.audio.mp3 )
							{
								var audio = new Audio();
								audio.src = '/sounds/' + sound + '.mp3'
								this.sound = audio;
							}
							else if( Modernizr.audio.ogg )
							{
								
								var audio = new Audio();
								audio.src = '/sounds/' + sound + '.ogg'
								this.sound = audio;
							}
						}
				});
				
				if( Modernizr.audio.mp3 )
				{
					var audio = new Audio();
					audio.src = '/sounds/Puffer_Fish.mp3'
					pufferSound = audio;
				}
				else if( Modernizr.audio.ogg )
				{
					
					var audio = new Audio();
					audio.src = '/sounds/Puffer_Fish.ogg'
					pufferSound = audio;

				}
			}
			else
			{
				soundManager.onready(function() {
					$.each(aw.models, function(index){
						var sound = this.sound;
						this.sound = soundManager.createSound({
							id: "sound_" + index,
							url: '/sounds/' + sound + '.mp3'
						});
						
						this.sound.load("sound_" + index);
						
			
						var sound = this.sound;
						setTimeout(function(){
	
							sound.play();
							
							sound.mute();

						}, 1000);
					});
					
				});
			
									
						
						
			
			}
			

            updateCurrentModels();
            updateCurrentAnimations();

            fishPathAnim = new fishPath();
            fishPathAnim.pathClock.start();

            sunPathAnim = new sunPath();
            sunPathAnim.pathClock.start();
            sunPathAnim.update();

            // Create event triggers
            $(window).resize(resize);
            resize();
            $(window).hashchange(hashChange)
            hashChange();

            $('#canvasContainer').mousemove(mousemoveEvent);
            $('#canvasContainer').click(clickEvent);

            $('#canvasContainer .next').click(function () {
                var newPage = currentPage + 1;
                if (newPage > 6) {
                    newPage = 1;
                }
                window.location.hash = 'part-' + newPage;
                return false;
            });

            $('#canvasContainer .prev').click(function () {
                var newPage = currentPage - 1;
                if (newPage == 0) {
                    newPage = 6;
                }
                window.location.hash = 'part-' + newPage;
                return false;
            });

            var element = document.getElementById("animation1");

            (function animloop() {
                drawAnimationFrame();
                requestAnimFrame(animloop, element);
            })();

            $('.world-click').click(function () {
                window.location.hash = 'part-' + currentPage;
                return false;
            });
        }

        function doAlt1List(model, ctx) {
            var now = new Date().getTime();

            for (var animationName in model.list) {

                var animation = model.list[animationName];

                if (animation.layer != 2 && animation.lvl > aw.settings.animationLevel) {

                    if (animation.altOffset !== undefined) {
                        animation.animation.pathClock.value = animation.altOffset;
                    }
                    else {
                        animation.animation.pathClock.value = 0;
                    }

                    animation.animation.update();
                    ctx.save();

                    ctx.translate(animation.animation.x, animation.animation.y);
                    if (animation.followOrientation !== undefined) {
                        ctx.rotate(animation.followOrientation + animation.animation.orientation);
                    }

                    eval(animation.ctx)(ctx);

                    ctx.restore();
                }
            }
        }

        function doAlt2List(model, ctx) {
            var now = new Date().getTime();

            for (var animationName in model.list) {
                var animation = model.list[animationName];

                if (animation.layer == 2 && animation.lvl > aw.settings.animationLevel) {
                    if (animation.altOffset !== undefined) {
                        animation.animation.pathClock.value = animation.altOffset;
                    }
                    else {
                        animation.animation.pathClock.value = 0;
                    }

                    animation.animation.update();
                    ctx.save();

                    ctx.translate(animation.animation.x, animation.animation.y);
                    if (animation.followOrientation !== undefined) {
                        ctx.rotate(animation.followOrientation + animation.animation.orientation);
                    }

                    eval(animation.ctx)(ctx);

                    if (animation.after !== undefined) {
                        animation.after(ctx);
                    }

                    ctx.restore();
                }
            }
        }

        function addAnimationList(model) {
            for (var animationName in model.list) {
                addAnimation(animationName, model.list[animationName]);
            }
        }

        function addAnimation(name, model, callback, interationCallback) {
            if (aw.settings.animationLevel >= model.lvl) {
                animations[name] = model;

                if (model.type != 'function') {
                    model.animation.pathClock.restart();

                    if (callback) {
                        model.animation.pathClock.finished.subscribe(function () {
                            callback(name);
                        });
                    }

                    if (interationCallback) {
                        model.animation.pathClock.iterated.subscribe(function () {
                            interationCallback(name);
                        });
                    }

                    if (model.rotateClock) {
                        model.rotateClock.start();
                    }
                }
            }

        }

        function addSlideAnimation(name, model, callback, delay) {
            model.animation.pathClock.duration = getRandomArbitary(aw.settings.slideAnimationSpeedLow, aw.settings.slideAnimationSpeedHigh);

            if (delay) {
                model.animation.pathClock.delay = getRandomArbitary(0.5, 3);
            }
            if (aw.settings.animationLevel >= model.lvl) {
                if (!animations[name]) {
                    animations[name] = model;
                    animations[name].animation.pathClock.restart();

                    if (callback) {
                        animations[name].animation.pathClock.finished.subscribe(function () {
                            callback(name);
                        });
                    }
                }
                else {
                    if (!model.animation.pathClock.isRunning) {

                        animations[name].animation.pathClock.restart();
                    }
                }
            }
        }

        /**
        * Returns a random number between min and max
        */
        function getRandomArbitary(min, max) {
            return Math.random() * (max - min) + min;
        }
    })();


    function startUp() {

        $(document).ready(function () {
		

				if (mobi.mobile == "True") {
					aw.settings.animationLevel = 2;
				}

				fixIndexOf();

				if (window.FlashCanvas) {
					setupFlashCanvas();
					aw.settings.animationLevel = 0;
				}
				else {
					fixIsPointInPath();
				}

				// shim layer with setTimeout fallback
				window.requestAnimFrame = (function () {
					return window.requestAnimationFrame ||
			  window.webkitRequestAnimationFrame ||
			  window.mozRequestAnimationFrame ||
			  window.oRequestAnimationFrame ||
			  window.msRequestAnimationFrame ||
			  function (/* function */callback, /* DOMElement */element) {
				  window.setTimeout(callback, 1000 / 60);
			  };
				})();

				bannerBox();

				aw.init();
				$('nav').animate({ marginTop: 0 }, 1500, function () {
					$('.slideBanner').fadeIn(1500);
				});

				$('#initial').fadeOut(1000);

				if (mobi.mobile == "True") {
					$(window).scroll(function () { $("nav").css("top", ($(document).scrollTop()) + "px"); })
				}

				$("a").click(linkClick);

				$(".slideBanner a").click(function () {
					_gaq.push(['_trackEvent', 'Side Banner', 'Banner Click', $(this).attr("href").replace('http://' + window.location.host, '')]);
				});

				/**
				*  Setup so all Canvas in old ies are setup with flashcanvas.
				*/
				function setupFlashCanvas() {
					FlashCanvas.initElement(document.getElementById("earth"));
				}

				function fixIndexOf() {
					if (!Array.indexOf) {
						Array.prototype.indexOf = function (obj) {
							for (var i = 0; i < this.length; i++) {
								if (this[i] == obj) {
									return i;
								}
							}
							return -1;
						}
					}
				}

				/**
				* Older versions of fix have a problem with isPointInPath. Fix this issue.
				[https://bugzilla.mozilla.org/show_bug.cgi?id=405300]
				*/
				function fixIsPointInPath() {
					if (window.CanvasRenderingContext2D) {
						var c2dp = CanvasRenderingContext2D.prototype;

						function isPointInPath_mozilla(x, y) {
							this.save();
							this.setTransform(1, 0, 0, 1, 0, 0);
							var ret = this.isPointInPath_old(x, y);
							this.restore();
							return ret;
						};

						//  test for the presence of the bug, and set the workaround function only if needed
						var ctx = document.createElement("canvas").getContext("2d");
						ctx.translate(50, 0);
						ctx.moveTo(125, 50);
						ctx.arc(100, 50, 25, 0, 360, false);
						if (!ctx.isPointInPath(150, 50)) {
							c2dp.isPointInPath_old = c2dp.isPointInPath;
							c2dp.isPointInPath = isPointInPath_mozilla;
						}
					}
				}

        })
    }




    $(document).ready(function () {
        $('#initial').hide();
        if (window.FlashCanvas) {
            $('.noCanvas').fadeIn();
            $('.dontCare').click(function () {
                $('.noCanvas').hide();
				
				
				
                startUp();
            });
        }
        else {

            startUp();
        }
    
    $("#mobileSite").click(function(){
      var hash = window.location.hash.substr(1);
      if (hash.length > 0) {
        var start = hash.substr(0, 1);
        if (start == '/') {
          window.location = hash + "?mobile=t";
          return false;
        }
      }
      
      window.location = "/?mobile=t";
      return false;
               
    });
    });

    function bannerImage(ctx) {
        ctx.rotate((40 * Math.PI) / 180);
        ctx.translate(-6, -49);
        try {
            ctx.drawImage(document.getElementById("bannerImage"), 0, 0, 140, 85);
        }
        catch (ex) {
        }
    }

    function toggleGallery(gallery) {

        if (gallery == "photo") {
            $("#photogallery").show();
            $("#videogallery").hide();

            $("#photoTab").addClass("active");
            $("#videoTab").removeClass("active");
        }
        else {
            $("#photogallery").hide();
            $("#videogallery").show();

            $("#photoTab").removeClass("active");
            $("#videoTab").addClass("active");

            $(".photo-container-arrow.left").css({ visibility: "hidden" });
            $(".photo-container-arrow.right").css({ visibility: "hidden" });
        }
    }



    function bannerBox() {
        var container = $('.slideBanner');
        var element = $(".slideBanner a");

        $(window).scroll(function () {
            var amount = $(document).scrollTop();

            if (amount < 2950) {
                element.css("top", amount + "px");
            }
        });
    }

    (function () {
        var current = 0;
        var bannerImage = $('#bannerImage');
        bannerImage.attr("src", bannerImages[current].src);
        setInterval(function () {
            current++;

            if (current >= bannerImages.length) {
                current = 0;
            }

            if (!window.FlashCanvas) {
                bannerImage.attr("src", '/images/static.gif');
            }
            if (aw.settings.animationLevel == 0) {
                aw.helper.refresh();
            }

            setTimeout(function () {
                bannerImage.attr("src", bannerImages[current].src);
                if (aw.settings.animationLevel == 0) {
                    aw.helper.refresh();
                }
            }, 300);

        }, 8000);

        doFishClick = function () {
            _gaq.push(['_trackEvent', 'World', 'Banner Click', bannerImages[current].hash]);
            window.location.hash = bannerImages[current].hash;
        }
    })();

    var doFishClick;

    function linkClick() {

        if( $(this).attr("target") == '_blank' )
      {
        return true;
      }
      
    if( $(this).attr("id") == "umbracoPreviewBadge" )
    {
      return true;
    }
      
      if( $(this).hasClass("skipLink") )
    {
      return true;
    }
  
    var href = $(this).attr("href");

        if (href) {
            if ($.isUrlInternal(href) && !$(this).hasClass('download')) {
                window.location.hash = href.replace('http://' + window.location.host, '');
                return false;
            }
        }
    }

    function validateEmail(elementValue) {
        var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        return emailPattern.test(elementValue);
    }
	

	

})();
