var slider_w;
var width_w;

document.observe("dom:loaded", function() {   
    width_w = ($('info_recommend_con').scrollWidth - $('info_recommend_con').offsetWidth);
    //if no width set width to 1 to avoid JS error
    if(width_w == 0)
    {
        width_w = 1
    }
    
    slider_w = new Control.Slider('reco_bar', 'reco_track', {
        range: $R(0, width_w),
        onSlide: function(v) { scrollHorizontal(v, $('info_recommend_con'), slider_w);  },
        onChange: function(v) { scrollHorizontal(v, $('info_recommend_con'), slider_w); }
    });

    //if slider not needed hide it, else create it
    if ($('info_recommend_con').scrollWidth <= $('info_recommend_con').offsetWidth) {
        slider_w.setDisabled();
        $('reco_wrap').hide();
    }
    
    Event.observe('info_recommend_con', 'DOMMouseScroll', wheel_w); // mozilla
    Event.observe('info_recommend_con', 'mousewheel', wheel_w); // IE/Opera
});


//mouse scrolling right
function handle_w(delta) {
	slider_w.setValueBy(-delta);
}

function wheel_w(event){
	var delta = 0;
	if (!event)
		event = window.event;
	if (event.wheelDelta) { // IE Opera
		delta = event.wheelDelta/6;
	} else if (event.detail) { // Mozilla
		delta = -event.detail*2;
	}
	if (delta)
		handle_w(delta);

	if (event.preventDefault)
		event.preventDefault();
	
	event.returnValue = false;
}
