/* 
   ----------------------------------------------------------------
		jQuery Extensions & Patches
   ----------------------------------------------------------------
*/

$(function(){

/* HOME PAGE ENHANCEMENTS ---------------------------------------------------------------- */

	/* Find and initialise any slideshows (included in content spots) */
	
	if ($('#slideShow').length) {
		var slideShowElement =  $('#slideShow');
		
			
		if ($.browser.msie && $.browser.version == '6.0') {
			//Pick a random slide and show it:
	
			var slides = slideShowElement.children();
			var randomPick = Math.floor(Math.random()*slides.length);
			slides.hide().filter(':eq(' + randomPick + ')').show();

		} else {
		
			//We'll pull some meta data from the rel attribute on the slideShow:
			//this is because we can't include JS in the content spot itself.
			
			var metaData = slideShowElement.attr('rel');
			
			//default config
			var slideShowConfig = {
				duration: 2000,
				transition: 'fade',
				speed: 1000,
				pager:'#slideShowPager .liner'
			}
			
			//An array of the options we can set from the rel
			var availableOptions = ['transition', 'duration', 'speed']; 
			
				for (var i =0; i < availableOptions.length; i++) {
					var pattern = new RegExp(availableOptions[i] + ":([a-z0-9]+)");
					if (pattern.test(metaData)) {
						slideShowConfig[availableOptions[i]] = pattern.exec(metaData)[1];
					}
				} 
			
			//Initialise the cycle with the new options
			slideShowElement.cycle(slideShowConfig);
		}
	}
	
    //This is a workaround for category thumbnail images not being clickable within anchors...
	if ($.browser.msie) {
		$('#categorylister div.imageFrame img')
			.click(function(e){
				document.location = $(this).closest('a').attr('href');
			});
	}
	
	//Set thumbnail heights to be equal:
	/*$('ul.thumbnails', '#pagebody').each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	})*/
	
});

