﻿$(function () {

    var currentView = 0;
    var contentListItems = $('#contentListingItems');


    $('.subNavLeftNav').click(function () {
        var thisIndex = $(this).index();
        var diff = (thisIndex - currentView);
        var moveDist = (diff * 860);
        contentListItems.animate({ left: '-=' + moveDist + 'px' }, 1200, 'swing');
        currentView = thisIndex;
        setSubColor();
    });


    
    function setSubColor() {
        $('.subNavLeftNav').attr('style', '');
        $('.subNavLeftNav').eq(currentView).attr('style', 'color:#CFB52B');
    };

    setSubColor();


    //IMPORTANT START POSITION OF SCROLLER
    contentListItems.offset({ top: 0, left: 180 });

    //PREVIOUS CLICK
    function prevMove() {
        if (!currentView == 0) {
            currentView--;
            contentListItems.animate({ left: '+=860px' }, 1200, 'swing', function () {
                setSubColor();
            });
        };
    };

    //NEXT CLICK
    function nextMove() {
        currentView++;
        if (currentView < $('ul#contentListingItems li').size()) {
            contentListItems.animate({ left: '-=860px' }, 1200, 'swing', function () {
                setSubColor();
            });
        };
    };


    $('.prev').live('click', function () {
        prevMove();
        return false;
    });

//    $('ul#contentListingItems li').swipe({
//        threshold: {
//            x: 150,
//            y: 100
//        },
//        swipeLeft: function () { nextMove(); },
//        swipeRight: function () { prevMove(); }
//    });

    $('.next').live('click', function () {
        nextMove();
        return false;
    });

    $(document).keydown(function (e) {
        if (e.keyCode == 37 || e.keyCode == 38 || e.keyCode == 39 || e.keyCode == 40) {
            return false;
        }
    });
   





    $('ul#contentListingItems li').last().find('.prevNextBlog').html('<a class="prev" href="">Prev</a>');
    $('ul#contentListingItems li').first().find('.prevNextBlog').html('<div style="position:relative"><a class="next" href="" style="position:absolute; left:-140px" ><img src="images/arrowRedRight.png" /></a><a class="next" href="">Next</a></div>');

    //UL WIDTH
    $('ul#contentListingItems li').each(function (i) {
        if (i > 0) {
            contentListItems.width(contentListItems.width() + $(this).outerWidth(true));
        };
    });

    //TABS
    contentListItems.children('li').each(function () {
        $(this).find('.isShow').eq(0).show();
    });

    $('.isShowClick').click(function () {
        $(this).parent('td').children('a').each(function () {
            $(this).removeClass('activeNumber').removeClass('isShowClick').addClass('isShowClick');
        });
        $(this).removeClass('isShowClick').addClass('activeNumber');
        $(this).parent('td').parent('tr').parent('tbody').parent('table').next('div').children('.thisContent').children('.isShow').hide();
        $('#' + $(this).attr('href')).show();
        return false;
    });

    $('.itemSingleCases').each(function () {
        $(this).children('a').eq(0).removeClass('isShowClick').addClass('activeNumber');
    });


});
