//global custom event handlers
document.observe('page:set_meta_title', function(event) {
    document.title = event.memo.value;
}.bindAsEventListener(this));

document.observe('page:set_title', function(event) {
    //TODO: add something here when we add page title into layout
}.bindAsEventListener(this));

document.observe('page:set_breadcrumbs', function(event) {
    $('breadcrumbs').replace(event.memo.value);
}.bindAsEventListener(this));





Element.addMethods({
    
});

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;
		} else if (event.detail) { delta = -event.detail/3;	}
		return Math.round(delta); //Safari Round
	}
});


var ImagesFadeIn = Class.create({
    initialize: function(container)
    {
        if (Prototype.Browser.IE)
            return;

        this.domContainer = $(container);

        this.onLoadBound = this.onLoad.bindAsEventListener(this);



        var fadeIns = this.domContainer.select('.fade-in');

        //find all images and add onload handlers
        for (var i = 0; i < fadeIns.length; i++)
        {
            var images =  fadeIns[i].select('img');

            fadeIns[i].fi_incompleteImagesCount = 0;

            for (var j = 0; j < images.length; j++)
            {
                if (!images[j].complete)
                {
                    Event.observe(images[j], 'load', this.onLoadBound);
                    images[j].fi_container = fadeIns[i];

                    fadeIns[i].fi_incompleteImagesCount += 1;
                }
            }




            if (fadeIns[i].fi_incompleteImagesCount > 0)
                fadeIns[i].setOpacity(0);
            else
            {
                this.animate(fadeIns[i]);
            }


        }

    },

    onLoad: function(event)
    {
        var domImg = event.element();
        var domFadeIn = domImg.fi_container;

        domFadeIn.fi_incompleteImagesCount -= 1;


        if (domFadeIn.fi_incompleteImagesCount == 0)
        {
            this.animate(domFadeIn);
        }
    },

    animate: function(domFadeIn)
    {
        var effect = new Effect.Opacity(domFadeIn, {
            to: 1.0,
            delay: parseFloat(domFadeIn.readAttribute('fade_in_delay')),
            duration: parseFloat(domFadeIn.readAttribute('fade_in_duration')),
            queue: {scope: 'fi', position: 'end'},
            afterFinish: function() {domFadeIn.removeClassName('fade-in')}
        });

    }
});




var AnimatedText = Class.create({
    initialize: function(container, duration)
    {
        this.domContainer = $(container);
        this.duration = duration || 0.5;

        this.timer = new PeriodicalExecuter(this.onTimer.bind(this), this.duration);
    },

    nextFrame: function()
    {
        var current = this.domContainer.down('span.current');
        if (!current)
        {
            next = this.domContainer.down('span');
        }
        else
        {
            next = current.next('span') || this.domContainer.down('span');
        }

        this.domContainer.select('span').invoke('removeClassName', 'current');
        next.addClassName('current');
    },

    onTimer: function()
    {
        this.nextFrame();  
    }
    
});


var DragScrollable = Class.create({
    initialize: function(container, options)
    {
        this.domContainer = $(container);

        this.defaultOptions = ({
            acceleration: 400,
            fps: 30,
            type: 'horizontal'
        });


        this.options = Object.clone(this.defaultOptions);
        Object.extend(this.options, (options || {}));




        this.domContainer.addClassName('drag-scrollable');


        this.onMouseDownBound = this.onMouseDown.bindAsEventListener(this);
        this.onMouseUpBound = this.onMouseUp.bindAsEventListener(this);
        this.onMouseMoveBound = this.onMouseMove.bindAsEventListener(this);
        this.onClickBound = this.onClick.bindAsEventListener(this);


        Event.observe(this.domContainer, 'mousedown', this.onMouseDownBound);
        Event.observe(document, 'mouseup', this.onMouseUpBound);
        Event.observe(document, 'mousemove', this.onMouseMoveBound);
        Event.observe(this.domContainer, 'click', this.onClickBound);
    },

    dispose: function()
    {
        this.domContainer.removeClassName('drag-scrollable');

        Event.stopObserving(this.domContainer, 'mousedown', this.onMouseDownBound);
        Event.stopObserving(document, 'mouseup', this.onMouseUpBound);
        Event.stopObserving(document, 'mousemove', this.onMouseMoveBound);
        Event.stopObserving(this.domContainer, 'click', this.onClickBound);
    },

    onMouseDown: function(event)
    {
        this.stopAnimation();

        if (event.isLeftClick())
        {
            this.dragging = true;

            $(document.body).addClassName('drag-scrollable-dragging');

            this.downPointer = this.options.type=='horizontal' ? event.pointerX() : event.pointerY();
            this.previousPointer = this.downPointer;

            this.startSpeedMeasure();

            event.stop();
        }
    },

    onMouseUp: function(event)
    {
        if (this.dragging)
        {
            event.stop();

            this.upPointer = this.options.type=='horizontal' ? event.pointerX() : event.pointerY();

            this.dragging = false;
            $(document.body).removeClassName('drag-scrollable-dragging');

            this.stopSpeedMeasure();

            this.animate();    
        }



    },

    onMouseMove: function(event)
    {
        if (this.dragging)
        {
            event.stop();

            var currentPointer = this.options.type=='horizontal' ? event.pointerX() : event.pointerY();
            var currentTimestamp = new Date().getTime();

            if (!this.previousPointer)
                this.previousPointer = currentPointer;

            var offset = this.previousPointer - currentPointer;

            this.setScrollOffset(this.getScrollOffset() + offset);


            this.previousPointer = currentPointer;

            if (this.options.onChange)
                this.options.onChange(this.getScrollOffset());

            this.doSpeedMeasure();
        }
    },

    onClick: function(event)
    {
        if (Math.abs(this.downPointer-this.upPointer) > 5)
        {
            event.stop();
        }
    },

    startSpeedMeasure: function()
    {
        this.speedMeasures = [];        
        this.speedTimer = new PeriodicalExecuter(this.doSpeedMeasure.bind(this), 0.01);
    },

    stopSpeedMeasure: function()
    {
        this.speedTimer.stop();
    },

    doSpeedMeasure: function()
    {
        this.speedMeasures.push({
            time: new Date().getTime(),
            position: this.getScrollOffset()
        });

        while(1)
        {
            if (this.speedMeasures.last().time - this.speedMeasures.first().time > 100)
                this.speedMeasures.shift();
            else
                break;
        }

        this.speed = 1000*(this.speedMeasures.last().position - this.speedMeasures.first().position)/(this.speedMeasures.last().time - this.speedMeasures.first().time)
    },



    setScrollOffset: function(val)
    {
        val = Math.round(val);

        if (this.options.type=='horizontal')
            this.domContainer.scrollLeft = val;
        else
            this.domContainer.scrollTop = val;


        return this.getScrollOffset();
    },

    getScrollOffset: function()
    {
         return this.options.type=='horizontal' ? this.domContainer.scrollLeft : this.domContainer.scrollTop;
    },

    animate: function()
    {

        //return;

        this.animation = new PeriodicalExecuter(this.onAnimationFrame.bind(this), 1.0/this.options.fps);
    },

    stopAnimation: function()
    {
        if (this.animation)
            this.animation.stop();
    },

    onAnimationFrame: function()
    {
        var t = 1/this.options.fps;
        var acc = this.options.acceleration;

        if (this.speed*acc >= 0)
            acc = -acc;

        var origSpeed = this.speed;
        var origOffset = this.getScrollOffset();


        this.setScrollOffset(this.getScrollOffset()+this.speed*t + acc*t*t/2);
        this.speed += acc*t;


        //offset didn't change or speed is zero or sign(speed) changed
        if (this.getScrollOffset()==origOffset || this.speed == 0 || this.speed*origSpeed < 0)
        {
            this.stopAnimation();
        }

        if (this.options.onChange)
            this.options.onChange(this.domContainer.scrollLeft);
    }


});



var Carousel = Class.create({
    initialize: function(container)
    {
        this.domCarousel = $(container);
        this.domCarouselItems = this.domCarousel.down('.carousel-items');


        this.domScrollTrack = this.domCarousel.down('.scroll-track');
        this.domScrollHandle = this.domScrollTrack.down('a'); 




        this.onContentLoadBound = this.onContentLoad.bindAsEventListener(this);
        this.onSlideBound = this.onSlide.bind(this);


        this.initSlider();

        this.domCarousel.select('img').each(function(e) {
            e.observe('load', this.onContentLoadBound);
        }.bind(this));


        this.dragScroll = new DragScrollable(this.domCarouselItems, {
            onChange: this.setScrollLeft.bind(this)
        });



        this.domCarouselItems.observe('mousewheel', this.onMouseWheel.bindAsEventListener(this));
        this.domCarouselItems.observe('DOMMouseScroll', this.onMouseWheel.bindAsEventListener(this));


    },

    initSlider: function()
    {
        var containerWidth =  this.domCarouselItems.getWidth();
        var containerScrollWidth = this.domCarouselItems.scrollWidth;
        var scrollTrackWidth = this.domScrollTrack.getWidth();


        var handleWidth = scrollTrackWidth*containerWidth/containerScrollWidth;
        if (!handleWidth)
            handleWidth = 0;

        if (handleWidth < 20)
            handleWidth = 20;


        this.domScrollHandle.style.width = Math.round(handleWidth)+'px';

       
        if (handleWidth < scrollTrackWidth)
        {
            this.showScrollTrack();

            if (this.slider)
            {
                this.slider.dispose();
            }


            this.slider = new Control.Slider(this.domScrollHandle, this.domScrollTrack, {
                value: this.slider ? this.slider.value : 0,
                range: $R(0, containerScrollWidth-containerWidth),
                onSlide: this.onSlideBound, onChange: this.onSlideBound
            });


        }
        else
        {
            this.hideScrollTrack();
        }











    },


    setScrollLeft: function(val)
    {
        if (this.slider)
            this.slider.setValue(val);

    },

    showScrollTrack: function()
    {
       this.domScrollTrack.style.visibility = 'visible';
        //this.domScrollHandle.style.visibility = 'visible';
    },

    hideScrollTrack: function()
    {
        this.domScrollTrack.style.visibility = 'hidden';
        //this.domScrollHandle.style.visibility = 'hidden';
    },

    onSlide: function(value)
    {
        this.domCarouselItems.scrollLeft = Math.round(value);///this.slider.maximum*(this.domCarouselItems.scrollWidth-this.domCarouselItems.offsetWidth));
    },

    onContentLoad: function(event)
    {
        this.initSlider();
    },

    onMouseWheel: function(event)
    {
        var offset = Event.wheel(event);

        if (this.slider)
        {
            this.slider.setValue(this.slider.value - offset*30);
            Event.stop(event);
        }

    }
});


var ProductList2 = Class.create({

    initialize: function(container)
    {
        this.domContainer = $(container);
        this.domHighlighted = this.domContainer.down('.highlighted-product');
        this.domProductsContainer = this.domContainer.down('.products-container');
        this.domLayoutSwitcher = this.domContainer.down('.layout-switcher');

        this.domProductsContainer.select('.product').each(function(domProduct) {
            domProduct.observe('mouseover', this.onProductMouseOver.bindAsEventListener(this));
            domProduct.observe('mouseout', this.onProductMouseOut.bindAsEventListener(this));
        }.bind(this));


        this.domContainer.select(".pagination a", ".product-filter a").each(function(domLink) {

            domLink.observe('click', this.onCatalogLinkClick.bindAsEventListener(this));

        }.bind(this));

    },


    onProductMouseOver: function(event)
    {
        var domProduct = this.getEventProduct(event);

        clearTimeout(domProduct.stopAnimationTimer);

        if (!domProduct.animation)
        {
            domProduct.animation = new PeriodicalExecuter(this.animationFrame.bind(this, domProduct), 0.8);
            this.animationFrame(domProduct)
        }
    },

    onProductMouseOut: function(event)
    {
       
        var domProduct = this.getEventProduct(event);


        if (domProduct.animation)
        {
            domProduct.stopAnimationTimer = setTimeout(this.stopAnimation.bind(this, domProduct), 0.8)
        }

    },

    stopAnimation: function(domProduct)
    {
        domProduct.animation.stop();
        domProduct.animation = null


        domProduct.select('.product-images .artwork').invoke('removeClassName', 'current');;
        domProduct.select('.product-images .artwork:first-child').invoke('addClassName', 'current');;
    },

    getEventProduct: function(event)
    {
        var e = event.element();
        if (e.match('.product'))
            return e;
        else
            return e.up('.product');
    },

    animationFrame: function(domProduct)
    {
        var screenshots = domProduct.select('.product-images .artwork');

        if (screenshots.length == 0)
            return;

        var current = domProduct.down('.product-images .artwork.current');
        var next = current.next('.artwork');

        if (!next)
            next = screenshots.first();


        screenshots.invoke('removeClassName', 'current');
        next.addClassName('current');
    },

    onCatalogLinkClick: function(event)
    {
        event.stop();

        this.loadList(event.element().href);
    },


    loadList: function(url)
    {
        this.domProductsContainer.select('.product').invoke('removeClassName', 'active-product');



        this.domProductsContainer.select('.product').invoke('setOpacity', 0.4);
        new Ajax.Request(url, {method: 'get', onSuccess: this.onLoadList.bind(this)});
    },

    onLoadList: function(res)
    {
        this.domContainer.replace(res.responseText);
    }
});


var ProductList = Class.create({
    initialize: function(container)
    {
        this.domContainer = $(container);
        this.domHighlighted = this.domContainer.down('.highlighted-product');
        this.domProductsContainer = this.domContainer.down('.products-container');
        this.domLayoutSwitcher = this.domContainer.down('.layout-switcher');


        this.domProductsContainer.select('.product').each(function(domProduct) {
            domProduct.observe('mouseover', this.onProductMouseOver.bindAsEventListener(this));
            domProduct.observe('mouseover', this.onProductMouseOut.bindAsEventListener(this));
        }.bind(this));

        this.domProductsContainer.select('a.product-details-link').each(function(domDetailsLink) {
            domDetailsLink.observe('click', this.onProductDetailsLinkClick.bindAsEventListener(this));
        }.bind(this));



        this.domLayoutSwitcher.select('a').each(function(domLink) {
            domLink.observe('click', this.onSwitchLayoutClick.bindAsEventListener(this));
        }.bind(this));


        this.domContainer.select(".pagination a", ".product-filter a").each(function(domLink) {

            domLink.observe('click', this.onCatalogLinkClick.bindAsEventListener(this));

        }.bind(this));


        
        if (this.domProductsContainer.cumulativeOffset()[1] < document.documentElement.scrollTop)
		{
			new Effect.ScrollTo(this.domLayoutSwitcher);
		}


        this.higlightOnMouseOver = true;

        var domHighlightedProduct = this.domHighlighted.down('.product');
        if (domHighlightedProduct)
        {
            var domHighlightedInGrid = this.domProductsContainer.down('.product[product_id='+domHighlightedProduct.readAttribute('product_id')+']');
            if (domHighlightedInGrid)
                this.highlightProduct(domHighlightedInGrid);
        }
    },


    highlightProduct: function(domProduct)
    {
        if (!domProduct)
            domProduct = this.domProductsContainer.down('.product');

        if (!domProduct)
            return;

        var currentProduct = this.domHighlighted.down('.product');

        if (!currentProduct || currentProduct.readAttribute('product_id') != domProduct.readAttribute('product_id'))
        {
            if (currentProduct)
                currentProduct.remove();


            var domClone = domProduct.cloneNode(true);
            domClone.removeClassName('fade-in');
            domClone.style.opacity = '';

            this.domHighlighted.insert({top: domClone});
        }

        domProduct.up().select('.product').invoke('removeClassName', 'active-product');
        domProduct.addClassName('active-product');
    },

    isGridView: function()
	{
        return this.domContainer.hasClassName('product-list-grid');
	},


    onProductMouseOver: function(event)
    {
        if (this.isGridView())
        {
            if (this.higlightOnMouseOver)
            {
                var domProduct = event.element();
                if (!domProduct.match('.product'))
                    domProduct = domProduct.up('.product');

                this.highlightProduct(domProduct);
            }

        }
    },

    onProductMouseOut: function(event)
    {

    },

    onProductDetailsLinkClick: function(event)
    {
        if (this.isGridView())
        {
            event.stop();

            this.highlightProduct(event.element().up('.product'));
            this.higlightOnMouseOver = false;
        }
    },

    onSwitchLayoutClick: function(event)
    {
        if (event.element().hasClassName('change-layout-grid'))
            this.domContainer.addClassName('product-list-grid');
		else
            this.domContainer.removeClassName('product-list-grid');
        
        Set_Cookie('product_list_layout', this.isGridView()?'grid':'list');
    },

    onCatalogLinkClick: function(event)
    {
        event.stop();

        this.loadList(event.element().href);
    },


    loadList: function(url)
    {
        this.domProductsContainer.select('.product').invoke('removeClassName', 'active-product');



        this.domProductsContainer.select('.product').invoke('setOpacity', 0.4);
        new Ajax.Request(url, {method: 'get', onSuccess: this.onLoadList.bind(this)});
    },

    onLoadList: function(res)
    {
        this.domContainer.replace(res.responseText);
    }

});



var Overlay = Class.create({
    initialize: function()
    {
        this.initDom();
    },

    initDom: function()
    {
        this.domOverlay = new Element('div', {'class': 'overlay'});
        this.domOverlay.style.position = 'absolute';
        this.domOverlay.style.width = '100%';
        this.domOverlay.style.height = $(document.body).getStyle('height');
        this.domOverlay.style.left = '0';
        this.domOverlay.style.top = '0';

        $(document.body).insert({bottom: this.domOverlay});
    },

    close: function()
    {
        this.domOverlay.remove();
    },

    observe: function(event, handler)
    {
        this.domOverlay.observe(event, handler);   
    }
})


var Popup = Class.create({

    initialize: function(options)
    {
        this.defaultOptions = ({
            title: 'Message',
            html: 'loading...',
            url: null
        });


        this.options = Object.clone(this.defaultOptions);
        Object.extend(this.options, (options || {}));

        this.initDom();
        this.setTitle(this.options.title);
        this.setHtml(this.options.html);

        if (this.options.url)
            this.loadUrl(this.options.url);




    },

    initDom: function()
    {
        this.domPopup = new Element('div', {'class': 'popup'});

        /*table workaround*/
        var domTable = new Element('table', {cellspacing: '0', cellpadding: '0', border: '0'}); this.domPopup.appendChild(domTable);
        var domTbody = new Element('tbody'); domTable.appendChild(domTbody);
        var domRow = new Element('tr'); domTbody.appendChild(domRow);
        var domCell = new Element('td'); domRow.appendChild(domCell); 
        /*table workaround end*/

        this.domHeader = new Element('div', {'class': 'popup-header'}); domCell.appendChild(this.domHeader);
        this.domBody = new Element('div', {'class': 'popup-body'}); domCell.appendChild(this.domBody);

        this.domCloseLink = new Element('a', {href:'javascript:void(0)', 'class':'popup-close-link', onclick: "this.fire('popup:close')"});
        this.domCloseLink.innerHTML = 'close';
        this.domHeader.appendChild(this.domCloseLink);

        this.domTitle = new Element('span', {'class':'popup-title'});
        this.domHeader.appendChild(this.domTitle);


        this.overlay = new Overlay();
        this.overlay.observe('click', this.onOverlayClick.bindAsEventListener(this));
        
        $(document.body).insert({bottom: this.domPopup});


        /*events*/
        this.domPopup.observe('popup:close', this.onClose.bindAsEventListener(this));
        this.domPopup.observe('page:set_title', this.onSetTitle.bindAsEventListener(this));
        this.domPopup.observe('page:set_meta_title', this.onSetMetaTitle.bindAsEventListener(this));
        this.domPopup.observe('page:set_breadcrumbs', this.onSetBreadcrumbs.bindAsEventListener(this));





    },


    center: function()
    {
        var viewportSize = document.viewport.getDimensions();


        var popupSize = this.domPopup.getDimensions();


        var targetViewportOffset = [(viewportSize.width-popupSize.width)/2, (viewportSize.height-popupSize.height)/2];
        var currentViewportOffset = this.domPopup.viewportOffset();

        var currentDocumentOffset = this.domPopup.cumulativeOffset();
        var targetDocumentOffset = [
        targetViewportOffset[0]-currentViewportOffset[0]+currentDocumentOffset[0],
        targetViewportOffset[1]-currentViewportOffset[1]+currentDocumentOffset[1]
        ];


        if (targetDocumentOffset[1] < 10)
        	targetDocumentOffset[1] = 10; //do not show popup above the screen %)

        var styleLeft = targetDocumentOffset[0]+'px';
        var styleTop = targetDocumentOffset[1]+'px';


        this.domPopup.style.left = styleLeft;
        this.domPopup.style.top = styleTop;
    },



    close: function()
    {
        this.domPopup.remove();
        this.overlay.close();
    },

    setTitle: function(title)
    {
        this.domTitle.update(title);  
    },

    setHtml: function(html)
    {
        this.domBody.update(html);
        this.center();
    },

    loadUrl: function(url)
    {

        new Ajax.Request(url, {method: 'get', onSuccess: this.onUrlLoad.bind(this)});

    },

    onUrlLoad: function(res)
    {
        this.setHtml(res.responseText);
    },




    /*event handlers*/

    onClose: function(event)
    {
        this.close();
    },

    onOverlayClick: function(event)
    {
        this.domPopup.fire('popup:close');        
    },

    onSetTitle: function(event)
    {
        this.setTitle(event.memo.value);

        //prevent changing of the page title
        event.stop();
    },

    onSetMetaTitle: function(event)
    {
        //no not change meta title when event is fired inside of popup
        event.stop();
    },

    onSetBreadcrumbs: function(event)
    {
        //no not change breadcrumbs when event is fired inside of popup
        event.stop();
    }

});






function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


function Get_Cookie( check_name )
{
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for ( i = 0; i < a_all_cookies.length; i++ )
    {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split( '=' );


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if ( cookie_name == check_name )
        {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if ( a_temp_cookie.length > 1 )
            {
                cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if ( !b_cookie_found )
    {
        return null;
    }
}


// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}















/*
function scrollHorizontal(value, element, slider) {
	 element.scrollLeft = Math.round(value/slider.maximum*(element.scrollWidth-element.offsetWidth));
}

InitSlider = function (){

        $$('.carousel').each (function(carusel) {
            if (carusel.down('div table').offsetWidth > carusel.down('div ').offsetWidth) {
                var handle = document.createElement('a');
                handle.href = 'javascript: void(0);'

                var track = document.createElement('div');
                track.className = 'scroll-track'
                track.appendChild(handle)

                carusel.appendChild(track);

                var scrollable = carusel.down('div');

                var slider = new Control.Slider(handle, track, {
                    onSlide: function(v) { scrollHorizontal(v, scrollable, slider);  },
                    onChange: function(v) { scrollHorizontal(v, scrollable, slider); }
                });
            }

        });

}


Event.observe(window, 'load', InitSlider);
*/


Event.observe(document, 'dom:loaded', function() {new ImagesFadeIn(document.body)});
