$(document).ready(function() {
	
	// ul.expander 
	var selector = 'ul.expander';
	var liHeight = '100px';
	var rowHeights = [];
	var rowContent = [];
	
	$(selector + ' li').each(function(index, value){
		
		var rowHeight = $(this).css('height').replace('px','');
		rowHeight = parseInt(rowHeight) + 20;
		
		rowHeights.push(
			 (rowHeight-10)
		);
		
	});
	
	$(selector + ' li:odd').each(function(index){
		
		rowContent.push('');
		
		rowContent.push(
			$(this).html()
		);
		
		$(this).html('');
		
	});
	
	hideOddRows();
	
	$(selector + ' li:even').each(function(index, value){
		
		$(this).attr('class', 'question');
		$(this).html('<a class="hiding" href="#' + index + '">' + $(this).html() + '</a>');
		
	});
	
	$(selector + ' li:odd').each(function(index, value){
		
		$(this).html('<span class="padding">' + $(this).html() + '</span>');
		
	});
	
	$(selector + ' li:even a').live('click', function(e) {
		
		var liIndex = $(this).parent('li').index((selector + ' li'));
		
		e.preventDefault();
		
		if( $(this).parent('li').next('li').css('height') != rowHeights[liIndex+1] + 'px'){
			collapseOddRows($(this));
			expandNextRow($(this), rowHeights[liIndex+1], liIndex+1);
			$(this).css('backgroundPosition', 'right -274px');
		} else {
			collapseOddRows($(this));
		}
		
	});
	
	function expandNextRow(clickedLink, height, dex){
		
		clickedLink.parent('li').next('li').animate({
				height: height + 'px',
				paddingTop: '10px'
			}, 
			250, 
			function() {
				//clickedLink.parent('li').next('li').css('paddingTop', '10px');
				clickedLink.parent('li').next('li').html(rowContent[dex]);
		 	}
		);
		
	}
	
	function collapseOddRows(clickedLink){
		
		$(selector + ' li:odd').each(function(index){

			$(this).html('');

		});
		
		$(selector + ' li:odd').animate({
				height: '0px',
				paddingTop: '0px'
			}, 
			250, 
			function() {
		    	//clickedLink.parent('li').next('li').css('paddingTop', '0');
		 	}
		);
		
		$(selector + ' li:even a').css('backgroundPosition', 'right 16px');
		
	}
	
	function hideOddRows(){
		
		$(selector + ' li:odd').css('overflow', 'hidden');
		$(selector + ' li:odd').css('height', '0');
		
	}
	
	$(".signpost_wrap").click(function(){
		window.location=$(this).find("a").attr("href");
		return false;
	});

	$(".signpost_wrap").css("cursor","pointer");
	
	$('blockquote').append('<span class="blockquote_end"><!-- IE Fix --></span>');
	
});
