/*
	global.js	
*/

// =========================================================================================
//
// jQuery main
//
// =========================================================================================
	$(document).ready(function() {
		
		/* add print button to every page */
		$('#side ul.navigation').append('<li><a href="#" class="print">Print this page</a></li>');
		$('#side ul.navigation li a.print').click(function(event) {
			event.preventDefault();
			$('dt.recipe, dd.recipe, ul.recipe-list li, div.wysiwyg').removeClass('no-print');
			window.print();
		});
		
		/* add print button to every recipe */
		$('dt.recipe div').append('<br /><a href="#" class="no-print">Print this recipe</a>');
		$('dt.recipe div a').click(function(event) {
			event.preventDefault();
			$('dt.recipe, dd.recipe').addClass('no-print');
			$(this).closest('dt.recipe').removeClass('no-print').next('dd.recipe').removeClass('no-print');
			$('ul.recipe-list li').addClass('no-print');
			$('dl.whats-on').prev('div.wysiwyg').addClass('no-print');
			window.print();
		});
		
		/* rollover effects using opacity */										
		if (jQuery.support.opacity) {
			$('ul.navigation li, form .submit, #main a, #homepage a.button').css('cursor','pointer').hover(
				function() {
					$(this).fadeTo("fast", 0.5);
				},
				function() {
					$(this).fadeTo("fast", 1.0);
				}
			);
		} else {
			$('ul.navigation li a img').hover(
				function() {
					$(this).attr("src", function() {
						return this.src.replace(".png","-hover.png");
					});
				},
				function() {
					$(this).attr("src", function() {
						return this.src.replace("-hover.png",".png");
					});
				}
			);
		}
		
		/* table alternate row shading */
		$('table#centre-directory tr').hover(
			function() {
				$(this).find('a').addClass('active');
				$(this).find('td:nth-child(2)').css('background','#f3f3f3 url("/site_media/img/table-td-highlight-odd.gif") left center no-repeat');
				$(this).find('td:nth-child(3)').css('background','#e8e8e8 url("/site_media/img/table-td-highlight-even.gif") left center no-repeat');
			},
			function() {
				$(this).find('a').removeClass('active');
				$(this).find('td:nth-child(2)').css('background','#f3f3f3');
				$(this).find('td:nth-child(3)').css('background','#e8e8e8');
			}
		);
		$('table#centre-directory tr th:first').addClass('left');
		$('table#centre-directory tr th:last').addClass('right');
		$('table#centre-directory tr td:nth-child(2), #main :not(form) ul li:nth-child(odd)').addClass('odd');
		$('table#centre-directory tr th').css('borderRight','1px solid #f3f3f3');
		$('table#centre-directory tr th:last').css('borderRight','none');
		
		$('#main ul.layout-two-column-blocks li:odd').addClass('left');
		$('#main ul.layout-two-column-blocks li:even').addClass('right');
		$('#main ul.layout-two-column-blocks li table tr:nth-child(2n+2) td').addClass('odd');
		$('#main ul.layout-two-column-blocks li table').find('tr:first td:first').addClass('top-left');
		$('#main ul.layout-two-column-blocks li table').find('tr:first td:last').addClass('top-right');
		$('#main ul.layout-two-column-blocks li table').find('tr:last td:first').addClass('bottom-left');
		$('#main ul.layout-two-column-blocks li table').find('tr:last td:last').addClass('bottom-right');
		
		$('.wysiwyg table tr:odd td').addClass('odd');
		$('.wysiwyg table tr:even td').addClass('even');
		
		
	});
