(function() {
    var Event = YAHOO.util.Event,
        Dom   = YAHOO.util.Dom,
        lang  = YAHOO.lang,
        slider, 
        bg="track", thumb="dragBar";

    // The slider can move 0 pixels up
    var topConstraint = 0;

    // The slider can move 241 pixels down
    var bottomConstraint = 250;
	
	var visibleArea = 250;

    // Custom scale factor for converting the pixel offset into a real value
    var scaleFactor = 1.5;

    // The amount the slider moves when the value is changed with the arrow
    // keys
    var keyIncrement = 20;

	var flashAnchor = "flashScreen";

    Event.onDOMReady(function() {

		allArea = Dom.getRegion("paper").bottom-Dom.getRegion("paper").top;
		
		dragBarHeight = (visibleArea/allArea) * bottomConstraint;
		
		Dom.setStyle  ( "dragBar" , "height" , dragBarHeight+"px" );
		
		/* real */
		bottomConstraint = bottomConstraint - dragBarHeight;
		
		scaleFactor = ((allArea-visibleArea)/bottomConstraint)/1;


        slider = YAHOO.widget.Slider.getVertSlider(bg, thumb, topConstraint, bottomConstraint);

        slider.getRealValue = function() {
			value = this.getValue();
			if (YAHOO.env.ua.opera)
			{
				value = value-777;
			}
            return Math.round(value * scaleFactor);
        }

        slider.subscribe("change", function(offsetFromStart) {

		    var actualValue = slider.getRealValue();

			Dom.setStyle  ( "paper" , "margin-top" ,"-"+actualValue+"px" );
        });
		

		 Event.on("scrollUp","mousedown",function(e) {
		 	var value = slider.getValue();
			slider.setValue(value-keyIncrement*4);
		 });
		 
		 Event.on("scrollBottom","mousedown",function(e) {
		 	var value = slider.getValue();
			slider.setValue(value+keyIncrement*4);
		 });
	
		 /* add to thumbnails connection to flash, animation scrolling to anchor*/
		 
		anchorXY = Dom.getXY(flashAnchor);
		thumbnails = Dom.getElementsByClassName( "bace-gallery-thumbnails-holder-element" , "div" , "paper");
		 
		
		var attributes = {scroll:{to:anchorXY}};
		var anim = new YAHOO.util.Scroll('html', attributes,1,YAHOO.util.Easing.easeOut);
		 
		Event.on(thumbnails,"click",function(e){
			
			var name = "flashGallerySwf";
			
			var M$ =  navigator.appName.indexOf("Microsoft")!=-1
	        movie = (M$ ? window : document)[name];
			
			if (this.title) 
			{
				movie.showSlide(this.title);
			}
			if (YAHOO.env.ua.ie != 6) 
			{
				anim.animate();
				opacityAnim.animate();
			}
			else
			{
				location.href = "#flashScreen"
			}
		});

		Event.on(thumbnails,"mouseover",function(e){
			if (YAHOO.env.ua.ie != 6)
			{
				hint = Dom.getElementsByClassName( "bace-gallery-thumbnails-holder-hint" , "div" , this);
				
				Dom.setStyle(hint,"opacity",0);
				//Dom.setXY(hint,Event.getXY(e));
				
				var opacityAnim = new YAHOO.util.Anim(hint, { opacity: { from: 0, to: 1 } }, 1, YAHOO.util.Easing.easeOut);
				opacityAnim.animate();
			}
		});

    });
})();
