/* 	news-list-slider */
/*
 * Orginal: http://adomas.org/javascript-mouse-wheel/
 * prototype extension by "Frank Monnerjahn" <themonnie@gmail.com>
 */
Object.extend(Event, {
	wheel:function (event){
		var delta = 0;
		if (!event) event = window.event;
		if (event.wheelDelta) {
			delta = event.wheelDelta/120; 
/* 			if (window.opera) delta = delta;  - Opera 9 fix*/
		} else if (event.detail) { delta = -event.detail/3;	}
		
		return Math.round(delta); //Safari Round
	}
});
/*
 * enf of extension 
 */ 

Slider = new function() {};
(function() {
    var YuiEvent = YAHOO.util.Event,
		Dom = YAHOO.util.Dom,
		lang = YAHOO.lang,
		Anim = YAHOO.util.Anim,
 		bg="news-list-slider-bg", thumb="news-list-slider-thumb", ci="news-list-content-slided",
        valuearea="news-list-slider-value", textfield="news-list-slider-converted-value"

    // The slider can move 0 pixels up
    var topConstraint = 0;

    // The slider can move 200 pixels down
    var bottomConstraint = 250;

    // Custom scale factor for converting the pixel offset into a real value
    var scaleFactor = 1.7;

    // The amount the slider moves when the value is changed with the arrow
    // keys
    var keyIncrement = 20;

    YuiEvent.onDOMReady(function() {

        slider = YAHOO.widget.Slider.getVertSlider(bg,thumb, topConstraint, bottomConstraint);
        slider.getRealValue = function() {
            return Math.round(this.getValue() * scaleFactor);
        }

        slider.subscribe("change", function(offsetFromStart) {
			
			var ci_pos = 0;
			
            var fld = Dom.get(textfield);

            // use the scale factor to convert the pixel offset into a real value
            var actualValue = slider.getRealValue();

            // update the text box with the actual value
            fld.value = actualValue;
			
			// update content-iner position
			var height = Dom.getStyle(ci,"height");
			
			height = parseInt(height.substring(0,height.length-2));
			
			// ie6 and above safty
			if(!height) {
				height = document.getElementById( 'news-list-content-slided' ).offsetHeight;
			}
					
			ci_pos = Math.round(height/bottomConstraint*actualValue/2);
            
			attributes = {
				top: { to: -ci_pos, unit:'px' }
			};
			anim = new Anim(ci, attributes, 0.2, YAHOO.util.Easing.easeOut); 
			anim.animate();
			
			//Dom.setStyle(ci,'top',-ci_pos+'px');
			
			// Update the title attribute on the background.  This helps assistive
            // technology to communicate the state change
            Dom.get(bg).title = "slider value = " + actualValue;
			
        });

        slider.subscribe("slideStart", function() {
			YAHOO.log("slideStart fired", "warn");
		});

        slider.subscribe("slideEnd", function() {
			YAHOO.log("slideEnd fired", "warn");
		});

        // set an initial value
        slider.setValue(0);
		
		function handleDIV(e) {
			slider.setValue(slider.getValue()-(Event.wheel(e)*20));	
		}
			
		Event.observe(document, "mousewheel", handleDIV, false);
		Event.observe(document, "DOMMouseScroll", handleDIV, false); // Firefox
    });
    
})();

YAHOO.util.Event.on("news-list-container", "mouseenter", function (e) {
    //YAHOO.log("Mouse entered: " + this.id);
    //console.log('asdf');
});
 
YAHOO.util.Event.on("news-list-content-slided", "mouseleave", function (e) {
    //YAHOO.log("Mouse left: " + this.id);
    //console.log('qwf');
});

