﻿var useFlash = false;

var maxWidth = 970;
var currentVol = 1;
var currentlyPlaying;
var imageSizes = new Object();
var imagesToResize = new Array();
var contentContainers = new Array();
var homeVideo;
var pages;
var currentScroll;
var currentWindowSize;
var fades = null;
var lastScrollTop;
var tracks = new Array();
var videos = new Array();
var agent = navigator.userAgent.toLowerCase();

$(window).load(function () {
    if (agent.indexOf("firefox") != -1 || agent.indexOf("msie") != -1 || (agent.indexOf("safari") != -1 && agent.indexOf("mobile/") == -1 && agent.indexOf("chrome/") == -1)) {
        useFlash = true;
    }

    recordWindowSize();
    recordCurrentScroll();

    initClearerDivs();
    initCenteredBoxes();

    initGlobalVolume();
    initMusicPlayer();

    initHomeVideo();
    initVideoPlayer();

    initVideoLoading();

    $("#global-container").show();

    resizeContainers();

    initGallery();

    initBandPaging();

    initResizeEvents();

    initPaging();

    initScrollLinks();

    initShop();

    initSharing();
});

function initSharing() {
    $('a.twitterShare').click(function () {
        var url = 'http://twitter.com/share?url=' + encodeURIComponent(window.location);
        if ($(this).attr('href') != '#')
            url = 'http://twitter.com/share?url=' + encodeURIComponent($(this).attr('href'));
        window.open(url, 'twitter', 'width=500,height=300');
        return false;
    });

    $('a.fbShare').click(function () {
        var url = 'http://www.facebook.com/sharer.php?u=' + encodeURIComponent(window.location);
        if ($(this).attr('href') != '#')
            url = 'http://www.facebook.com/sharer.php?u=' + encodeURIComponent($(this).attr('href'));
        window.open(url, 'facebook', 'width=500,height=300');
        return false;
    });
}

function initScrollLinks() {

    $("a.scroller").click(function (e) {
        e.preventDefault();
        $.scrollTo("#" + $(this).attr("href"), 500, { easing: 'easeInOutCubic' });
    });
}

function initShop() {
    $("#shop-frame-container").empty().append($("<iframe />").attr("src", "/shop.aspx").attr("frameborder", "0").attr("id", "shop-frame").attr("scrolling", "no"));
}

function initBandPaging() {
    initBandBackgrounds();

    var bi = $("#band-info");
    bi.find("div.bio").hide();
    bi.find("div.bio:first").addClass("first").addClass("active").show();
    bi.find("div.bio:last").addClass("last");
    bi.css("height", currentWindowSize.height + "px");
    bi.find("a.prev").hide();

    bi.find(".band-members a:first").addClass('active');
    bi.delegate('.band-members a', 'click', function (e) {
        e.preventDefault();

        var bio = $($(this).attr("href"));
        var active = $("#band-info div.active");

        active.hide();
        bio.show();
        active.removeClass("active");
        bio.addClass("active");

        if (bio.hasClass("last")) {
            $("#band-info a.next").hide();
            $("#band-info a.prev").show();
        } else if (bio.hasClass("first")) {
            $("#band-info a.prev").hide();
            $("#band-info a.next").show();
        } else {
            $("#band-info a.prev").show();
            $("#band-info a.next").show();
        }

        bi.find(".band-members a.active").removeClass("active");
        $(this).addClass("active");

        loadBioImage(bio.attr("id"));
    });

    bi.delegate("a.next", "click", function (e) {
        e.preventDefault();

        var active = $("#band-info div.active");
        var next = active.next();

        active.hide();
        next.show();

        active.removeClass("active");
        next.addClass("active");
        $("#band-info a.prev").show();
        if (next.hasClass("last")) {
            $(this).hide();
        }

        var id = next.attr("id");
        $("#band-info .band-members a.active").removeClass("active");
        $("#band-info .band-members a[href='#" + id + "']").addClass('active');

        loadBioImage(id);
    });
    bi.delegate("a.prev", "click", function (e) {
        e.preventDefault();

        var active = $("#band-info div.active");
        var prev = active.prev();

        active.hide();
        prev.show();

        active.removeClass("active");
        prev.addClass("active");

        $("#band-info a.next").show();
        if (prev.hasClass("first")) {
            $(this).hide();
        }

        var id = prev.attr("id");
        $("#band-info .band-members a.active").removeClass("active");
        $("#band-info .band-members a[href='#" + id + "']").addClass('active');

        loadBioImage(id);
    });
}

function initBandBackgrounds() {
    $("#band a.bio-image").hide();
    $("#band a.bio-image:first").addClass("active").addClass("first");
    $("#band a.bio-image:last").addClass("last");
    loadImage($("#band a.bio-image:first"), function () {
        $("#band img.active").show();
    }, false);
}

function loadBioImage(id) {
    var active = $("#band img.active");
    var load = $("#bio-image-" + id);
    if (!load.hasClass("loaded")) {
        loadImage(load, function () {
            loadBioImage(id);
        }, true);
    } else {
        active.fadeOut(500);
        load.fadeIn(500);
        active.removeClass("active");
        load.addClass("active");
    }
}

function initClearerDivs() {
    $(".clearfix").append($("<span></span>").addClass("clearfix").html("&nbsp;")).removeClass("clearfix");
}

function initCenteredBoxes() {
    centerBoxes();
}

function centerBoxes() {
    $(".centered").each(function (idx) {
        var wWidth = currentWindowSize.width;
        var thisWidth = $(this).width();
        $(this).css("left", (wWidth - thisWidth) / 2 + "px");
    });
}

function initHomeVideo() {

    homeVideo = $("#home-video");
    if (useFlash) {
        $("#hv").hide();
        var flashvars = {
            vidPath: "/resources/video/six60-home.mp4",
            imgPath: "/resources/images/ui/movie-loading.gif",
            vidID: "0",
            vidWidth: "550",
            vidHeight: "310",
            loopMe: true
        };

        var params = {
            wmode: "opaque",
            menu: "false",
            scale: "noScale",
            salign: "tl",
            allowfullscreen: "true",
            quality: "low"
        };

        swfobject.embedSWF("/resources/flash/player.swf", "homeMovieBackup", "100%", "100%", "9.0.28", "/resources/flash/expressInstall.swf", flashvars, params);

    } else {
        resizeVideo("hv");

        var vid = homeVideo.find("video").get(0);
        $(vid).bind('canplaythrough', function () {
            vid.play();
        });

        vid.load();
    }
}

function positionHomeVideo() {

    if (!useFlash) {
        var bandtop = $("#band").offset().top;
        var vidbottom = currentScroll + currentWindowSize.height;
        if (vidbottom > bandtop) {
            homeVideo.css({ position: "absolute", top: bandtop - currentWindowSize.height + "px" });
        } else {
            homeVideo.css({ position: "fixed", top: "0px" });
        }
    } else {
        var bandtop = $("#band").offset().top;
        /*if (currentScroll > bandtop) {
            homeVideo.hide();
        } else {
            homeVideo.show();
        }*/
    }
}

function initVideoPlayer() {
    $("#video-container").hide();
    if (useFlash) {
        $("#video").hide();
    }
}

function initVideoLoading() {

    $("#video-list div.list a:first").addClass("first");
    $("#video-list div.list a:last").addClass("last");

    $("#video-list div.list").delegate("a", "click", function (e) {
        e.preventDefault();
        if (!useFlash) {
            var thisLink = $(this);
            var vidSrc = thisLink.attr("rel");
            var video = $("#video").get(0);
            if (video.src.indexOf(vidSrc) == -1) {
                resetCurrentlyPlaying("video");
                video.src = vidSrc;
                video.volume = currentVol;
                $(video).bind('canplaythrough', function () {
                    video.play();
                });

                video.load();

                $(video).bind("play", function () {
                    resizeVideo("video");
                    $("#video-placeholder").hide();
                    $("#video-container").show();

                    $("#video-list div.list a.active").removeClass("active");
                    thisLink.addClass("active");
                });
            }
        } else {

            $("#video-placeholder").hide();
            $("#video-container").show();

            pauseAllFlash();

            var vidSrc = $(this).attr("rel");

            var flashvars = {
                vidPath: vidSrc,
                imgPath: "/resources/images/ui/movie-loading.gif",
                vidID: "1",
                vidWidth: "550",
                vidHeight: "310",
                loopMe: false
            };

            var params = {
                wmode: "opaque",
                menu: "false",
                scale: "noScale",
                salign: "tl",
                allowfullscreen: "true"
            };

            swfobject.embedSWF("/resources/flash/player.swf", "flashMovieBackup", "100%", "100%", "9.0.28", "/resources/flash/expressInstall.swf", flashvars, params);

            currentPlayingFlash = "flashMovieBackup";

            $("#video-list div.list a.active").removeClass("active");
            $(this).addClass("active");
        }
    });

    $("#video-list div.paging").delegate("a.next", "click", function (e) {
        e.preventDefault();

        var active = $("#video-list div.list a.active");
        var next;
        if (active.length == 0 || active.hasClass("last"))
            next = $("#video-list div.list a.first");
        else
            next = active.next();

        active.removeClass("active");
        next.addClass("active");
        next.click();
    });

    $("#video-list div.paging").delegate("a.prev", "click", function (e) {
        e.preventDefault();

        var active = $("#video-list div.list a.active");
        var prev;
        if (active.length == 0 || active.hasClass("first"))
            prev = $("#video-list div.list a.last");
        else
            prev = active.prev();

        active.removeClass("active");
        prev.addClass("active");
        prev.click();
    });

    $("#videos").delegate("video", "click", function (e) {
        resetCurrentlyPlaying("video");
        var vid = $(this).get(0);
        vid.volume = currentVol;
        if (vid.paused) {
            vid.play();
        } else {
            vid.pause();
        }
    });

    $("#videos").delegate("video", "touchend", function (e) {
        resetCurrentlyPlaying("video");
        var vid = $(this).get(0);
        vid.volume = currentVol;
        if (vid.paused) {
            vid.play();
        } else {
            vid.pause();
        }
    });
}

function initMusicPlayer() {

    if (useFlash) {
        var params = {
            menu: "false",
            scale: "noScale",
            wmode: "transparent"
        };

        $("#music-player div.track").each(function (idx) {

            var src = $(this).find("a.control").attr("rel");
            var title = $(this).find("span.title").text();
            var trackId = idx + 1;
            var id = "music-player-" + trackId;
            $(this).attr("id", id);

            var album = $(this).parents(".album");
            var albumCover = album.find(".album-cover img").attr("src");
            var albumName = album.find("h3").text();

            tracks.push({ trackName: title, albumCover: albumCover, albumName: albumName });

            var flashvars = {
                trackPath: src,
                trackTitle: encodeURIComponent(title),
                trackID: trackId
            };

            swfobject.embedSWF("/resources/flash/MP3.swf", id, "454", "30", "9.0.0", "expressInstall.swf", flashvars, params);
        });

        setTimeout(function () {
            playMusicFlash(1);
        }, 2000);

    } else {

        $("a.control").each(function (idx) {
            tracks.push($(this));
        });

        loadHTML5MusicPlayer();

        setTimeout(function () {
            $("a.control:first").click();
        }, 2000);
    }
}

function loadHTML5MusicPlayer() {
    $("#music-player").delegate(".control", "click", function (event) {
        event.preventDefault();

        var link = $(this);
        var parent = link.parent();
        var musicId = link.attr("id") + "_audio";
        var title;

        resetCurrentlyPlaying(musicId);

        if ($("#" + musicId).length == 0) {
            parent.css('border-bottom', '0');
            parent.append($("<audio></audio>").attr("id", musicId).append("<source></source>").attr("src", $(this).attr("rel")));
            parent.append($("<span></span>").addClass("progress").append($("<span></span>").addClass("bar")));

            var music = document.getElementById(musicId);
            title = parent.find(".title").text();
            parent.find(".title").append($("<i></i>"));
            $(music).bind('timeupdate', function () {
                var length = music.duration;
                var secs = music.currentTime;
                var progress = parseInt(((secs / length) * 100), 10);
                parent.find('.progress .bar').css({ 'width': progress + '%' });

                // And finally calculate where we are in the track
                var tcMins = parseInt(secs / 60);
                var tcSecs = parseInt(secs - (tcMins * 60));
                if (tcSecs < 10) { tcSecs = '0' + tcSecs; }

                // Display the time
                parent.find('.title i').text(" (" + tcMins + ":" + tcSecs + ")");
            });

            music.addEventListener('ended', function () {
                var idx;
                for (var i = 0; i < tracks.length; i++) {
                    if (tracks[i].attr("id") == link.attr("id")) {
                        idx = i + 1;
                        break;
                    }
                }

                if (idx == tracks.length)
                    idx = 0;

                var track = tracks[idx];
                if (link.attr("mediaId") == track.attr("mediaId")) {
                    idx = idx + 1;
                    if (idx == tracks.length)
                        idx = 0;

                    track = tracks[idx];
                }

                track.click();
            });

            music.volume = currentVol;
            music.addEventListener('canplaythrough', function () {
                music.play();
            });

            music.load();

            $(this).addClass("playing");

        } else {
            var music = document.getElementById(musicId);
            music.volume = currentVol;
            if (music.paused) {
                music.play();
                $(this).addClass("playing");
            } else {
                music.pause();
                $(this).removeClass("playing");
            }

            title = parent.find(".title").html();
            title = title.substring(0, title.indexOf("<i>"));
        }

        $("#current-track-name").html(title);
        var albumCover = link.parents(".album").find(".album-cover img");
        $("#current-track-cover").hide().attr("src", albumCover.attr("src")).fadeIn("fast");
        var albumName = link.parents(".album").find("h3").text();
        $("#current-album h2").hide().text(albumName).fadeIn("fast");
        $("#current-album").css("visibility", "visible");
    });
}

function initGlobalVolume() {
    $("body").append($("<div></div>").attr("id", "global-volume").append($("<div></div>")));
    $("#global-volume div:first-child").slider({
        orientation: 'horizontal',
        range: "min",
        min: 0,
        max: 100,
        value: (currentVol * 100),
        slide: function (event, ui) {
            currentVol = (ui.value / 100);
            if (currentlyPlaying != null) {
                var media = document.getElementById(currentlyPlaying);
                if (media.muted)
                    media.muted = false;
                media.volume = currentVol;
            }

            if (useFlash) {
                setVolumeFlash(currentVol);
            }
        }
    });
}

function initGallery() {
    prepareAjaxLoader();

    $("#gallery .images a").hide();
    $("#gallery .images a:first").addClass("active").addClass("first");
    $("#gallery .images a:last").addClass("last");
    loadImage($("#gallery .images a:first"), function () {
        $("#gallery .images img.active").show();
    }, false);

    $("#gallery").delegate(".next", "click", function (e) {
        e.preventDefault();
        nextImage();
    });

    $("#gallery").delegate(".prev", "click", function (e) {
        e.preventDefault();
        prevImage();
    });
}

function prevImage() {
    var active = $("#gallery .images img.active");
    var prev = active.prev();
    if (active.hasClass("first"))
        prev = $(".images .last");

    if (!prev.hasClass("loaded")) {
        prev = loadImage(prev, function () {
            prevImage();
        }, true);
    } else {
        active.fadeOut(500);
        prev.fadeIn(500);
        active.removeClass("active");
        prev.addClass("active");
    }
}

function nextImage() {
    var active = $("#gallery .images img.active");
    var next = active.next();
    if (active.hasClass("last"))
        next = $(".images .first");

    if (!next.hasClass("loaded")) {
        loadImage(next, function () {
            nextImage();
        }, true);
    } else {
        active.fadeOut(500);
        next.fadeIn(500);
        active.removeClass("active");
        next.addClass("active");
    }
}

function prepareAjaxLoader() {
    var ajaxload = $("<div></div>")
        .attr("id", "ajaxload")
        .append($("<span></span")
        .text("please wait"))
        .css("height", currentWindowSize.height)
        .prependTo("body")
        .hide();
    ajaxload.find("span")
        .css("top", (currentWindowSize.height - 80) / 2 - 100 + "px")
        .css("left", (currentWindowSize.width - 300) / 2 + "px");

}
function positionAjaxLoader() {
    $("#ajaxload")
        .css("width", currentWindowSize.width)
        .css("height", currentWindowSize.height);

    $("#ajaxload span")
        .css("top", (currentWindowSize.height - 80) / 2 - 100 + "px")
        .css("left", (currentWindowSize.width - 300) / 2 + "px");
}

function loadImage(link, callback, showAjaxLoader) {
    if (showAjaxLoader)
        $("#ajaxload").show();
    var image = $("<img></img>")
                .attr("id", link.attr("id"))
                .attr("class", link.attr("class"))
                .attr("src", link.attr("href"))
                .attr("width", link.attr("width"))
                .attr("height", link.attr("height"))
                .addClass("image-bg")
                .hide();

    link.replaceWith(image);

    image.bind('load', function (e) {
        imageSizes[$(this).attr('id')] = { width: $(this).width(), height: $(this).height() };
        imagesToResize.push($(this));
        resizeImage($(this));

        $(this).addClass("loaded");

        callback();

        if (showAjaxLoader) {
            setTimeout(function () {
                $("#ajaxload").hide();
            }, 500);
        }
    });

    return image;
}

function initPaging() {
    initContentContainers();
    loadPageCoords();
    $("#nav li:first").addClass("active");
    lastScrollPosition = currentScroll;

    calculateActivePage();

    $("#nav li").delegate("a", "click", function (e) {
        e.preventDefault();
        $.scrollTo("#" + $(this).attr("href"), 500, { easing: 'easeInOutCubic' });
    });
}

function initResizeEvents() {
    loadImageDimensions();
    resizeAssets(false);
}

function loadPageCoords() {
    pages = new Array();
    for (var i = 0; i < contentContainers.length; i++) {
        var container = contentContainers[i];
        var offset = container.offset();
        var height = container.height();
        pages.push({
            index: i,
            id: container.attr("id"),
            scrollStart: offset.top,
            scrollEnd: offset.top + height,
            height: height
        });
    }
}

function initContentContainers() {
    $('.content-container').each(function (idx) {
        contentContainers.push($(this));
    });
}

function loadImageDimensions() {
    imagesToResize = new Array();
    $("img.image-bg").each(function (idx) {
        imageSizes[$(this).attr("id")] = { width: parseInt($(this).attr("width")), height: parseInt($(this).attr("height")) };
        imagesToResize.push($(this));
    });
}

function getActivePageId() {
    return $("#nav li.active a").attr("href");
}

function calculateActivePage() {
    var curScroll = currentScroll + currentWindowSize.height - 200;
    var dir = "down";
    if (curScroll < lastScrollTop)
        dir = "up";

    lastScrollTop = curScroll;
    if (dir == "up")
        curScroll = currentScroll + 50;

    var activeIdx;
    for (var i = 0; i < pages.length; i++) {
        var page = pages[i];
        if (curScroll >= page.scrollStart && curScroll < page.scrollEnd) {
            activeIdx = i;
            break;
        }
    }

    $("#nav li.active").removeClass("active");
    $("#nav li:eq(" + activeIdx + ")").addClass("active");
}

function resizeContainers() {
    $(".resize-container").css("min-height", currentWindowSize.height + "px");
    $(".resize-container-to-window").css("height", currentWindowSize.height + "px");
}

function resizeAssets(performVideoResize) {
    resizeImages();
    if (!useFlash && performVideoResize) {
        resizeVideo("video");
        resizeVideo("hv");
    }
}

function supportsVideo() {
    return useFlash;
}

function resizeImages() {
    for (var i = 0; i < imagesToResize.length; i++) {
        resizeImage(imagesToResize[i]);
    }
}

function resizeImage(img) {
    var wWidth = currentWindowSize.width;
    if (wWidth < maxWidth)
        wWidth = maxWidth;

    var wHeight = img.parent().height();
    var windowRatio = wHeight / wWidth;

    var iWidth = imageSizes[$(img).attr("id")].width;
    var iHeight = imageSizes[$(img).attr("id")].height;
    var imageRatio = iHeight / iWidth;

    if (windowRatio <= imageRatio) {
        var newHeight = (wWidth * imageRatio);
        var reset = (newHeight - wHeight) / 2;
        img.css("width", wWidth + "px");
        img.css("height", newHeight + "px");
        img.attr("width", wWidth);
        img.attr("height", newHeight);
        img.css("top", "-" + reset + "px");
        img.css("left", "0");
    } else {
        var newRatio = iWidth / iHeight;
        var newWidth = (wHeight * newRatio);
        var reset = (newWidth - wWidth) / 2;
        img.css("height", wHeight + "px");
        img.css("width", newWidth + "px");
        img.attr("height", wHeight);
        img.attr("width", newWidth);
        img.css("left", "-" + reset + "px");
        img.css("top", "0");
    }
}

function resizeVideo(video) {
    var wWidth = currentWindowSize.width;
    if (wWidth < maxWidth)
        wWidth = maxWidth;

    var wHeight = currentWindowSize.height;
    var windowRatio = wHeight / wWidth;

    var vWidth = parseInt(document.getElementById(video).videoWidth);
    var vHeight = parseInt(document.getElementById(video).videoHeight);
    var aspectRatio = vHeight / vWidth;

    var videoEle = $("#" + video);
    if (windowRatio <= aspectRatio) {
        var newHeight = (wWidth * aspectRatio);
        var reset = (newHeight - wHeight) / 2;
        videoEle.css("top", "-" + reset + "px");
        videoEle.css("left", "0");
        videoEle.css("width", wWidth + "px");
        videoEle.css("height", newHeight + "px");
    } else {
        var newRatio = vWidth / vHeight;
        var newWidth = (wHeight * newRatio);
        var reset = (newWidth - wWidth) / 2;
        videoEle.css("left", "-" + reset + "px");
        videoEle.css("top", "0");
        videoEle.css("height", wHeight + "px");
        videoEle.css("width", newWidth + "px");
    }
}

function resetCurrentlyPlaying(id) {
    if (currentlyPlaying != null && currentlyPlaying != id) {
        $("#" + currentlyPlaying).get(0).pause();
        $(".playing").removeClass("playing");
    }

    currentlyPlaying = id;
}

function resizeShop(height) {
    var currHeight = $("#shop-frame").height();
	var minHeight = parseInt($('#shop div.resize-container:first').css('min-height').replace('px', ''));
    if (height > minHeight) {
        $("#shop-frame").css("height", height + "px");
    } else {
        $("#shop-frame").css("height", minHeight + "px");
	}
}

function getMinHeight() {
    return currentWindowSize.height;
}

function logoFade() {
    if (fades == null)
        buildFades();

    var logo = $("h1");
    var logoPos = { start: logo.offset().top, end: logo.offset().top + logo.height() };
    for (var i = 0; i < fades.length; i++) {
        var fade = fades[i];
        if (logoPos.end >= fade.start && logoPos.start < fade.end) {
            if (!logo.hasClass("insideFadeArea")) {
                logo.fadeTo(500, 0.3);
            }

            logo.addClass("insideFadeArea");
        } else {
            if (logo.hasClass("insideFadeArea")) {
                logo.fadeTo(500, 1);
            }

            logo.removeClass("insideFadeArea");
        }
    }
}

function buildFades() {
    fades = new Array();
    $(".logo-fade").each(function (idx) {
        var offset = $(this).offset();
        fades.push({ start: offset.top, end: offset.top + $(this).height() });
    });
}

function logoContactFade() {
    var logo = $("h1");
    if ((logo.offset().top + logo.height()) >= $("#contact").offset().top) {
        logo.hide();
    } else {
        logo.show();
    }
}

function recordWindowSize() {
    currentWindowSize = { width: $(window).width(), height: $(window).height() };
}

function recordCurrentScroll() {
    currentScroll = $(window).scrollTop();
}

$(window).resize(function () {
    recordWindowSize();
    centerBoxes();
    resizeContainers();
    resizeAssets(true);
    loadPageCoords();
    positionAjaxLoader();

    var activePage = $($("#nav li.active a").attr("href"));
    if (activePage != null && activePage.offset() != null) {
        $(window).scrollTop(activePage.offset().top);
    }
});

$(window).scroll(function () {
    recordCurrentScroll();

    positionHomeVideo();
    calculateActivePage();
    logoFade();
    logoContactFade();
});


// --- FLASH FUNCTIONS --- //

var currentPlayingFlash = null;

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}

function pauseAllFlash() {
    if (currentPlayingFlash != null) {
        if (currentPlayingFlash.indexOf("music") != -1) {
            thisMovie(currentPlayingFlash).pauseMP3();
        } else {
            thisMovie(currentPlayingFlash).pauseVideo();
        } 
    }
}

function mp3Play(trackID) {
    var musicId = "music-player-" + trackID;
    if (currentPlayingFlash != null && currentPlayingFlash != musicId) {
        pauseAllFlash();
    }

    if (currentPlayingFlash != musicId) {
        currentPlayingFlash = musicId;
        var idx = trackID - 1;
        var trackInfo = tracks[idx];

        $("#current-track-name").text(trackInfo.trackName);
        $("#current-track-cover").hide().attr("src", trackInfo.albumCover).fadeIn("fast");
        $("#current-album h2").hide().text(trackInfo.albumName).fadeIn("fast");
        $("#current-album").css("visibility", "visible");
    }

    setVolumeFlash(currentVol);
}

function mp3End(trackID) {
    if (trackID <= tracks.length) {
        playMusicFlash(trackID+1);
    } else {
        playMusicFlash(1);
    }
}

function playMusicFlash(trackID) {
    thisMovie("music-player-" + trackID).playMP3();
}

function pauseMusicFlash(trackID) {
    thisMovie("music-player-" + trackID).pauseMP3();
}

function setVolumeFlash(volume) {
    thisMovie(currentPlayingFlash).setVolume(volume);
}

function getGlobalVol() {
    return currentVol;
}

function videoPlay(vidID) {
    if (vidID == 1 && currentPlayingFlash.indexOf("music") != -1) {
        pauseAllFlash();
    }

    setVolumeFlash(currentVol);
}

function scrollToShop() {
    $.scrollTo("#shop", 500, { easing: 'easeInOutCubic' });
}
