var albums = [
    "vision", "clients", "team", "careers", "contact", "testimonies", "advertising", "audio", "brand", "copy_editing", "copywriting", "creative", "design", "direct_mail", "fashion", "games", "internet", "photography", "press", "proofreading", "publications", "television", "transcribing"
];

window.onload = function(e) {
    for (var i = 0; i < albums.length; i++) {
        var album = albums[i];
        $("<img>").attr("src", "/themes/cre8ion/images/" + album + ".jpg");
    }
}

var mycarousel_itemList = [];

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1], i));
    Shadowbox.setup($(".monkey" + i));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

function mycarousel_getItemHTML(item, i)
{
    return '<a class="monkey' + i + '" href="' + item.target + '" title="' + item.title + '" rel="' + item.rel + '"><img src="' + item.thumbnail + '" alt="' + item.title + ' /></a>';
};

$(function() {

    mycarousel_itemList = $.map($('#carousel li'), function (e) {
       var a = $("a", $(e));
       var img = $("img", $(e));
       return { thumbnail: img.attr('src'), target: a.attr('href'), title: a.attr('title'), rel: a.attr('rel') };
    });
    $('#carousel').empty();

    Shadowbox.init();

    $('#carousel').jcarousel({
        buttonNextEvent: "mouseover click",
        buttonPrevEvent: "mouseover click",
        scroll: 1,
        auto: 1,
        wrap: 'circular',
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
    $("#navigation").accordion({
        header: "h2",
        event: "mouseover",
        collapsible: true,
        active: -1
    })
});


/* hover background for collections */

$(function () {

    $("#content").each(function() {
        var me = $(this);

        $("a", me).hover(function (e) {
            var oldBg = $(".background", me);
            var newBg = $("<div class='background'></div>");
            newBg.addClass($(e.target).attr("title"));
            newBg.css("display", "none");
            if (oldBg.length == 0) { $(":first", me).before(newBg); }
            else { oldBg.after(newBg); }
            newBg.fadeIn(600, function() {
                oldBg.remove();
            });
            return false;
        });
        
    });

});

/* background for album */

$(function () {

    $("#contents").each(function() {
        var me = $(this);

        $("a", me).hover(function (e) {
            var oldBg = $(".background", me);
            var newBg = $("<div class='background'></div>");
            newBg.addClass($(e.target).attr("title"));
            newBg.css("display", "none");
            if (oldBg.length == 0) { $(":first", me).before(newBg); }
            else { oldBg.after(newBg); }
            newBg.fadeIn(600, function() {
                oldBg.remove();
            });
            return false;
        });
        
    });

});

