
$('ul#coverflow').jcoverflip({

            beforeCss: function(el, container, offset) {

                return [

              $.jcoverflip.animationElement(el, { left: (container.width() / 2 - (345+(offset*50))) + 'px', bottom: 0 }, { 0: { 'z-index': 100 - offset} })
            ];
            },
            afterCss: function(el, container, offset) {
                return [

              $.jcoverflip.animationElement(el, { left: (((container.width() / 2)-175) + (offset*50)) + 'px', bottom: 0 }, { 0: { 'z-index': 100 - offset} })
              
            ];
            },
            currentCss: function(el, container) {
                return [
              $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 260) + 'px', bottom: 0 }, { 0: { 'z-index': 101} })
            ];
            },
            current: 3
        });

$('ul#coverflow img.bgimgpreload').load(function(){ 
        $(this).parent('li').css('background','url('+ $(this).attr('src') + ')0 0 no-repeat'); 
        $(this).parent('li').find('.item_text').show();
});


     
        var touch = {};
        var endtouch = {};
        function touchstart(elt, e) {

            var t = e.touches[0];
            touch.x = t.clientX;
            touch.y = t.clientY;
            console.log("touchstart:"+touch.x +":"+touch.y);
            endtouch={}; //reinitialize endtouch;
        }

        function touchmove(elt, e) {

            // only deal with one finger
            if (e.touches.length == 1 && !$(elt).is(":animated")) {
                var t = e.touches[0];
                endtouch.x = t.clientX;
                endtouch.y = t.clientY;
            
                var deltaX = touch.x - endtouch.x,
                deltaY = touch.y - endtouch.y;

                if (Math.abs(deltaX) / Math.abs(deltaY) > 1.0) {
                    e.preventDefault();
                }
            }
        }
        function touchend(elt, e) {

            if (endtouch != {})
            {
                var deltaX = touch.x - endtouch.x,
                    deltaY = touch.y - endtouch.y;

                console.log("touchend:"+endtouch.x +":"+endtouch.y); 
                console.log("delta:"+deltaX +":"+deltaY);    
            
                if (Math.abs(deltaX) / Math.abs(deltaY) > 1.0) {
                
                
                    if ((deltaX) > 0)
                    {
                     
                     if ($(elt).jcoverflip('current') < $(elt).jcoverflip('length')-1){
                        $(elt).jcoverflip("next");
                     }
                  }
                  else{
                     if ($(elt).jcoverflip('current') >0){
                          $(elt).jcoverflip("previous");
                        }
                 }
              }
           }
        }
