
var headline_interval;
var bar_left_cur;
var max_left;
var step;
var bar_move = false;

$(document).ready(function(){
    var objs = $('.gallerydiv_inner cadr');
    var cStep = $('#arr_L').parent().get(0).getAttribute('class').indexOf('g_double') >= 0 ? 2 : 1;
    max_left = $(".gallerydiv").width()-$(".gallerydiv_inner div").width()*objs.length+10;
    step = $(".gallerydiv_inner div").width();       
       
    $("#arr_L").bind("mousedown", function(e) {
        var cStep = $('#arr_L').parent().get(0).getAttribute('class').indexOf('g_double') >= 0 ? 2 : 1;
        StartScrollPics(1, cStep);   
        $("body").one("mouseup", function(e) {	
            clearInterval(headline_interval);
            $("body").unbind("mousemove");				
            bar_move = false;
        }); 
				                
        return false;		
    });	
											
    $("#arr_R").bind("mousedown", function(e) {
        var cStep = $('#arr_L').parent().get(0).getAttribute('class').indexOf('g_double') >= 0 ? 2 : 1;
        StartScrollPics(0, cStep); 
        $("body").one("mouseup", function(e) {
            $("body").unbind("mousemove");
            clearInterval(headline_interval);
            bar_move = false;
        }); 
				                
        return false;		
    });
			
			
    $("#arr_R").bind("click", function(e) {
        var cStep = $('#arr_L').parent().get(0).getAttribute('class').indexOf('g_double') >= 0 ? 2 : 1;
        move_content(bar_left_cur - (step * cStep), 600, false);
        return false;
    });
			
    $("#arr_L").bind("click", function(e) {
        var cStep = $('#arr_L').parent().get(0).getAttribute('class').indexOf('g_double') >= 0 ? 2 : 1;
        move_content(bar_left_cur + (step * cStep), 600, false);
        return false;
    });			
});
			
function StartScrollPics(d, cStep)
{   
    bar_move = true;
    var dest = d;     
    bar_left_cur = parseInt($(".gallerydiv_inner").css("left"));

    if(dest == 1)
        move_content(bar_left_cur + (step * cStep), 600, false);
    else				        
        move_content(bar_left_cur - (step * cStep), 600, false);   
             
    clearInterval(headline_interval);       
    headline_interval = setInterval(function(){
        StartScrollPics(dest)
        }, 600);
}

function move_content(left, sec, move)
{
    if (left > 0)
        left = 0;
    else if (left < max_left)
        left = max_left;   
		
    $(".gallerydiv_inner").animate({
        "left": left + "px"
        }, sec, function () {
        bar_move = false;
    });
}


