﻿(function ($) {

    $(function () {
        //move info text down
        $("#movieswapper .movinfo p").each(function () {
            $(this).css("margin-top", $(this).parent().height() - $(this).height());
        });

        //build movie pager
        var total = $("#movieswapper > div").length;
        var i = 0;
        var number;

        for (i = 0; i < total; i++) {
            //set label and add link button
            number = i + 1;
            $("#movpag").append("<a id='lnk" + i + "'>" + number + "</a>&nbsp;");

            //add click to new button
            $("#movpag #lnk" + i).click(function () {
                var id = $(this).attr("id").replace("lnk", '');

                //set selected button
                $("#movieswapper #movpag a").removeClass("sel");
                $(this).addClass("sel");

                //hide all movies and show the selected
                $("#movieswapper > div").hide();
                $("#movieswapper > div:eq(" + id + ")").show();
            });
        }

        //to start hide all but the first
        $("#movieswapper > div:not(:first)").hide();
        $("#movieswapper #movpag a:first").addClass("sel");

    });

})(jQuery);
