﻿/*
Ajax paging plugin.
Apply this plugin to any container e.g. a div.
    
Usage:
$("#containerId").paging({
pageSize: 5, // Optional - specifies the number of elements per page.
currentPage: 1, // Optional - specifies the current displaied page (or start page).
totalPages: 1, // Optional - Will be overwritten with the result from the WebMethod behind 'itemCountUrl'.
template: 'path to template', // Required - Specifies the markup for the navigation links and data container.
dataUrl: 'path to WebMethod', // Required - Should return a IEnumerable that fits with the template.
numberOfLinks: 10, // optional - Specifies the number of direct page links.
itemCountUrl: 'path to the WebMethod', // required - Should return an integer that equals the total number of elements in the datasource
pagingLinkClass: '', // required - specifies the class name of the direct page links.
nextPageClass: '', // required - specifies the class name of the "next page" links.
previousPageClass: '' // required - specifies the class name of the "previous page" links.
});
    
For generating jTemplates have a look at this website: http://jtemplates.tpython.com/
*/

(function($) {
    $.fn.fasttrackpaging = function(options) {
        var defaults = {
            pageSize: 5,
            currentPage: 1,
            totalPages: 1,
            dataContainer: '',
            dataUrl: '',
            numberOfLinks: 10,
            itemCountUrl: '',
            pagingLinkClass: '',
            nextPageClass: '',
            previousPageClass: '',
            sortContainer: '',
            filters: [],
            sortKey: '',
            resetKey: [],
            pagingContainerClass: '',
            pageIndexContainer: '',
            pageCountContainer: '',
            useExternalFilter: false
        };

        var options = $.extend({}, defaults, options);
        var $this = this;
        var originalNumberOfLinks = options.numberOfLinks;
        var originalSortKey = options.sortKey;
        var filter = [];
        var genre;
        var oldGenre;
        var movie;
        var oldMovie;
        var date;
        var oldDate;
        var city;
        var oldCity;
        var firstDateChange = true;
        var itemCount = 0;

        this.initialize = function() {
            $.historyInit($this.DisplayData, "");
            if (options.numberOfLinks > options.totalPages) {
                options.numberOfLinks = options.totalPages;
            }
            $.each(options.resetKey, function(key, item) {
                $this.find(item.key).click(function() {
                    $.each(item.filters, function(k, i) {
                        for (var j = 0; j < filter.length; j++) {
                            if (i == filter[j].key) {
                                filter[j].value = '';
                                break;
                            }
                        }
                    });
                    $this.HistoryLoad(true);
                });
            });
            this.UpdateSorting();
            this.UpdateTotalCount();
            this.UpdatePaging();
        };

        this.DisplayData = function(hash) {
            BlockPage();
            var localThis = $this;
            var updateHeader = false;
            var repopulate = false;
            if (hash) {
                hash = $.base64.decode(hash);
                var splitHash = hash.split('&');
                $.each(splitHash, function(index, value) {
                    var entry = value.split('=');
                    switch (entry[0].toLowerCase()) {
                        case 'pagesize':
                            options.pageSize = entry[1];
                            break;
                        case 'pageindex':
                            options.currentPage = entry[1];
                            break;
                        case 'sortkey':
                            options.sortKey = entry[1];
                            break;
                        case 'updateheader':
                            updateHeader = true;
                            break;
                        default:
                            $.each(options.filters, function(key, item) {
                                if (item.name == entry[0]) {
                                    $this.UpdateFilter(item, entry[1]);
                                }
                            });
                            break;
                    }
                });
            }
            else {
                repopulate = true;
                updateHeader = true;
                options.currentPage = 1;
                options.sortKey = originalSortKey;
                $.each(options.filters, function(key, item) {
                    $this.UpdateFilter(item, '');
                });
                $this.UpdateParameters();
                var parameters = 'genre=' + genre + '&movieId=' + movie + '&date=' + date + '&city=' + city;
                hash = "control=" + options.dataUrl + "&pageSize=" + options.pageSize + "&pageIndex=" + options.currentPage + "&sortKey=" + options.sortKey + "&" + parameters;
            }
            window.setTimeout(
                function() {
                    $.ajax(
                    {
                        type: "POST",
                        url: "/Layouts/AjaxPages/ControlLoader.aspx",
                        data: hash,
                        dataType: "text",
                        success: function(data) {
                            var y = $this.find('#' + options.dataContainer).html(data).offset().top;
                            window.scrollTo(0, y - 200);
                            $this.UpdateTotalCount();
                            $this.UpdateHeader($('select.movieId'), $('select.date').eq(0));
                            $this.RepopulateAll();
                            $this.find('.' + options.sortContainer).children('a').removeClass('selected');
                            $this.find('.' + options.sortContainer).children('a[id=' + options.sortKey + ']').addClass('selected');
                        }
                    });
                },
            1);


        };

        this.HistoryLoad = function(add, repopulate) {
            this.UpdateParameters();
            var parameters = 'genre=' + genre + '&movieId=' + movie + '&date=' + date + '&city=' + city;
            var str = "control=" + options.dataUrl + "&pageSize=" + options.pageSize + "&pageIndex=" + options.currentPage + "&sortKey=" + options.sortKey + "&" + parameters;
            if (add) {
                str += '&updateHeader=true';
            }
            $.historyLoad($.base64.encode(str));
            return false;
        };

        this.UpdateTotalCount = function() {
            options.numberOfLinks = originalNumberOfLinks;
            itemCount = TotalCount;
            options.totalPages = Math.ceil(TotalCount / options.pageSize);
            if (options.numberOfLinks > options.totalPages) {
                options.numberOfLinks = options.totalPages;
            }
            var itemCountSpan = $('span.colorlayout3');
            if (itemCountSpan.length > 0) {
                itemCountSpan.html(itemCount);
                if (itemCount != 0)
                    itemCountSpan.show();
                else
                    itemCountSpan.hide();
            }
            this.UpdatePaging();

        };

        this.FirstLinkedPage = function() {
            var halfLimit = Math.floor(options.numberOfLinks / 2);
            if (options.currentPage >= 1 && options.currentPage <= halfLimit) {
                return 1;
            }
            if (options.currentPage >= options.totalPages - options.numberOfLinks + halfLimit && options.currentPage <= options.totalPages) {
                return options.totalPages - options.numberOfLinks + 1;
            }
            return options.currentPage - halfLimit + 1;
        };

        this.LastLinkedPage = function() {
            return this.FirstLinkedPage() + options.numberOfLinks - 1;
        };

        this.UpdateDirectLinks = function() {
            if ($this.find('a.directlink').length != options.numberOfLinks) {
                $this.find('.pagingpages').html('');
                for (var i = 1; i <= options.numberOfLinks; i++) {
                    var pagingLink = '<div class="pagingpage">';
                    pagingLink += '<a href="#page_' + i + '" title="" kn:page="' + i + '" class="paginglink directlink">' + i + '</a>';
                    pagingLink += '</div>';
                    $this.find('.pagingpages').append(pagingLink);
                }
            }
            $this.find('.pagingfirstpage').find('a').attr('kn:page', '1');
            $this.find('.pagingfirstpage').find('a').attr('href', '#page_1');
            $this.find('.paginglastpage').find('a').attr('kn:page', options.totalPages);
            $this.find('.paginglastpage').find('a').attr('href', '#page_' + options.totalPages);
            if (options.currentPage == 1) {
                $this.find('.pagingfirstpage').find('a').parent().hide();
            }
            else {
                $this.find('.pagingfirstpage').find('a').parent().show();
            }
            if (options.currentPage == options.totalPages) {
                $this.find('.paginglastpage').find('a').parent().hide();
            }
            else {
                $this.find('.paginglastpage').find('a').parent().show();
            }
        };

        this.UpdatePaging = function() {
            if (options.totalPages <= 1) {
                $.each(options.pagingContainerClass, function(key, c) {
                    $this.find('.' + c).hide();
                });
                return false;
            }
            else {
                $.each(options.pagingContainerClass, function(key, c) {
                    $this.find('.' + c).show();
                })
            }

            $this.find('.' + options.pagingLinkClass).unbind('click');
            $this.find('.' + options.pagingLinkClass).attr('href', '');
            $this.UpdateDirectLinks();

            var page = 0;
            $this.find('a.directlink').each(function() {
                $(this).attr('kn:page', page + $this.FirstLinkedPage());
                $(this).text(page + $this.FirstLinkedPage());
                page++;
                $(this).parent().removeClass('pagingpageactive');
                if ($(this).attr('kn:page') == options.currentPage) {
                    $(this).parent().addClass('pagingpageactive');
                }
            });
            $this.find(options.pageIndexContainer).html(options.currentPage);
            $this.find(options.pageCountContainer).html(options.totalPages);
            // Reset and disable all prev/next links.
            $this.find('.' + options.previousPageClass).unbind('click');
            $this.find('.' + options.previousPageClass).attr('href', '');
            $this.find('.' + options.nextPageClass).unbind('click');
            $this.find('.' + options.nextPageClass).attr('href', '');
            // If we're not on the first page, enable the "Previous" link.
            if (options.currentPage != 1) {
                $this.find('.' + options.previousPageClass).find('img').removeClass('inactive');
                var prevPage = options.currentPage * 1 - 1;
                $this.find('.' + options.previousPageClass).attr('href', '#page_' + prevPage);
                $this.find('.' + options.previousPageClass).click(
                    function(e) {
                        e.preventDefault();
                        --options.currentPage;
                        if (options.currentPage < 1) {
                            ++options.currentPage;
                            return false;
                        }
                        $this.HistoryLoad(false);
                        return false;
                    }
                );
            }
            else {
                $this.find('.' + options.previousPageClass).find('img').addClass('inactive');
            }
            // If we're not on the last page, enable the "Next" link.
            if (options.currentPage != options.totalPages) {
                $this.find('.' + options.nextPageClass).find('img').removeClass('inactive');
                var nextPage = options.currentPage * 1 + 1;
                $this.find('.' + options.nextPageClass).attr('href', '#page_' + nextPage);
                $this.find('.' + options.nextPageClass).click(
                    function(e) {
                        e.preventDefault();
                        ++options.currentPage;
                        if (options.currentPage > options.totalPages) {
                            --options.currentPage;
                            return false;
                        }
                        $this.HistoryLoad(false);
                        return false;
                    }
                );
            }
            else {
                $this.find('.' + options.nextPageClass).find('img').addClass('inactive');
            }
            $this.find('.' + options.pagingLinkClass).each(
                function(index) {
                    var link = $(this);
                    link.click(
                        function(e) {
                            e.preventDefault();
                            options.currentPage = link.attr('kn:page');
                            $this.HistoryLoad(false);
                            return false;
                        }
                    );
                }
            );
        };

        this.UpdateSorting = function() {
            if (options.sortContainer != '') {
                if (options.sortKey != '') {
                    $this.find('.' + options.sortContainer).children('a[id=' + options.sortKey + ']').addClass('selected');
                }
                $this.find('.' + options.sortContainer).children('a').each(function() {
                    $(this).click(function() {
                        options.sortKey = $(this).attr('id');
                        $this.find('.' + options.sortContainer).find('a.selected').removeClass('selected');
                        $(this).addClass('selected');
                        options.currentPage = 1;
                        $this.HistoryLoad(false);
                        return false;
                    });
                });
            }
            if (options.filters.length > 0) {
                $.each(options.filters, function(key, filter) {
                    var control = $(filter.control);
                    switch (filter.name) {
                        case 'genre':
                            control.change(function(e) {
                                e.stopPropagation();
                                e.preventDefault();
                                $this.GenreChange($(this));
                            });
                            break;
                        case 'movieId':
                            control.change(function(e) {
                                e.stopPropagation();
                                e.preventDefault();
                                $this.MovieChange($(this));
                            });
                            break;
                        case 'date':
                            control.change(function(e) {
                                e.stopPropagation();
                                e.preventDefault();
                                $this.DateChange(e, $(this));
                            });
                            break;
                        case 'city':
                            control.change(function(e) {
                                e.stopPropagation();
                                e.preventDefault();
                                $this.CityChange($(this));
                            });
                            break;
                    }
                });
            }
        };

        this.RepopulateAll = function() {
            var queryString = "'genre': '" + genre + "', 'movieId': '" + movie + "', 'date': '" + date + "', 'city': '" + city + "'";
            $.ajax({
                type: "POST",
                url: '/Webservices/FasttrackOptions.asmx/AllOptions',
                data: '{' + queryString + '}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) {
                    var result = data.d;
                    $('select.date').html(result.Dates.SelectOptions);
                    if (result.Dates.SelectedValue != '') {
                        $('select.date').val(result.Dates.SelectedValue);
                    }
                    $('select.movieId').html(result.Movies.SelectOptions);
                    if (result.Movies.SelectedValue != '') {
                        $('select.movieId').val(result.Movies.SelectedValue);
                    }
                    $('select.genre').html(result.Genres.SelectOptions);
                    if (result.Genres.SelectedValue != '') {
                        $('select.genre').val(result.Genres.SelectedValue);
                    }
                    $('select.city').html(result.Cities.SelectOptions);
                    if (result.Cities.SelectedValue != '') {
                        $('select.city').val(result.Cities.SelectedValue);
                    }
                }
            });
        };

        this.RepopulateDateCityGenre = function() {
            var queryString = "'genre': '" + genre + "', 'movieId': '" + movie + "', 'date': '" + date + "', 'city': '" + city + "'";
            $.ajax({
                type: "POST",
                url: '/Webservices/FasttrackOptions.asmx/GetDateCityGenre',
                data: '{' + queryString + '}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) {
                    var result = data.d;
                    $('select.date').html(result.Dates.SelectOptions);
                    if (result.Dates.SelectedValue != '') {
                        $('select.date').val(result.Dates.SelectedValue);
                    }
                    $('select.genre').html(result.Genres.SelectOptions);
                    if (result.Genres.SelectedValue != '') {
                        $('select.genre').val(result.Genres.SelectedValue);
                    }
                    $('select.city').html(result.Cities.SelectOptions);
                    if (result.Cities.SelectedValue != '') {
                        $('select.city').val(result.Cities.SelectedValue);
                    }
                }
            });
        };

        this.RepopulateMovieCityGenre = function() {
            var queryString = "'genre': '" + genre + "', 'movieId': '" + movie + "', 'date': '" + date + "', 'city': '" + city + "'";
            $.ajax({
                type: "POST",
                url: '/Webservices/FasttrackOptions.asmx/GetMovieCityGenre',
                data: '{' + queryString + '}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) {
                    var result = data.d;
                    $('select.movieId').html(result.Movies.SelectOptions);
                    if (result.Movies.SelectedValue != '') {
                        $('select.movieId').val(result.Movies.SelectedValue);
                    }
                    $('select.genre').html(result.Genres.SelectOptions);
                    if (result.Genres.SelectedValue != '') {
                        $('select.genre').val(result.Genres.SelectedValue);
                    }
                    $('select.city').html(result.Cities.SelectOptions);
                    if (result.Cities.SelectedValue != '') {
                        $('select.city').val(result.Cities.SelectedValue);
                    }
                }
            });
        };

        this.RepopulateDateMovieCity = function() {
            var queryString = "'genre': '" + genre + "', 'movieId': '" + movie + "', 'date': '" + date + "', 'city': '" + city + "'";
            $.ajax({
                type: "POST",
                url: '/Webservices/FasttrackOptions.asmx/GetDateMovieCity',
                data: '{' + queryString + '}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) {
                    var result = data.d;
                    $('select.date').html(result.Dates.SelectOptions);
                    if (result.Dates.SelectedValue != '') {
                        $('select.date').val(result.Dates.SelectedValue);
                    }
                    $('select.movieId').html(result.Movies.SelectOptions);
                    if (result.Movies.SelectedValue != '') {
                        $('select.movieId').val(result.Movies.SelectedValue);
                    }
                    $('select.city').html(result.Cities.SelectOptions);
                    if (result.Cities.SelectedValue != '') {
                        $('select.city').val(result.Cities.SelectedValue);
                    }
                }
            });
        };

        this.RepopulateDateMovieGenre = function() {
            var queryString = "'genre': '" + genre + "', 'movieId': '" + movie + "', 'date': '" + date + "', 'city': '" + city + "'";
            $.ajax({
                type: "POST",
                url: '/Webservices/FasttrackOptions.asmx/GetDateMovieGenre',
                data: '{' + queryString + '}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) {
                    var result = data.d;
                    $('select.date').html(result.Dates.SelectOptions);
                    if (result.Dates.SelectedValue != '') {
                        $('select.date').val(result.Dates.SelectedValue);
                    }
                    $('select.genre').html(result.Genres.SelectOptions);
                    if (result.Genres.SelectedValue != '') {
                        $('select.genre').val(result.Genres.SelectedValue);
                    }
                    $('select.movieId').html(result.Movies.SelectOptions);
                    if (result.Movies.SelectedValue != '') {
                        $('select.movieId').val(result.Movies.SelectedValue);
                    }
                }
            });
        };

        this.RePopulateDateCity = function() {
            var queryString = "'genre': '" + genre + "', 'movieId': '" + movie + "', 'date': '" + date + "', 'city': '" + city + "'";
            $.ajax({
                type: "POST",
                url: '/Webservices/FasttrackOptions.asmx/GetDateCityCinemas',
                data: '{' + queryString + '}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) {
                    var result = data.d;
                    $('select.date').html(result.Dates.SelectOptions);
                    if (result.Dates.SelectedValue != '') {
                        $('select.date').val(result.Dates.SelectedValue);
                    }
                    $('select.city').html(result.Cities.SelectOptions);
                    if (result.Cities.SelectedValue != '') {
                        $('select.city').val(result.Cities.SelectedValue);
                    }
                    $('select.cinema').html(result.Cinemas.SelectOptions);
                }
            });
        };

        this.MovieChange = function(control) {
            $this.UpdateParameters();
            if (oldMovie == movie) {
                return false;
            }
            $this.ShowGenre(true);
            if (movie != '' && (date != '' && date != 'pick')) {
                $this.RePopulateDateCity();
                $this.ShowGenre(false);
                options.currentPage = 1;
                $this.HistoryLoad(true);
            }
            else if (movie == '' && date != '') {
                $this.RepopulateDateCityGenre();
                options.currentPage = 1;
                $this.HistoryLoad(true);
            }
            else if ((movie != '' && date == '') || date == 'pick') {
                $this.RePopulateDateCity();
                OpenMovieDialog(control);
            }
            else if (oldMovie != '' && movie == '' && oldDate == '') {
                $this.RePopulateDateCity();
                $this.HistoryLoad(true);
            }
            else {
                $this.RepopulateAll();
                options.currentPage = 1;
                $this.HistoryLoad(true);
            }
            this.UpdateHeader(control, $('#movieDialog').find('select.date'));
        };

        this.RePopulateMovie = function() {
            $('select.movieId').populate({
                queryString: "'genre': '" + genre + "', 'movieId': '" + movie + "', 'date': '" + date + "', 'city': '" + city + "'",
                url: '/Webservices/FasttrackOptions.asmx/GetMovies'
            });
        };

        this.RePopulateCity = function() {
            $('select.city').populate({
                queryString: "'genre': '" + genre + "', 'movieId': '" + movie + "', 'date': '" + date + "', 'city': '" + city + "'",
                url: '/Webservices/FasttrackOptions.asmx/GetCities'
            });
        };

        this.RePopulateGenre = function() {
            $('select.genre').populate({
                queryString: "'genre': '" + genre + "', 'movieId': '" + movie + "', 'date': '" + date + "', 'city': '" + city + "'",
                url: '/Webservices/FasttrackOptions.asmx/GetGenres'
            });
        };

        this.DateChange = function(e, control) {
            $this.SynchronizeDateSelectors(e, control);
            CloseMovieDialog();
            $this.UpdateParameters();
            firstDateChange = false;
            $this.ShowGenre(true);
            options.currentPage = 1;
            if (movie != '' && date != '') {
                $this.RepopulateMovieCityGenre();
                $this.ShowGenre(false);
                $this.HistoryLoad(true);
            }
            else if (movie == '' && date != '') {
                $this.RepopulateMovieCityGenre();
                $this.HistoryLoad(true);
            }
            else if (movie != '' && date == '') {
                $this.RepopulateMovieCityGenre();
                OpenMovieDialog($('select.movieId'));
            }
            else {
                $this.RepopulateAll();
                $this.HistoryLoad(true);
            }
            this.UpdateHeader($('select.movieId'), control);
        };

        this.GenreChange = function(control) {
            $this.UpdateParameters();
            if (oldGenre == genre) {
                return false;
            }
            options.currentPage = 1;
            $this.RepopulateDateMovieCity();
            $this.HistoryLoad(true);
        };

        this.CityChange = function() {
            $this.UpdateParameters();
            if (oldCity == city) {
                return false;
            }
            options.currentPage = 1;
            $this.UpdateParameters();
            $this.RepopulateDateMovieGenre();
            $this.HistoryLoad(true);
        };

        this.SynchronizeDateSelectors = function(e, control) {
            e.stopPropagation();
            e.preventDefault();
            var selectedDate = control.val();
            $('select.date').val(selectedDate);
        };

        this.UpdateHeader = function(movie, date) {
            if ((movie.val() == '' && date.val() == '') || date.val() == 'pick') {
                $('.fasttrackheader').html('Hvilken film vil du se? <span class="colorlayout3">' + itemCount + '</span>');
                $('div#currentpickContainer').hide();
                this.ShowGenre(true);
            }
            else if (movie.val() == '' && date.val() != '') {
                $('.fasttrackheader').html('Hvilken film vil du se ' + $('option:selected', date).text());
                $('div#currentpickContainer').find('span#currentmovie').html('');
                $('div#currentpickContainer').find('span#currentdate').html($('option:selected', date).text());
                $('div#currentpickContainer').show();
                this.ShowGenre(true);
            }
            else if (movie.val() != '' && date.val() != '') {
                var link = GetImage(movie.val()).link;
                var movieHtml = movie.find('option:selected').text()
                if (link != '') {
                    movieHtml = '<a href="' + link + '">' + movieHtml + '</a>';
                }
                $('.fasttrackheader').html('Hvor og hvornår vil du se ' + movieHtml + '?');
                $('div#currentpickContainer').find('span#currentmovie').html($('option:selected', movie).text());
                $('div#currentpickContainer').find('span#currentdate').html($($('option:selected', date)[0]).text());
                $('div#currentpickContainer').show();
            }
            else if (movie.val() != '' && date.val() != '') {
                var link = GetImage(movie.val()).link;
                var movieHtml = movie.find('option:selected').text()
                if (link != '') {
                    movieHtml = '<a href="' + link + '">' + movieHtml + '</a>';
                }
                $('.fasttrackheader').html('Hvor og hvornår vil du se ' + movieHtml + '?');
                $('div#currentpickContainer').find('span#currentmovie').html($('option:selected', movie).text());
                $('div#currentpickContainer').find('span#currentdate').html($($('option:selected', date)[0]).text());
                $('div#currentpickContainer').show();
            }
        };

        this.ShowGenre = function(show) {
            if (show) {
                $('#genrePickerContainer').show();
                var link = $('a[id=Cinema]');
                if (link.length == 0) {
                    return;
                }
                link.attr('id', 'Date');
                link.attr('title', 'Premieredato');
                link.attr('href', '#Date');
                link.html('Premieredato');
                link.show();
            }
            else {
                $('#genrePickerContainer').hide();
                var link = $('a[id=Date]');
                if (link.length == 0) {
                    return;
                }
                link.attr('id', 'Cinema');
                link.attr('title', 'Biografby');
                link.attr('href', '#Cinema');
                link.html('Biografby');
                link.show();
            }
        };

        this.UpdateParameters = function() {
            oldCity = city;
            oldDate = date;
            oldGenre = genre;
            oldMovie = movie;
            $.each(options.filters, function(index, value) {
                var control = $(value.control);
                switch (value.name) {
                    case 'genre':
                        genre = control.val();
                        if (genre == null) {
                            genre = '';
                        }
                        break;
                    case 'movieId':
                        movie = control.val();
                        break;
                    case 'date':
                        date = control.val();
                        break;
                    case 'city':
                        city = control.val();
                        break;
                }
            });
        };

        this.UpdateFilter = function(k, v) {
            if (filter.length > 0) {
                filter = $.grep(filter, function(item) {
                    return item.key != k;
                });
            }
            filter.push({ key: k, value: v });
            switch (k.name) {
                case 'movieId':
                    movie = v;
                    $('select.movieId').val(v);
                    break;
                case 'date':
                    date = v;
                    $('select.date').val(v);
                    break;
                case 'city':
                    city = v;
                    $('select.city').val(v);
                    break;
                case 'genre':
                    genre = v;
                    $('select.genre').val(v);
                    break;
            }
        };

        return this.initialize();

    };

})(jQuery);