$(document).ready(function(){
	
	add_icon    = '<img src="/img/icons/add.png"/>';
	view_icon   = '<img src="/img/icons/magnifier.png" />';
	edit_icon   = '<img src="/img/icons/pencil.png" />';
	delete_icon = '<img src="/img/icons/delete.png" />';
	list_icon   = '<img src="/img/icons/list.png" />';

	/**
	 * Zebra table
	 */
	$("tr:nth-child(odd)").addClass("paire");

	/**
	 * Modifiy the action links of an items (index action)
	 */
	$("td.actions a").each(function(i){
		switch($(this).text()){
			case "View"  :$(this).html($(view_icon)); break;
			case "Edit"  :$(this).html($(edit_icon)); break;
			case "Delete":$(this).html($(delete_icon)); break;
		}
	});

	/**
	 * modify the add links
	 */
	$("ul.actions a[href*=/edit/]").prepend($(edit_icon));
	// patch the add link
	$("ul.actions a[href$=/edit/0] img").remove();
	$("ul.actions a[href$=/edit/0]").prepend($(add_icon));
	$("ul.actions a[href*=/delete/]").prepend($(delete_icon));
	$("ul.actions a[href*=/index]").prepend($(list_icon));
	
	/**
	 * transforme 0 and 1 to yes or no
	 */
	$("td,dd").each(function(i) {
		if ($(this).text() == '1') {
			$(this).text('yes');
		} else if ($(this).text() == '0') {
			$(this).text('no');
		}
	});
});
