/**
 * Author: Lee Langley
 * Date Created: 07/03/2011 15:11
 */
function setScrollPosition(){
	// check if an ID has been set
	var params = getQueryParams();
	if((params['id'] != undefined) && !isNaN(params['id'])){
		// an ID has been set so we need to find it's location

		var container = $('#scrollContainerLeft .customScrollBox .content');

		// loop through all of the elements up to the selected one, adding their height as we go
		var scrolledHeight = 0;
		$(container).children('a').each(function(){
			var tHeight = ($(this).outerHeight(true) >= $(this).children(':first').outerHeight(true)) ? $(this).outerHeight(true) : $(this).children(':first').outerHeight(true);

			if($(this).attr('name').replace(/^index/i, '') == params['id']){
				return false;
			}

			scrolledHeight += tHeight;
		});
	}

	// if the scroll height is greater than 0 then we need to posiotion the elements correctly
	if(scrolledHeight > 0){
		var maxHeight = $(container).outerHeight() - $(container).parents('.customScrollBox:first').outerHeight();
		scrolledHeight = ((scrolledHeight) > (maxHeight)) ? maxHeight : scrolledHeight;

		// set the container position to the top of the selected element
		$(container).parent('.container').css('top', -scrolledHeight + 'px');


		// now set up the scroller position
		var scrollContainer = $('#scrollContainerLeft .dragger_container');
		var scrollBar = $(scrollContainer).children('.dragger:first');

		var changePercent = scrolledHeight/(maxHeight + $(container).parents('.customScrollBox:first').outerHeight());
		var percentToMove = $(scrollContainer).innerHeight() * changePercent;

		percentToMove = ((percentToMove+$(scrollBar).height()) > ($(scrollContainer).innerHeight())) ? ($(scrollContainer).innerHeight()-$(scrollBar).height()) : percentToMove;

		$(scrollBar).css('top', percentToMove + 'px');
	}
}
