﻿function mycarousel_initCallback2(carousel) {

    jQuery('.jcarousel-control-' + $(carousel).attr("id") + ' a').bind('click', function() {
        Curr = (jQuery.jcarousel.intval(jQuery(this).text()) - 1) * parseInt(carousel.options.scroll) + 1;
        carousel.scroll(Curr);
        return false;
    });

    jQuery('#mycarouselnext' + $(carousel).attr("id")).bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarouselprev' + $(carousel).attr("id")).bind('click', function() {
        carousel.prev();
        return false;
    });

//    jQuery('.addtocart' + $(carousel).attr("id")).bind('click', function() {

//        el_ = document.getElementById(this.id);

//        var scriptMethod = "Services/StoreService.asmx/AddToCart_";       
//        // "http://localhost/BreslovWorld/test.aspx/AddToCart"
//        // "Services/StoreService.asmx/AddToCart"

//        var parameters = "{'args':'" + $(el_).attr("args") + "'}"; // "{}";//
//        //"{'sDate':'" + sDate + "','eDate':'" + eDate + "'}"

//        $.ajax({
//            type: "POST",
//            url: scriptMethod,
//            data: parameters,
//            contentType: "application/json; charset=utf-8",
//            dataType: "json",
//            timeout: 10000,
//            success: function(result) {
//                Success(result);
//                //document.location.href = url;
//            },
//            error: Failed
//        });

//    });

    function Success(result) {
        ///! alert(result);
    }
    
    function Failed(result) {
        ///! alert(result.status + " " + result.responseText); // readyState, responseText, responseXML, status, statusText
    }        

//    jQuery('.addtocart' + $(carousel).attr("id")).click(function() {
//        alert(this.id);
//    });
    
//  $('#' +$(carousel).attr("id") + '.jcarousel-skin-ie7 li').css('display', 'none');
//  $('.jcarousel-clip-horizontal').css('width', $(carousel).attr("width") + 'px');

}

function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
    
    id_ = "sp" + $(carousel).attr("id");

    try {

        img1 = $('#' + id_).find('#img' + $(carousel).attr("id") + '_1');
        img2 = $('#' + id_).find('#img' + $(carousel).attr("id") + '_2');
        img3 = $('#' + id_).find('#img' + $(carousel).attr("id") + '_3');

        $(img1).attr('src', 'App_Themes/Theme1/images/modules/circle_b.gif');
        $(img2).attr('src', 'App_Themes/Theme1/images/modules/circle_b.gif');
        $(img3).attr('src', 'App_Themes/Theme1/images/modules/circle_b.gif');

    } catch (e) { }

    //alert(carousel.options.scroll);
    //alert(carousel.options.total);

    //alert(idx);
    //alert(carousel.options.scroll);

    //--- change curr circle
    if (carousel.options.scroll == 1) {
        Curr = parseInt(idx / parseInt(carousel.options.scroll));
    }
    else {
        Curr = parseInt(idx / parseInt(carousel.options.scroll)) + 1;
    }

    //alert(carousel.options.scroll);
    //alert(Curr);

    try {
        img_ = $('#' + id_).find('#img' + $(carousel).attr("id") + '_' + Curr);
        $(img_).attr('src', 'App_Themes/Theme1/images/modules/circle_a.gif');
    } catch (e) { }

    //--- disable buttons
    if (idx == 1) {
        //$('#imgPrev' + $(carousel).attr("id")).css({ opacity: 0.5 });

        //$('#imgPrev' + $(carousel).attr("id")).attr("style", "display:none;");
        $('#imgPrev' + $(carousel).attr("id")).attr("disabled", "true");
        
        $('#imgPrev' + $(carousel).attr("id")).css("cursor", "default");
        $('#imgPrev' + $(carousel).attr("id")).pixastic("desaturate");
    } else {

    //$('#imgPrev' + $(carousel).attr("id")).css({ opacity: 1 });

        //$('#imgPrev' + $(carousel).attr("id")).attr("style", "display:; border:0;");
        $('#imgPrev' + $(carousel).attr("id")).removeAttr("disabled");
        
        //$('#imgPrev' + $(carousel).attr("id")).css('cursor', '"hand');
        //$('#imgPrev' + $(carousel).attr("id")).css('cursor', 'pointer');
        Pixastic.revert(document.getElementById('imgPrev' + $(carousel).attr("id")));

        $('#imgPrev' + $(carousel).attr("id")).hover(function() {
            $(this).css('cursor', 'pointer');
        }, function() {
            $(this).css('cursor', 'auto');
        });

    }

    if (carousel.options.scroll == 1) {

        if (idx == 3) { //3
            //$('#imgNext' + $(carousel).attr("id")).css({ opacity: 0.5 });

            //$('#imgNext' + $(carousel).attr("id")).attr("style", "display:none;");
            $('#imgNext' + $(carousel).attr("id")).attr("disabled", "true");
            
            $('#imgNext' + $(carousel).attr("id")).css("cursor", "default");
            $('#imgNext' + $(carousel).attr("id")).pixastic("desaturate");
        } else {

            //$('#imgNext' + $(carousel).attr("id")).css({ opacity: 1 });

            //$('#imgNext' + $(carousel).attr("id")).attr("style", "display:; border:0;");
            $('#imgNext' + $(carousel).attr("id")).removeAttr("disabled");
            
            //$('#imgNext' + $(carousel).attr("id")).css("cursor", "pointer");
            //$('#imgNext' + $(carousel).attr("id")).css("cursor", "hand");
            Pixastic.revert(document.getElementById('imgNext' + $(carousel).attr("id")));

            $('#imgNext' + $(carousel).attr("id")).hover(function() {
                $(this).css('cursor', 'pointer');
            }, function() {
                $(this).css('cursor', 'auto');
            });

        }

    } else {

        if (Curr == 3) { //3
            //$('#imgNext' + $(carousel).attr("id")).css({ opacity: 0.5 });

            //$('#imgNext' + $(carousel).attr("id")).attr("style", "display:none;");
            $('#imgNext' + $(carousel).attr("id")).attr("disabled", "true");
            
            $('#imgNext' + $(carousel).attr("id")).css("cursor", "default");
            $('#imgNext' + $(carousel).attr("id")).pixastic("desaturate");
        } else {

            //$('#imgNext' + $(carousel).attr("id")).css({ opacity: 1 });

            //$('#imgNext' + $(carousel).attr("id")).attr("style", "display:; border:0;");
            $('#imgNext' + $(carousel).attr("id")).removeAttr("disabled");
            
            //$('#imgNext' + $(carousel).attr("id")).css("cursor", "pointer");
            //$('#imgNext' + $(carousel).attr("id")).css("cursor", "hand");
            Pixastic.revert(document.getElementById('imgNext' + $(carousel).attr("id")));

            $('#imgNext' + $(carousel).attr("id")).hover(function() {
                $(this).css('cursor', 'pointer');
            }, function() {
                $(this).css('cursor', 'auto');
            });

        }

    }

    //--- start auto scroll
//    var delay = function() { startCarousel(carousel); }; // carousel.scroll(1);

//    if (carousel.options.auto > 0 && Curr == 3) { //3
//        var t = setTimeout(delay, carousel.options.auto * 1000);
//    }

}

//function startCarousel(carousel) {
//    carousel.scroll(1);
//}

function mycarousel_itemVisibleOutCallbackBeforeAnimation(carousel, item, idx, state) {
}    
