window.addEvent('domready',function(){

	$$('.nojs').setStyle('display','none');
	$$('.jsenabled').removeClass('jsenabled');

	SqueezeBox.initialize({});
	SqueezeBox.assign($$('a.SqueezeBox'), {
		parse: 'rel'
	});
	
	
	//submit/go button rollovers
	$$('#content input[src$=btn-submit.gif],#content input[src$=btn-il-go.gif],#content img[src$=btn-delete.gif],#content input[src$=btn-i-agree.gif]').addEvents({
		'mouseenter': function(){
			this.set('src',this.src.replace(/\.gif/i,'-hover.gif'));
		},
		'mouseleave': function(){
			this.set('src',this.src.replace(/\-hover.gif/i,'.gif'));
		}
	});
	
	
	//add open in new window function to anchors of class "open-new-win"
	$$('a.open-new-win').addEvents({
		'click':function(){
			window.open(this.href);
			return false;
		},
		'keypress':function(){
			window.open(this.href);
			return false;
		}
	});

				
});

var shadowOpen = false;


function setLayerPosition() {
	var shadow = document.getElementById("shadow");

	var bws = window.getSize();
	shadow.style.width = bws.x + "px";	
	shadow.style.height = bws.y + "px";
	if (!Browser.Engine.trident4) {
		shadow.style.position = 'fixed';
	} else {	
		if(document.body.getScrollHeight() < bws.y){
			shadow.style.height = bws.y+'px';			
		} else {
			shadow.style.height = document.body.getScrollHeight()+'px';
		}
	}
	shadow = null;
}


function showLayer( el ) {
	shadowOpen = true;
	setLayerPosition();
	el.style.zIndex = 500;

	var shadow = $("shadow");
	
	shadow.style.zIndex = 400;
	if (Browser.Engine.trident4) {
		$$('select').each(function(el){
			el.setStyle('visibility','hidden');
			//alert('they\'re gone');
		});
	}
	shadow.set('tween',{duration:100});
	shadow.style.display = "block"; 
	shadow.style.opacity = 0;	
	shadow.tween('opacity',[0,0.2]);
	shadow = null;
}

function hideLayer(zIndex, el) {
	shadowOpen = false;
	var shadow = $("shadow");
	shadow.tween('opacity',0);
	if (Browser.Engine.trident4) {
		$$('select').each(function(el){
			el.setStyle('visibility','visible');
		});
	}
	el.style.zIndex = zIndex;
	shadow = null;
}

window.addEvent('resize',function(){
	if(shadowOpen) {setLayerPosition();}
});


var Sliders = new Class({
    Implements: [Events, Options],
    options:{
        button:'.toggle',
        slideClass:'.slider',
        autoHide:'',
        openFirst:'',
        showImage:'',
        hideImage:'',
        showText:'',
        hideText:'',
        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.showFirst && !this.options.autoHide){$$(this.options.button)[0].fireEvent('click');}
        
    }
});


	
	//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:'',
		showText:'',
		textClass:'.inline-slide-toggle',
		textClassBg:true
	});

function ClearInput(target, defaultval){
	if(target.value === defaultval){
		target.value = "";
	}
	if(target.nodeName.test('textarea','i')){
		if(target.innerHTML == defaultval){
			target.innerHTML = '';
		}
	}
}

function ReplaceInputPrompt(target,defaultval){
	if(target.value === ""){
		target.value = defaultval;
	}
	if(target.nodeName.test('textarea','i')){
		if(target.innerHTML === ""){
			target.innerHTML = defaultval;
		}
	}
}


function hideHomeContent() 
{            
    
    var container;
    var getleftvalue;
    var currentleft;
    var newleft;
    var imageurlnew;

    getleftvalue = $('homepage-content').getStyle('left');
    
    if (getleftvalue == '0px')
        {
            currentleft = '0px';
            newleft = '-619px';
        }
    else
        {
            currentleft = '-619px';
            newleft = '0px';
        }
                     
    container = $('homepage-content');
    container.set('tween', {duration:'500', transition: Fx.Transitions.linear, onComplete: function()
            {
                if (getleftvalue == '0px')
                    {
                        imageurlnew = $('button').getElement('img').src.replace('hide','show');
                    }
                else
                    {
                        imageurlnew = $('button').getElement('img').src.replace('show','hide');
                    }
                $('showhidebutton').src = imageurlnew;
            }
     }); 
    container.tween('left', currentleft, newleft); 
}


function printpage(){
    window.print();
}

