﻿//Site wide JS
/// <reference path="~/Scripts/jquery-1.3.2-vsdoc.js" />


$(document).ready(function(){
  $('#nav_menu_dropdown').change(function(){
    location.href = '/Categories/List/' + $(this).find('option:selected').val();
  });
});

//Movies drop down
$(document).ready(function() {
    $('a.moviesDDLLink').parents('li').hover(
			    function() { $('#moviesDDL').css('display', 'block'); },
			    function() { $('#moviesDDL').css('display', 'none'); });

    $('#moviesDDL').hover(
			    function() { $('#moviesDDL').css('display', 'block'); },
			    function() { $('#moviesDDL').css('display', 'none'); });
});



//--------------------------------------------------
// AllMoviesHorizontal  class

var AllMovies = function(containerId) {
    var CONTENT_ITEM_WIDTH = 180;
    var STRIP_WIDTH = 3;
    var container = $('#' + containerId);
    var scrollButtons = container.find('.ScrollArrow');
    var locked = false;

    scrollButtons.click(function() { pageHorizontalScroller($(this)) });

    showhideArrows(container);

    function pageHorizontalScroller(ele) {
        var contentStrip = ele.parents('.content').find('.scrollPanel');
        if (locked)
            return;
        if (ele.hasClass('ScrollRightArrow')) {
            if (canScrollRight(contentStrip, contentStrip.find('.tile').length)) {
                locked = true;
                contentStrip.animate({ left: parseInt(contentStrip.css("left")) - (STRIP_WIDTH * CONTENT_ITEM_WIDTH) }, 500, function() { showhideArrows(container) });
            }
        }
        else if (ele.hasClass('ScrollLeftArrow')) {
            if (canScrollLeft(contentStrip)) {
                locked = true;
                contentStrip.animate({ left: parseInt(contentStrip.css("left")) + (STRIP_WIDTH * CONTENT_ITEM_WIDTH) }, 500, function() { showhideArrows(container) });
            }
        }
    };

    function showhideArrows(tabContainer) {
        var items = tabContainer.find('.tile').length;
        var leftArrow = tabContainer.find('.ScrollLeftArrow');
        var contentStrip = tabContainer.find('.scrollPanel');
        /*
        if (canScrollLeft(contentStrip))
        leftArrow.css("visibility", "visible");
        else
        leftArrow.css("visibility", "hidden");

        var rightArrow = tabContainer.find('.ScrollRightArrow');
        if (canScrollRight(contentStrip, items))
        rightArrow.css("visibility", "visible");
        else
        rightArrow.css("visibility", "hidden");
        */
        locked = false;

    };

    function canScrollRight(contentStrip, totalItems) {
        return (totalItems > 0) && totalItems - getCurrentItem(contentStrip) > STRIP_WIDTH;
    };

    function canScrollLeft(contentStrip) {
        return getCurrentItem(contentStrip) > 0;
    };

    function getCurrentItem(contentStrip) {
        return Math.abs(parseInt(contentStrip.css("left")) / CONTENT_ITEM_WIDTH);
    };

    function getId(ele) {
        var numberRegexp = /\d+$/
        return parseInt(ele.attr("id").match(numberRegexp));
    }

}


