// Init
var webroot = '/'; // Change this if the server moves

// Let's work the magic!
window.addEvent('domready', function() {		
	// Set up the requisite resources for the lightbox
	var overlay = new Element('div', {
		'id': 'lightbox-overlay',
		'styles': {
			'opacity': 0
		}
	}).inject('page');
	var overlayIn = new Fx.Tween($('lightbox-overlay'));
	function lightboxIn() {
		// Do this every time in case they resize the window
		$('lightbox-overlay').setStyles({
			'width': window.getScrollSize().x + 'px',
			'height': window.getScrollSize().y + 'px'
		});
	
		$('lightbox').setStyle('left', ((window.getScrollSize().x/2) - 429) + 'px');
		overlayIn.start('opacity', .6).chain(function() {
			$('lightbox').setStyle('display', 'block');
		});
	}
	// Set up the Store Map lightbox links
	$$('a.lightbox').each(function(el) {
		el.addEvent('click', function(e) {
			e.stop();
			if (!$('lightbox')) {
				var lightbox = new Element('div', {
					'id': 'lightbox'
				}).inject('page');
				new Request.HTML({'update': lightbox}).get(this.href + 'inline/').chain(function() {
					lightbox.getElement('.close-btn').addEvent('click', function(e) {
						e.stop();
						$('lightbox').setStyle('display', 'none');
						overlayIn.start('opacity', 0).chain(function() {
						});
						$('lightbox').destroy();	

					});
					lightboxIn();
				});
			} else {
				lightboxIn();
			}
		});
	});
})

/*==============================*/
// Homepage animation


window.addEvent('domready', function(){
	// Setup the homepage rotator
	if ($('home_banner')) {
		var frames = $('home_banner').getElements('.slide_nav a.frame-link');
		new TIControlledRotator(frames, $('home_banner'), {
			duration: 2,
			transition: Fx.Transitions.Quad.easeOut,
			fade_duration: 2.5,
			frame_class: 'slide',
			controls: {
				play_on_jump: true,
				buttons: {
					'play': $('home_banner').getElement('.play_pause_button'),
					'next': null,
					'prev': null
				}
			}
		});
	}
	

});

/*==============================*/
// IE6 and FF2 warning window


window.addEvent('domready', function() {
	if (Browser.ie6){
		if ( $('ie6_recommendation') ){
			$('ie6_recommendation').set('html','<p>This website does not support Internet Explorer 6 (IE6).</p><p>Please use one of the following browsers: Internet Explorer 8 or 7, Firefox 3, Safari, Chrome, or Opera.</p><p><a href="http://www.microsoft.com/windows/internet-explorer/worldwide-sites.aspx" target="_blank">Download the current version of Internet Explorer.</a></p><p class="more"><a class="close_window" href="">No thanks, view the website using IE6.</a></p>');
		}
	}else{
		if ( $('ie6_recommendation') ){
			$('ie6_recommendation').set('html','<p>This website does not support Firefox 2 (FF2).</p><p>Please use one of the following browsers: Internet Explorer 8 or 7, Firefox 3, Safari, Chrome, or Opera.</p><p><a href="http://www.mozilla.com/en-US/" target="_blank">Download the current version of Firefox.</a></p><p class="more"><a class="close_window" href="">No thanks, view the website using FF2.</a></p>');
		}
	}
	
	if (Browser.ie6 === 'TRUE' || Browser.firefox2 === 'TRUE'){

		if ( $('ie6_recommendation') ){
			var warning_window = $('ie6_recommendation');
			warning_window.addClass('display');
			warning_window.setProperty('top',0);
			warning_window.getElements('a.close_window').each(function(ele){
				ele.addEvent('click', function(e){
					e.stop();
					warning_window.removeClass('display');
				});
			});
		}
	}
});





   window.addEvent('domready',function() {
	$$('.comments_toggle').each(function(el) {
		var href = el.get('href');
		href = href.substr(href.lastIndexOf('#') + 1);
	

		
		$(href).set('slide').slide('hide');
		//Togles the comment-box in and out
		
		el.addEvent('click', function(e){
			e.stop();
			$(href).slide('toggle');
			var txt = this.get('text');
	
			if(txt == '+ Read more')
			{
				this.set('text', '- Read less');
			
			}
			else
			{
				this.set('text', '+ Read more');
				
			}


		});
		
		
		
		
		

	});

	
	

	
	
});



	 
    


