/* Solution list scroller object */
var solutionList = {
	headings: [[],[]],		//Heading td elements
	heights: [],			//Heights for contents
	active: 0,				//Active element (selected element) index
	count: 0,				//Number of elements in the list
	container: null,		//Container element
	container_width: 0,		//Container width
	content: null,			//Content element
	
	/* Make element selected */
	select: function (index) {
		if (index == solutionList.active) return;
		
		solutionList.headings[0][solutionList.active].removeClass('active');
		solutionList.headings[1][solutionList.active].removeClass('active');
		
		solutionList.headings[0][index].addClass('active');
		solutionList.headings[1][index].addClass('active');
		
		solutionList.active = index;

		solutionList.container.stop().animate({height: solutionList.heights[solutionList.active] + 'px'});
		solutionList.content.stop().animate({marginLeft: (- solutionList.container_width * solutionList.active) + 'px'});
	},
	/* Initialize scroller */
	init: function () {
		var headings = $('div.data_list .headings tr:first-child td');
		var table = $('div.data_list table.headings');
		
		for(var i=0,j=headings.length; i<j; i++)
		{
			solutionList.headings[0][i] = $(headings[i]);
			solutionList.headings[1][i] = $('tr:last-child td:nth-child(' + (i + 1) + ')', table);
			
			solutionList.headings[0][i][0]._solutionListIndex = i;	//Save index for use in event handler
			solutionList.headings[1][i][0]._solutionListIndex = i;	//Save index for use in event handler
			
			//Check if element is active (currently selected)
			if (solutionList.headings[1][i].hasClass('active')) {
				solutionList.active = i;
			}
			
			var el = $('div.content td:nth-child(' + (i + 1) + ') p');	//Content element
			var padding = parseInt(el.css('paddingTop')) + parseInt(el.css('paddingBottom'));	//Needed for height

			//Store content height
			solutionList.heights[i] = el.height() + padding;
		}
		
		/* Handle click */
		$('a', table).click(function () {
			solutionList.select($(this).parents('td')[0]._solutionListIndex);
			return false;
		});
		
		solutionList.count = j;
		solutionList.container = $('div.container').css('height', solutionList.heights[solutionList.active] + 'px');
		solutionList.content = $('div.content', solutionList.container);
		solutionList.container_width = solutionList.container.width();
	}
};

//Fix for "ready" event beeing fired on safari before document is loaded
$(window).bind("load", function () {
	solutionList.init();
	
	if (jQuery.browser.opera) $('div.data_list').addClass('opera_safari');
	if (jQuery.browser.safari) $('div.data_list').addClass('opera_safari');
});