/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



$(function() {
    if ($('.category').length > 0) {
        var gallery=window

        
        function scrollGallery(e){
        
            direction = 0;
            var evt=window.event || e //equalize event object
            var delta=evt.detail? evt.detail*(-120) : evt.wheelDelta //delta returns +120 when wheel is scrolled up, -120 when scrolled down
            direction=(delta<=-120)? direction+1 : direction-1 //move image index forward or back, depending on whether wheel is scrolled down or up
            //direction=(direction<0)? -1 : (1)? 0 : direction //wrap image index around when it goes beyond lower and upper boundaries
            if (direction == 1) {
                $('html,body').stop().animate({
                    scrollLeft: '+=250'
                },200, 'easeInOutQuad')
            //$(window).scrollLeft($(window).scrollLeft() +120) 
            }
                
            else {
                $('html,body').stop().animate({
                    scrollLeft: '-=250'
                },200, 'easeInOutQuad')
            //$(window).scrollLeft($(window).scrollLeft() -120) 
            }
          
            
            //console.log( direction )
            //slideshow.src=myimages[nextslideindex]
            if (evt.preventDefault) //disable default wheel action of scrolling page
                evt.preventDefault()
            else
                return false
 
        }
 
        var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel" //FF doesn't recognize mousewheel as of FF3.x
 
        if (gallery.attachEvent) //if IE (and Opera depending on user setting)
            gallery.attachEvent("on"+mousewheelevt, scrollGallery)
        else if (gallery.addEventListener) //WC3 browsers
            gallery.addEventListener(mousewheelevt, scrollGallery, false)
    }
    
    
    $('.cls-table-gallery img').click(function() {
        $('html,body').animate({
            scrollLeft: $(this).parent().parent().next().offset().left - 390
        },500, 'easeInOutQuad')
       
    //console.log ($(this).parent().parent().next().offset().left);
    //$(window).animate({'scrollLeft' :$(this).parent().parent().next().offset().left - 382},1000, 'easeInOutQuad')
    //$(window).animate('scrollLeft', $(this).parent().parent().next().offset().left - 382)

    })
});
