﻿$(document).ready(function () {
    function isMobile() {
        var index = navigator.appVersion.indexOf("Mobile");
        return (index > -1);
    }



    // top navgation
    $('ul.navagition li').hover(
        function () {
            $(this).children('div.nav-drop').slideDown('fast');
        },
        function () {
            $(this).children('div.nav-drop').hide();
        });

    // category item rollover
    $('div.category-items div.item').hover(
        function () {
            $(this).children('div.item-img').children('a').children('img').animate({ width: '203px' }, 100);
        },
        function () {
            $(this).children('div.item-img').children('a').children('img').animate({ width: '197px' }, 100);
        });

    // save gal info
    $('div.category-items div.item a, a.info-nav').click(function () {
        var m_referUrl = $(this).attr('href');
        if ($('input#listInfoSes').length > 0) {
            $.get("/_Methods/ModulesMethods.aspx?method=SaveListInfo", { o_info: $('input#listInfoSes').val() }, function (response) {
                window.location = m_referUrl;
            });
            return false;
        }
    });

    // product images click
    $('div.small-images a').click(function () {
        var m_bimg = $(this).attr('href');
        if (m_bimg != '#') {
            $('div.big-img').html('<a href="' + m_bimg + '" class="zoom-img"><img src="' + $(this).attr('rel') + '" /></a>');
            $('div.big-img a.zoom-img').jqzoom({ zoomType: 'reverse' });
        }
        else {
            $('div.big-img').html('<img src="' + $(this).attr('rel') + '" /> ');
        }
        return false;
    });

    $("a.popup").click(function () {
        url = $(this).attr("href");
        window.open(url, "", "width=600,height=300");
        return false;
    });


    // collection courosl
    // product curosal
    var listMoves;
    var listIndexMove = 1;
    var listItemWidth;
    var run = false;
    // show backstage
    $('a#show-backstage').click(function () {
        if (listIndexMove != listMoves) {
            movesToGo = listMoves - listIndexMove;
            right = parseInt($('div.colc-gallery-items ul').css('left'));
            right = right - (listItemWidth * movesToGo);
            //$('div.colc-gallery-items ul').css('left', right + 'px');
            run = true;
            $('div.colc-gallery-items ul').animate({ left: right + 'px' }, 1000, function () {
                run = false;
            });

            listIndexMove = listMoves;
        }
    });
    // count sum moves
    if ($('div.colc-gallery-items').length > 0) {
        $('div.colc-gallery').prepend('<img class="misgart" src="/_Images/gallery-misgart.png" />');
        $('div.colc-gallery').prepend('<a class="but-next">הבא</a>');
        $('div.colc-gallery').prepend('<a class="but-prev">הקודם</a>');
        listItems = $('div.colc-gallery-items').children('ul').children('li').length;
        itemPerMove = parseInt($('input#list-item-count').val());
        listMoves = parseInt(listItems / itemPerMove);
        listWidth = listItems * 380;
        $('div.colc-gallery-items ul').css('width', listWidth);
        listItemWidth = parseInt($('input#list-item-width').val());
    }
    // relative product curosel
    $('div.colc-gallery a.but-next').click(function () {
        if (listIndexMove < listMoves && !run) {
            right = parseInt($('div.colc-gallery-items ul').css('left'));
            right = right - listItemWidth;
            //$('div.colc-gallery-items ul').css('left', right + 'px');
            run = true;
            $('div.colc-gallery-items ul').animate({ left: right + 'px' }, 1000, function () {
                run = false;
            });

            listIndexMove++;
        }
    });

    $('div.colc-gallery a.but-prev').click(function () {
        if (listIndexMove > 1 && !run) {
            right = parseInt($('div.colc-gallery-items ul').css('left'));
            right = right + listItemWidth;
            //$('div.colc-gallery-items ul').css('left', right + 'px');
            run = true;
            $('div.colc-gallery-items ul').animate({ left: right + 'px' }, 1000, function () {
                run = false;
            });
            listIndexMove--;
        }
    });
});
