/*SLIDESHOW*/

var play_slideshow = 1;
var play = 1;
var way = 1;

function slideShow() {
    
    movewidth = 168;//Ennyivel mozdul arrébb az egész cumó
    
    var slideshow_products_length = $('.slideshow_products').length;
    slideshow_products_box_new_width = (slideshow_products_length * 170);
    $('#slideshow_products_box').css('width',slideshow_products_box_new_width);
    
    //Auto slide
    setTimeout("autoslide("+movewidth+","+slideshow_products_box_new_width+")",2000);
    
    //Other over
    $('#slideshow_bg').mouseover(function() {
        play = 0;
    });
    $('#slideshow_shadows').mouseover(function() {
        play = 0;
    });
    $('#slideshow_products_box').mouseover(function() {
        play = 0;
    });
    $('.slideshow_products').mouseover(function() {
        play = 0;
    });
    $('.slideshow_products').children().mouseover(function() {
        play = 0;
    });
    
    //Left button    
    $('#slideshow_left_button_hover').mouseover(function() {
        $('#slideshow_left_button_hover').stop();
        $('#slideshow_left_button_hover').fadeTo('normal', 1); 
        play = 0;
    });
    $('#slideshow_left_button_hover').mouseout(function() {
        $('#slideshow_left_button_hover').stop();
        $('#slideshow_left_button_hover').fadeTo('normal', 0);  
    });
    $('#slideshow_left_button_hover').click(function() {
        $('#slideshow_products_box').stop();
        slideshow_bg_offset = $('#slideshow_bg').offset();
        slideshow_products_box_offset = $('#slideshow_products_box').offset();
        if ( (slideshow_products_box_offset.left + movewidth) > (slideshow_bg_offset.left + 10) ) {
            newmovewidth = slideshow_products_box_offset.left - slideshow_bg_offset.left; 
            $('#slideshow_products_box').animate({'marginLeft' : "-="+newmovewidth+"px"}, 1000);
        } else {
            $('#slideshow_products_box').animate({'marginLeft' : "+="+movewidth+"px"}, 1000);
        }
        play = 0;
        way = 0;
    });
    //Right button
    $('#slideshow_right_button_hover').mouseover(function() {
        $('#slideshow_right_button_hover').stop();
        $('#slideshow_right_button_hover').fadeTo('normal', 1); 
        play = 0;
    });
    $('#slideshow_right_button_hover').mouseout(function() {
        $('#slideshow_right_button_hover').stop();
        $('#slideshow_right_button_hover').fadeTo('normal', 0);  
    });
    $('#slideshow_right_button_hover').click(function() {
        $('#slideshow_products_box').stop();
        slideshow_bg_offset = $('#slideshow_bg').offset();
        slideshow_products_box_offset = $('#slideshow_products_box').offset();
        if ( ((slideshow_products_box_offset.left + slideshow_products_box_new_width) - movewidth) < ((slideshow_bg_offset.left + 516) - 10 )) {
            newmovewidth = (slideshow_products_box_offset.left + slideshow_products_box_new_width) - (slideshow_bg_offset.left + 516);
            $('#slideshow_products_box').animate({'marginLeft' : "-="+newmovewidth+"px"}, 1000);
        } else {
            $('#slideshow_products_box').animate({'marginLeft' : "-="+movewidth+"px"}, 1000);
        }
        play = 0;
        way = 1;
    }); 
}

function autoslide(movewidth, slideshow_products_box_new_width) {
    if (play == 1 && play_slideshow == 1) {  
        //way == 0 - left <-; 1- right ->
        if (way == 0) {
            $('#slideshow_left_button_hover').fadeTo('slow', 1);
            slideshow_bg_offset = $('#slideshow_bg').offset();
            slideshow_products_box_offset = $('#slideshow_products_box').offset();
            if ( (slideshow_products_box_offset.left + movewidth) > (slideshow_bg_offset.left + 10) ) {
                newmovewidth = slideshow_products_box_offset.left - slideshow_bg_offset.left; 
                $('#slideshow_products_box').animate({'marginLeft' : "-="+newmovewidth+"px"}, 1000);
            } else {
                $('#slideshow_products_box').animate({'marginLeft' : "+="+movewidth+"px"}, 1000);
            }
            if ((slideshow_products_box_offset.left) == (slideshow_bg_offset.left)) {
                way = 1;
            }
            $('#slideshow_left_button_hover').fadeTo('slow', 0);
            setTimeout("autoslide("+movewidth+","+slideshow_products_box_new_width+")",1800); 
        } else {
            $('#slideshow_right_button_hover').fadeTo('slow', 1);
            slideshow_bg_offset = $('#slideshow_bg').offset();
            slideshow_products_box_offset = $('#slideshow_products_box').offset();
            if ( ((slideshow_products_box_offset.left + slideshow_products_box_new_width) - movewidth) < ((slideshow_bg_offset.left + 516) - 10 )) {
                newmovewidth = (slideshow_products_box_offset.left + slideshow_products_box_new_width) - (slideshow_bg_offset.left + 516);
                $('#slideshow_products_box').animate({'marginLeft' : "-="+newmovewidth+"px"}, 1000);
            } else {
                $('#slideshow_products_box').animate({'marginLeft' : "-="+movewidth+"px"}, 1000);
            } 
            if( ((slideshow_products_box_offset.left + slideshow_products_box_new_width) == (slideshow_bg_offset.left  + 516)) ){
                way = 0;    
            }
            $('#slideshow_right_button_hover').fadeTo('slow', 0);
            setTimeout("autoslide("+movewidth+","+slideshow_products_box_new_width+")",1800);
        }
    } else {
        if (play_slideshow == 1) {
            clearTimeout(0);
            play = 1;
            setTimeout("autoslide("+movewidth+","+slideshow_products_box_new_width+")",8000);   
        }
    }
}  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
        
