﻿// common.js
//
// This file is the uncompressed source file for Yesworld.  The final file to
// used should be YUI compressed and should be called common-min.js.
//
//
// Prerequisites:
//
//    jquery (v1.5.1 or later)
//    colorbox for jquery
//
//
// Format:
//
//    This file contains the javascript for various objects.  Please keep the
//    functions together and in their appropriate section.
//

// Gallery
//
//============================================================================
$(document).ready(function () {
    $(".galleryitem a.img").colorbox({ title: function () { return this.title; } });
    $(".galleryitem a.vid").colorbox({ iframe: true, width: 560, height: 349 });
});

var NbrGallery = 0;
var GalleryTimeout;

$(document).ready(function () {
    if (typeof YWGALLERY != 'undefined') {
        NbrGallery = YWGALLERY.length;
        var selected = 0;
        updateGalleryPreview(selected);
    }
});

function updateGalleryPreview(sel) {
    $("#galleryimage").fadeOut(400, function () {
        if (YWGALLERY[sel].Type == "image") {
            $("#galleryimage").html("<a class='img' href='" + YWGALLERY[sel].ImagePath + "'><img alt='" + YWGALLERY[sel].Alt + "' title='" + YWGALLERY[sel].Title + "' src='" + YWGALLERY[sel].ThumbPath + "' /></a>");
        }
        else {
            $("#galleryimage").html("<a class='vid' href='" + YWGALLERY[sel].Link + "'><img alt='" + YWGALLERY[sel].Alt + "' title='" + YWGALLERY[sel].Title + "' src='" + YWGALLERY[sel].ThumbPath + "' /></a>");
        }
        $("#galleryimage a.img").colorbox({ title: function () { return this.Title; } });
        $("#galleryimage a.vid").colorbox({ iframe: true, width: 560, height: 349 });
        $("#galleryimage").fadeIn();
        if (++sel === NbrGallery) sel = 0;
        if (NbrGallery > 1) GalleryTimeout = setTimeout("updateGalleryPreview(" + sel + ")", 10000);
    });
}


// Catalog
//
//============================================================================
$(document).ready(function () {
    $("span", ".catalogsubnav").click(function () {

        // mark clicked filter
        $("span", ".catalogsubnav").removeClass("grey");
        $(this).addClass("grey");

        // filter the results
        var id = $(this).attr("id");
        $(".catalog .release").each(function () {
            if ($(this).hasClass(id) || id === "all") {
                $(this).show();
            }
            else {
                $(this).hide();
            }
        });
    });

    $("a", "div.image").colorbox();

    // auto-check 'all' on page load
    $("span#all", ".catalogsubnav").click();
});


// Hero
//
//============================================================================
var NbrNews = 0;
var NewsTimeout;

$(document).ready(function () {
    var selectedNews = 0;
    NbrNews = $("div.news").length;

    newsUpdate(selectedNews);
});

function newsUpdate(idx) {
    $(".channels a img").removeClass("channelSelected");
    $(".channels a:nth-child(" + (idx + 1) + ") img").addClass("channelSelected");
    $("div.newslist div.news").hide();
    $("div.newslist").find("div[id$='news_" + idx + "']").fadeIn("slow");
    // find the next index
    if (++idx === NbrNews) idx = 0;
    // set the timeout
    if (NbrNews > 1) NewsTimeout = setTimeout("newsUpdate(" + idx + ")", 9000);
}

function loadHeroImages(imgArray) {
    for (var i = 1; i <= imgArray.length; i++) {
        $("div[id='news_" + i + "'] div.heroimagecontainer img").attr("src", imgArray[i - 1]);
    }
}


// Members
//
//============================================================================
$(document).ready(function () {
    showMember(0);
    $("div.bandmembersubnav span").click(function () {
        var parts = $(this).attr("id").split('_');
        showMember(parts[parts.length - 1]);
    });
});

function showMember(nbr) {
    $("div.bandmemberbiocontainer").find("div[id^='memberbio_']").hide();
    $("div.bandmemberbiocontainer div#memberbio_" + nbr).show();
}
