$(document).ready(function(){
    var WindowHeight=window.innerHeight;
    var windowWidth=window.innerWidth;
    
    $("#win_size").html("<b>"+window.innerWidth+"</b>");
    
    $(window).resize(function(){
        $("#win_size").html("<b>"+window.innerWidth+"</b>");
        WindowHeight=window.innerHeight;
        windowWidth=window.innerWidth;
      
    });
    $(".Hslid-Em1990 > .Hslid-Em1990-SlideBox > table").each(function(){
        $(this).attr("currentScroll",0);
        $(this).parent().scrollLeft(0);
    });
    $(".Hslid-Em1990 > .Hslid-Em1990-SlideBox").scroll(function(){
        var obj=$(this);
        obj.children().filter("table").attr("currentScroll",obj.scrollLeft());
    }); 

    $(".Hslid-Em1990 .Hslid-Em1990-SlideBox td").each(function(){
        $(this).attr("offsetX",$(this).offset().left);
    });

    $(".Hslid-Em1990 .Hslid-Em1990-SlideBox td").click(function(evt){
        if($(evt.target).closest('.detail ').length){
            return false;  
        }
        $(this).siblings().each(function(){
            $(this).removeClass("ElementBox-openMod");
            $(this).children().filter(".Element-det").eq(0).children().filter(".detail").eq(0).removeClass("Element-det-openMod");
        });
        $(this).toggleClass("ElementBox-openMod");
        $(this).find(".detail").toggleClass("Element-det-openMod");
        var elm_Offset=Number($(this).attr("offsetX"));
        var obj=$(this).parents("table");
        obj.parents(".Hslid-Em1990-SlideBox").stop();
        obj.parents(".Hslid-Em1990-SlideBox").animate({scrollLeft:elm_Offset},800,'linear',function(){
            obj.attr("currentScroll",obj.parent().scrollLeft());
        });
        
    });

    $(".Hslid-Em1990>.Buttons button").click(function(){
        var obj=$(this).parent().siblings(".Hslid-Em1990-SlideBox").children().filter("table").eq(0);
        obj.parents(".Hslid-Em1990-SlideBox").stop();
        // alert(obj.html());
        var BoxWidth=obj.parent().width();
        var currentScroll=Number(obj.attr("currentScroll"));
        var minWith=1;
        var jumpNumber=1;
        var jump=obj.attr("Jump");

        // محاسبه ی طول استاندارد المنت ها
        var x1=obj.children().children().children().filter("td").eq(0).outerWidth();
        var x2=obj.children().children().children().filter("td").eq(1).outerWidth();
        minWith=Math.min(x1, x2);
        //---------------------------------------
        if(jump=="max"){
            
            jumpNumber=Math.floor(BoxWidth/minWith);
            if(jumpNumber<1){jumpNumber=1;}
            
        }else{
            jumpNumber=Number(jump);
            if(jumpNumber<1){jumpNumber=1;}
        }
        if($(this).hasClass("next")){
            obj.parents(".Hslid-Em1990-SlideBox").animate({scrollLeft:currentScroll+(jumpNumber*minWith)},1000,'linear',function(){
                obj.attr("currentScroll",obj.parent().scrollLeft());
            });
        }else{
            obj.parents(".Hslid-Em1990-SlideBox").animate({scrollLeft:currentScroll-(jumpNumber*minWith)},1000,'linear',function(){
                obj.attr("currentScroll",obj.parent().scrollLeft());
            });
        }
        
    });
    /*$('html').click(function(evt){       // this func is for change the display of menu-btn to none if user click anywhere else of menu-btn  
        // if(evt.target.class == ".menu-btn")
        //     return;
         //For descendants of .menu-btn being clicked, remove this check if you do not want to put constraint on descendants.
         if($(evt.target).closest('.Element-det ').length){
             return false;  
         }
         //Do processing of click event here for every element except with class .menu-btn
         $(".Hslid-Em1990  .Hslid-Em1990-SlideBox  table  td ").each(function(){
            $(this).removeClass("ElementBox-openMod");
            $(this).children().filter(".Element-det").eq(0).children().filter(".detail").eq(0).removeClass("Element-det-openMod");
        });
     });*/

    var prevScrollpos = window.pageYOffset;
    $(window).scroll(function(){
        
    });
});


