// JavaScript Docume
function getCurrentBox() {
	// check location for bookmark
	var pageURL = document.location.toString();

	if (pageURL.match('#')) { 
		// find the name of the anchor
		var activeItem = '#' + pageURL.split('#')[1];
	} else {
		// else default view
		var activeItem ='#overview';
	}

	return activeItem;
}

function hideAllBoxes () {

	$('#eventBox > div').each(function() {
		$(this).hide();
		var tempId=$(this).attr('id').split("_JQ");
		$(this).attr('id',tempId[0]);
	});

}


function resetMenu () {
	$('#rightMenu > ol > li > a > img:last-child').each (function() {
		// reset all images
		var imgSrc = $(this).attr('src');
		imgSrc = imgSrc.replace(/HI\.png/,'.png');
		$(this).attr('src',imgSrc);
		
	});
}

function activateCurrent (activeItem) {
	var activeLink = $('#rightMenu ol li a[href='+activeItem+']');

	// swap images
	activeImage = activeLink.find('img:last-child').attr('src').replace(/\.png/,'HI.png');
	$(activeLink).find('img:last-child').attr('src',activeImage);

	// switch boxes
	hideAllBoxes();
	var activeBox=$(activeItem);
	$(activeBox).show();

	// break id's
	$(activeBox).attr('id',activeItem.replace("#",'')+"_JQ");
}


function resetAccessButtons() {
	
	$('#accessButtons').find('img').each (function() {
		var imgSrc = $(this).attr('src');
		imgSrc = imgSrc.replace(/-red.gif/,'.gif');
		$(this).attr('src',imgSrc);
	});
}


$(document).ready(function(){
	
	/**************** 
	 EVENTS
	****************/
	var $body = $('body');
	if($body.attr("id") == 'whatsonPage') {
		hideAllBoxes();
		var activeItem=getCurrentBox();
		activateCurrent (activeItem);
	
		$('#rightMenu ol li a').click(function() {
			var boxName=$(this).attr('href');

			// only do js magic if page anchor in link
			if (boxName.match('#')) {

				// deactivate images
				resetMenu();
				
				//activate box and menu image
				activateCurrent (boxName);

				// change hash to boxname
				window.location.hash=boxName;

				// if returning from a bookmark scroll top
				window.scrollTo(0,0);
				
				return false;
			} else {
				return true;
			}
		});
	}
	
	
	/************ slickbox ************/
	// hides the slickbox as soon as the DOM is ready
	// (a little sooner than page load)
	$('div.toggleHide').hide();
	// then toggles the slickbox on clicking the noted link
	$('a.slick-toggle').click(function() {


	  if($.browser.msie && parseFloat($.browser.version.substr(0,3))<=6){

		var $box=$(this).next('div.toggleHide');

		if ($($box).css('display')=='block') $($box).hide();
		else $($box).show();
		
	  } else {
		$(this).next('div.toggleHide').slideToggle(400);
	  }
	  
		return false;
	});


		$('#triggerSmall').click( function () {
		resetAccessButtons();
		activeImage = $(this).find('img').attr('src').replace(/\.gif/,'-red.gif');
		$(this).find('img').attr('src',activeImage);

		$('.TXTcol').css('font-size','1em');
		$('.TXTcol').css('line-height','1.4em');
		$('#homepage #footer').css('top','0');
	});


	$('#triggerMedium').click( function () {
		resetAccessButtons();
		activeImage = $(this).find('img').attr('src').replace(/\.gif/,'-red.gif');
		$(this).find('img').attr('src',activeImage);

		$('.TXTcol').css('font-size','1.2em');
		$('.TXTcol').css('line-height','1.5em');
		$('#homepage #footer').css('top','20px');
	});


	$('#triggerLarge').click( function () {
		resetAccessButtons();
		activeImage = $(this).find('img').attr('src').replace(/\.gif/,'-red.gif');
		$(this).find('img').attr('src',activeImage);

		$('.TXTcol').css('font-size','1.4em');
		$('.TXTcol').css('line-height','1.6em');
		$('#homepage #footer').css('top','120px');
	});






});
