/**
 * @author	Marcel Werk
 * @copyright	2001-2007 WoltLab GmbH
 * @license	WoltLab Burning Board License <http://www.woltlab.com/products/burning_board/license.php>
 */
function BoardMarkAsRead() {
	this.boardIDs = new Array();
	
	/**
	 * Initialises a board.
	 */
	this.init = function(boardNo, boardID) {
		// save boardID
		this.boardIDs[boardNo] = boardID;
		
		// get icon element
		var icon = document.getElementById('boardIcon' + boardNo);
		if (icon) {
			// add information
			icon.name = boardNo;
			
			// add event listener
			icon.ondblclick = function() { boardMarkAsRead.markAsRead(parseInt(this.name)); }
		}
	}
	
	/**
	 * Marks the board as read.
	 */
	this.markAsRead = function(boardNo) {
		// get icon element
		var icon = document.getElementById('boardIcon' + boardNo);
		
		// mark board as read
		var ajaxRequest = new AjaxRequest();
		if (ajaxRequest.openGet('index.php?page=Board&boardID='+this.boardIDs[boardNo]+'&action=markAsRead&ajax=1'+SID_ARG_2ND)) {
			// change icon
			icon.src = icon.src.replace(/New/, '');
			
			// clear title tag
			icon.title = '';
			
			// get board link
			var link = document.getElementById('boardLink' + boardNo);
			if (link) {
				// remove class
				link.className = '';
				
				// get unread threads span
				var spans = link.getElementsByTagName('span');
				if (spans.length > 0) {
					link.removeChild(spans[0]);
				}
			}
		}
	
		// remove event listener
		if (icon) {
			icon.ondblclick = '';
		}
	}
}

var boardMarkAsRead = new BoardMarkAsRead();
