window.addEvent('domready',function(){

	$$('.nojs').setStyle('display','none');
	$$('.jsenabled').removeClass('jsenabled');	
	
	SqueezeBox.initialize({});
	SqueezeBox.assign($$('a.SqueezeBox'), {
		parse: 'rel'
	});
		
	//Page sliders for content managed areas
	var InlineSlides=new Sliders({
		button:'.inline-slide-toggle',
		slideClass:'.inline-slide',
		autoHide:true,
		openFirst:false,
		//showImage:'/images/inline-slide-toggle-down.gif',
		//hideImage:'/images/inline-slide-toggle-up.gif',
		imageClass:'',
		hideText:'Read less...',
		showText:'Read more...',
		textClass:'.inline-slide-toggle',
		textClassBg:true
	});
	
	var theHash = window.location.hash;
	
	if(theHash.test('slide')){
		var slideNum = theHash.replace('#slide','');
		
		if($$('.inline-slide-toggle')[slideNum]){
			scrollTo(0,$$('.inline-slide-toggle')[slideNum].getPosition().y);
			$$('.inline-slide-toggle')[slideNum].fireEvent('click');
		}
	}				
});

var shadowOpen = false;


var Sliders = new Class({
    Implements: [Events, Options],
    options:{
        button:'.toggle',
        slideClass:'.slider',
        autoHide:'',
        openFirst:'',
        showImage:'',
        hideImage:'',
        showText:'Read more...',
        hideText:'Read less...',
        imageClass:'',
        textClass:'',
        textClassBg:false
    },
    initialize:function(options){
        this.setOptions(options);
        
        this.sliders = $$(this.options.slideClass).map(function(e){
           
           if(Browser.Engine.gecko){
				//need to use FF hack so the slide doesn't flicker because it wraps around scrolling divs
				if(this.options.autoHide){
					return new Fx.Slide(e,{overflow:'auto'}).hide()
				}else{
					return new Fx.Slide(e,{overflow:'auto'})
				};
			}else{
				//don't hack for others as causes scroll bars to appear during slide in IE
				if(this.options.autoHide){
					return new Fx.Slide(e).hide()
				}else{
					return new Fx.Slide(e)
				};
			};			
        },this);
        
        $$(this.options.button).each(function(toggler,index){
			toggler.addEvent('click',function(){
				if(this.sliders[index]) this.sliders[index].toggle();		
				//change show/hide image
				if(this.options.imageClass != ''){
					if($$(this.options.imageClass)[index]){
						var indicatorImage = $$(this.options.imageClass)[index];
						if(indicatorImage.get('src').indexOf(this.options.showImage) > -1){
							indicatorImage.set('src',this.options.hideImage);													
						}else if(indicatorImage.get('src').indexOf(this.options.hideImage) > -1){
							indicatorImage.set('src',this.options.showImage);
						}
					}
				}				
				
				//change show/hide text
				if(this.options.textClass != ''){					
					if($$(this.options.textClass)[index]){
						var showHideText = $$(this.options.textClass)[index];
						if(this.options.showText !== '' && this.options.hideText !== ''){
							if(showHideText.get('text').indexOf(this.options.showText) > -1){
								showHideText.set('text',this.options.hideText);								
							}else if(showHideText.get('text').indexOf(this.options.hideText) > -1){
								showHideText.set('text',this.options.showText);
							}
						}
						
						//change background image
						if(this.options.textClassBg){
							var currentBg = showHideText.getStyle('background-image');
							if(currentBg.indexOf(this.options.showImage) > -1){								
								showHideText.style.backgroundImage = 'url('+this.options.hideImage+')';								
							}else if(currentBg.indexOf(this.options.hideImage) > -1){								
								showHideText.style.backgroundImage = 'url('+this.options.showImage+')';								
							}
						}
					}
				}
			}.bind(this));			
        },this);
        /*
        if(this.options.autoHide){					
			$$(this.options.button).each(function(e,index){
				if(!this.options.openFirst){
					e.fireEvent('click');
				} else if(this.options.openFirst && index != 0){
					e.fireEvent('click');
				}
			},this);
		};*/
		
		if(this.options.showFirst && !this.options.autoHide){$$(this.options.button)[0].fireEvent('click');}
        
    }
});
