$(document).ready(function() {
    $(".autofill").focus(
                        function () {
                            $(this).addClass("active");
                            if ($(this).val() == $(this).attr('title')) $(this).val('');
                        }
            );

    $(".autofill").blur(
                       function () {
                           if ($(this).val() == '') {
                               $(this).val($(this).attr('title'));
                               $(this).removeClass("active");
                           }
                       }
            );

    $("#intro").jcarousel({
        scroll: 1,
        auto:10,
        animation: 1000,
        wrap: 'circular',
        buttonNextHTML:null,
        buttonPrevHTML:null,
        initCallback: mycarousel_initCallback,
        itemVisibleInCallback:  highlight,
        itemVisibleOutCallback: removehighlight


    });

        $(".lnk-sizes").click(
                       function () {

                       }
            );



});

function open_window(link, w, h) {

    var win = "width=" + w + ",height=" + h
            + ",menubar=no,location=no,resizable=yes,scrollbars=yes";
    var newWin = window.open(link, 'newWin', win);
    if (newWin) {
        newWin.focus();
    }
    return newWin;
}


function mycarousel_initCallback(carousel) {

    carousel.clip.prepend('<div class="jcarousel-control"></div>');
    carousel.clip.find('.jcarousel-list li').each(function(){

          carousel.clip.find('.jcarousel-control').append('<a href="#" rel="'+$(this).attr('jcarouselindex')+'">'+$(this).attr('jcarouselindex')+'</a>');
    });

    jQuery('.jcarousel-control a').bind('click', function() {

        carousel.scroll($.jcarousel.intval($(this).attr('rel')));
        //carousel.stopAuto();
        return false;
    });
    carousel.clip.bind('mouseleave', function() {

        carousel.next();
        carousel.startAuto();
        return false;
    });
    carousel.clip.bind('mouseenter', function() {

        carousel.stopAuto();
        return false;
    });
    // Pause autoscrolling if the user moves with the cursor over the clip.
    /*
    carousel.clip.hover(function() {

        //carousel.stopAuto();
    }, function() {
        //carousel.startAuto();
        carousel.next();

    });

        jQuery('.jcarousel-control').hover(function() {
        //carousel.stopAuto();
    }, function() {
          //carousel.startAuto();

    });  */



};

function highlight(carousel, obejctli,liindex,listate){
            var len  = $('.jcarousel-control a').length;
        //alert('0:'+ idx%len + ' 1:' + idx/len + ' 2:' + Math.floor(idx/len)+ ' 3:' + (Math.floor(idx/len) * len));
        var tmp= liindex%len;
        if (tmp == 0)
        tmp= len;
      //  alert(' highlight '+liindex);
     //$('.b-i1').text('highlight '+liindex + ' tmp' + tmp);
     jQuery('.jcarousel-control a:nth-child('+ tmp +')').attr("class","active");
};
// it will remove last selected slide from <a>
// <a href="#" class="selected">1</a> to <a href="#">1</a>
function removehighlight(carousel, obejctli,liindex,listate){
                var len  = $('.jcarousel-control a').length;
        //alert('0:'+ idx%len + ' 1:' + idx/len + ' 2:' + Math.floor(idx/len)+ ' 3:' + (Math.floor(idx/len) * len));
        var tmp= liindex%len;
        if (tmp == 0)
        tmp= len;
   // alert(' removehighlight '+liindex);
   // $('.b-i2').text('removehighlight '+liindex + ' tmp' + tmp);
     jQuery('.jcarousel-control a:nth-child('+ tmp +')').removeAttr("class","active");
};

