$(document).ready(function(){

	// Selected menu items.
	// -----------------------------------------------------------------------------
	$('#submenu').children('.current_page_ancestor').children('a:eq(0)').attr('class', 'selected');
	
	
	
	
	
	// Image formatting.
	// Adjust formatting if there is more than 1 image.
	// -----------------------------------------------------------------------------
	function image_reformat() {
		var image_count = $('.page-images > .page-image').size();
		if (image_count > 1) {
			$('.page-images').attr('class', 'page-images-wide');
			setHeight(".page-images-wide", 2, 0);
		}
	}
	
	function setHeight(theClass, cols, item_height) {
		
		$('body').append('<div id="debug"></div>');
		
		$(theClass).wrapInner('<div class="inner"></div>');			// Wrap div around content of outer div.
		var block_count = $(theClass+' .inner').children().size();	// Count number of blocks.
		var block_item = '.'+$(theClass+' .inner').children('div:eq(0)').attr("class");	// Get the class name of repeating blocks.
		
		var looper = 0;												// Initialise variable.
		while (looper < block_count) {								// Loop for number of blocks...
			$(theClass).children('.inner').children(block_item).slice(0,cols).wrapAll('<div class="block-row"></div>');
			looper = looper+cols;	// Set for next row group.
		}
		
		if (item_height == 1) {											// Use if each block has background.
			var largestHeight = 1;										// Initialise variable.
			$(theClass+' .inner .block-row>div').each(function (i) {	// Loop through each block...
				if (parseInt($(this).height()) > largestHeight) {		// If current block is the tallest block yet...
					largestHeight = parseInt($(this).height());			// Set height placeholder to current block height.
				}
			});
			$(theClass+' .inner .block-row>div').css("height", largestHeight);	// Set all blocks to tallest value.
		}
	}
	
	image_reformat();
	
	
	
	
	
	// Fix PNGs for IE6.
	// -----------------------------------------------------------------------------
	$(document).pngFix();
	
	
	
	
	
	// Testimonials anim on home page
	// -----------------------------------------------------------------------------
	$('#testimonial .inner').cycle({
		fx: 'fade', 
		timeout: 5000
	});
	
	
	
	
	
	
	
	function helper_form_text(theid, thetext, theclass) {
		if ( $('#'+theid).val() == '' ) { $('#'+theid).val(thetext); }
		if ( $('#'+theid).val() == thetext ) { $('#'+theid).addClass(theclass); }
	
		$('#'+theid).bind("focus blur", function(event) {
			if ( $('#'+theid).val() == thetext ) {
				$('#'+theid).val('');
				$('#'+theid).removeClass(theclass);
			} else if ( $('#'+theid).val() == '' ) {
				$('#'+theid).val(thetext);
				$('#'+theid).addClass(theclass);
			}
		});
	}
	function helper_form_init(helpers, theclass) {
		for (theid in helpers) {
			if ( $('#'+theid).length > 0 ) {
				helper_form_text(theid, helpers[theid], theclass);
			}
		}
	}

	helpers = new Object();
	helpers.contact_form_1_Name = 'Name';
	helpers.contact_form_1_Email = 'Email';
	helpers.contact_form_1_Phone = 'Phone';
	helpers.contact_form_1_Collection_postcode = 'Collection postcode';
	helpers.contact_form_1_Distance_of_items_to_road = 'Distance of items to road';
	helpers.contact_form_1_Brief_description_of_the_job = 'Brief description of the job';
	helper_form_init(helpers, 'helper');	

	
});


