/**
 * Cell Link with jQuery
 *
 * @author      Lex van der Woude <lex@xq.co.nz>
 * @copyright   Copyright (c) 2008, X-StatiQ Online Design, Ltd.
 * @link        http://www.xq.co.nz
 * @since       Version 1.0
 */

// Counter
var CellLinkCounter = 0 ;

function cell_link()
{
	//--------------------------------------------------------
	
	// WHOLE ROWS
	$('tr.cl_cell:has(a.cl_link)').unbind('mouseover') ; // Need to unbind previous actions!
	$('tr.cl_cell:has(a.cl_link)').unbind('mouseout') ; // Need to unbind previous actions!
	$('tr.cl_cell:has(a.cl_link)').unbind('click') ; // Need to unbind previous actions!
	$('tr.cl_cell:has(a.cl_link)')

		/**
		 * Mouse over
		 */
		.mouseover(function(){
			CellLinkOriColor = $(this).find('td:first').css("background-color") ;
			$(this).find('td').css("background-color", '#C4E675') ;
			$(this).css('cursor', 'hand') ;
		})

		//--------------------------------------------------------
		
		/**
		 * Mouse out
		 */
		.mouseout(function(){
			$(this).find('td').css("background-color", CellLinkOriColor) ;
		})
	
		//--------------------------------------------------------
		
		/**
		 * Mouse click
		 */
		.click(function(){
			
			id = $(this).find('a.cl_link').attr('id') ;
			
			if (id == '')
			{
				$(this).find('a.cl_link').attr('id', 'CellLink' + CellLinkCounter) ;
				id = $(this).find('a.cl_link').attr('id') ;
				CellLinkCounter++ ;
			}
			
			document.getElementById(id).click() ;
		}) ;
	
	//--------------------------------------------------------
	
	// CELLS ONLY
	$('td.cl_cell:has(a.cl_link)').unbind('mouseover') ; // Need to unbind previous actions!
	$('td.cl_cell:has(a.cl_link)').unbind('mouseout') ; // Need to unbind previous actions!
	$('td.cl_cell:has(a.cl_link)').unbind('click') ; // Need to unbind previous actions!
	$('td.cl_cell:has(a.cl_link)')

		/**
		 * Mouse over
		 */
		.mouseover(function(){
			CellLinkOriColor = $(this).css("background-color") ;
			$(this).css("background-color", '#C4E675') ;
			$(this).css('cursor', 'hand') ;
		})

		//--------------------------------------------------------
		
		/**
		 * Mouse out
		 */
		.mouseout(function(){
			$(this).css("background-color", CellLinkOriColor) ;
		})
	
		//--------------------------------------------------------
		
		/**
		 * Mouse click
		 */
		.click(function(){
			
			id = $(this).find('a.cl_link').attr('id') ;
			
			if (id == '')
			{
				$(this).find('a.cl_link').attr('id', 'CellLink' + CellLinkCounter) ;
				id = $(this).find('a.cl_link').attr('id') ;
				CellLinkCounter++ ;
			}
			
			document.getElementById(id).click() ;
		}) ;
	
	//--------------------------------------------------------
}

$(document).ready(function(){

	cell_link() ;
	
});