window.addEvent('domready', function() {

    //homepage animation
    if ($('window')){
        //var background = new Fx.Scroll($('window'), {duration:'4000', transition:'sine:in:out'}); //4000
        var welcome = new Fx.Morph('welcometxt', {duration: '1000', transition:'sine:in:out'}); //1000
        var rainbow1 = new Fx.Morph('rainbow1', {duration: '1000', transition:'sine:in:out'});
        var whitebox = new Fx.Morph('whitebox', {duration: '1000', transition:'sine:in:out'});
        var rainbow2 = new Fx.Morph('rainbow2', {duration: '1000', transition:'sine:in:out'});
        
        whitebox.set({'opacity':0.90})
        
        
        // preloading homepage
        var images = ['images/fullscreen/home.jpg']; 
        var loader = new Asset.images(images, { 
            onComplete: function() {
                //hp image has finished loading, now start animation
                //background.toBottom().chain(function(){
                    welcome.start({'left':[1001, 700]}).chain(function(){
                        rainbow1.start({'left':[-12, 710]}).chain(function(){
                            whitebox.start({'left':[-505, 32]}).chain(function(){
                                rainbow2.start({'left':[-12, 16]})
                            });
                        });
                    });
                    
                //});                
            }
        });
        
        // preloading of everything else
        var images2 = ['images/fullscreen/home.jpg','images/fullscreen/whatWeDo.jpg','images/fullscreen/services.jpg','images/fullscreen/furnishingSolutions.jpg','images/fullscreen/lifestyle.jpg','images/fullscreen/kitchens.jpg','images/fullscreen/bathrooms.jpg','images/fullscreen/furniturePackages.jpg','images/fullscreen/silverPackage.jpg','images/fullscreen/goldPackage.jpg','images/fullscreen/platinumPackage.jpg','images/fullscreen/enquiryForm.jpg','images/fullscreen/ourClients.jpg','images/fullscreen/testimonials.jpg','images/fullscreen/mediaCentre.jpg','images/fullscreen/contactUs.jpg','images/fullscreen/careers.jpg']; 
        var loader2 = new Asset.images(images, {});                
        
    }; 
    
    //make the hide content button glow
    if ($('hcbutton')){
        makeMeGlow.periodical(3000);  
    };
    
        
    //photo gallery
    if ($('cave')){
        $('hcbutton').setStyle('visibility', 'hidden');
        var cave = new Fx.Scroll($('cave'), {duration:'4000', transition:'linear'});
        $('left-button').addEvent('mouseenter', function(){
            cave.toLeft()
        })
        $('left-button').addEvent('mouseleave', function(){
            cave.cancel()
        })
        $('right-button').addEvent('mouseenter', function(){
            cave.toRight()
        })
        $('right-button').addEvent('mouseleave', function(){
            cave.cancel()
        })
    };
    
    //homepage hide content button
    if ($('content')){    
                  
        $('hc').addEvent('click', function(e){
		    e.stop();
		    $('content').fade('toggle');
		    if ($('hc').get('text') == 'hide content'){
		        $('hc').set('text', 'show content')
		    }else{
		        $('hc').set('text', 'hide content')
		    }
	    });    
    }    
    
    //hide content button on other pages
    if ($('b2')){    
                  
        $('hc').addEvent('click', function(e){
		    e.stop();
		    $('b2').fade('toggle');
		    if ($('hc').get('text') == 'hide content'){
		        $('hc').set('text', 'show content')
		    }else{
		        $('hc').set('text', 'hide content')
		    }
	    });    
    }
    
    if($('b3')){					
        makeScrollbar( $('b3'), $('scrollbar1'), $('handle1') );
        //hide scrollbar if its not required
        if ($('b3').scrollHeight <= $('b3').offsetHeight) {
            $('scrollbar1').setStyle('visibility','hidden');
        }
    }            

});



        /// used to make the hide content button glow (grab the users attention)
        function makeMeGlow(){
            var hcbutton = new Fx.Morph('hc', {duration: '1000', transition:'sine:in:out'});
            hcbutton.start({'color': '#a7a9ac','margin-right':'0px'}).chain(function(){
                hcbutton.start({'color': '#de3931','margin-right': '12px'})
            });
        };


			function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
				var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
				var slider = new Slider(scrollbar, handle, {	
					steps: steps,
					mode: (horizontal?'horizontal':'vertical'),
					onChange: function(step){
						// Scrolls the content element in x or y direction.
						var x = (horizontal?step:0);
						var y = (horizontal?0:step);
						content.scrollTo(x,y);
					}
				}).set(0);
				if( !(ignoreMouse) ){
					// Scroll the content element when the mousewheel is used within the 
					// content or the scrollbar element.
					$$(content, scrollbar).addEvent('mousewheel', function(e){	
						e = new Event(e).stop();
						var step = slider.step - e.wheel * 30;	
						slider.set(step);					
					});
				}
				// Stops the handle dragging process when the mouse leaves the document body.
				$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
			}