﻿(function($) {

    $.fn.albumsAnim = function(options) {

        // default configuration properties
        var defaults = {
            prevId: 'deckLeft',
            nextId: 'deckRight',
            speed: 800
        };

        var options = $.extend(defaults, options);

        return this.each(function() {

            obj = $(this);
            var currentDeck = 0;
            var maxDecks = $("ul:first", this).children().length / 7;

            var objRef = "#" + obj.attr("id");

            $("#" + options.nextId).hover(function() {
                $("#" + options.nextId).addClass("active");
            }, function() {
                $("#" + options.nextId).removeClass("active");
            });

            $("#" + options.nextId).click(function() {
                if (currentDeck < (maxDecks - 1)) {
                    var deckPos = ((currentDeck + 1) * -595);
                    $("ul:first", objRef).animate({ marginLeft: deckPos }, 1800);
                    currentDeck++;
                }
            });

            $("#" + options.prevId).hover(function() {
                $("#" + options.prevId).toggleClass("active");
            }, function() {
                $("#" + options.prevId).toggleClass("active");
            });

            $("#" + options.prevId).click(function() {
                if (currentDeck > 0) {
                    var deckPos = ((currentDeck - 1) * -595);
                    $("ul:first", objRef).animate({ marginLeft: deckPos }, 1800);
                    currentDeck--;
                }
            });

        });

    };

    $.fn.albumPreview = function(options) {

        // default configuration properties
        var defaults = {};

        var options = $.extend(defaults, options);

        return this.each(function() {

            obj = $(this);
            var objRef = "#" + obj.attr("id");

            $("li", this).each(function() {

                $(this).bind("click", function() {
                    var imgName = $("img:first", this).attr("title");
                    WebForm_DoCallback("__Page", imgName, ActOnPreview, "", null, false);
                });
            });
        });

    };

    function ActOnPreview(arg) {

        args = arg.split('|');

        $(".previewcontainer a img").attr("src", args[0]);
        $(".previewcontainer a").attr("href", args[1]);
        $(".previewcontainer").width($(".previewcontainer a img").width());
    }

})(jQuery);