jQuery.noConflict();


(function($){
jQuery(document).ready(function($){
		
	$('.gallery_list ul li:odd').addClass('odd gallist_row');
	$('table tr:odd').addClass('odd');
		
	var sectionstyles = 
	{
		brightblue: ['whats-on'],
		pink: ['families'],
		blue: ['online-exhibitions'],
		purple: ['collections'],
		green: ['learning'],
		red: ['history-centre'],
		orange: ['herbert-media']
	};
	

	$('#top_menu li, .sidemenu li, .sitemap li.selected, .Asitemap li, body.page_home #maincontent ul li').each(function()
	{
		$this = $(this);
		
		var segments = $('a',$this).attr('href').split('/').reverse();
		$.each(segments, function(i,val){
			var style = '';
			$.each(sectionstyles, function(iStyle,valStyle){
				if(val.indexOf(valStyle)!==-1) style = iStyle;
			});
			
			if(style!=='')
			{
				$this.addClass(style);
				$this.bind('click',function(){location = link;}).css('cursor','pointer');
				if($this.is('#maincontent li')) $this.bind('click',function(){location = link;}).css('cursor','pointer');

				//only want to do this once so prevent further iterations
				return false;		
			}
		});



/*
		jQuery.each(sectionstyles, function(k,val){
			var link = $('a',$this).attr('href');
			if(link.indexOf('/'+val)!==-1 && !$this.is('.brightblue,.pink,.blue,.purple,.green,.red,.orange')) 
			{
				$this.addClass(k);
				$this.bind('click',function(){location = link;}).css('cursor','pointer');
			}
		});
*/
		
	});	


	$('#side_bar li').has('img').not('#share li').each(function()
	{
		$this = $(this);
		
		var segments = $('a',$this).attr('href').split('/').reverse();
		$.each(segments, function(i,val){
			var style = '';
			$.each(sectionstyles, function(iStyle,valStyle){
				if(val.indexOf(valStyle)!==-1) style = iStyle;
			});
			
			if(style!=='')
			{
				$this.addClass(style);
				//var matchingmainlink = $('#top_menu li a').filter(function(){return val.indexOf($(this).attr('href'))!==-1;}).eq(0);
				var $matchingmainlink = $('#top_menu li.'+style+' a');
				var labelText = $matchingmainlink.eq(0).text();
				var labelColor = $matchingmainlink.css('color');
				//console.log('labelText:'+labelText);
				$('a img',$this).before($('<span class="cat_label" style="max-width:106px;display:block;padding:1px 2px;color:white;position:absolute;background-color:'+labelColor+'">'+labelText+'</span>'));	
				
				//only want to do this once so prevent further iterations
				return false;		
			}
		});


/*
		jQuery.each(sectionstyles, function(k,val){
			
			if($('a',$this).attr('href').indexOf(val+'/')!==-1 && !$this.is('.brightblue,.pink,.blue,.purple,.green,.red,.orange')) 
			{
				$this.addClass(k);
				var labelText = $('#top_menu li a[href*='+val+']').eq(0).text();
				var labelColor = $('#top_menu li a[href*='+val+']').css('color');
				$('a img',$this).before($('<span class="cat_label" style="max-width:106px;display:block;padding:1px 2px;color:white;position:absolute;background-color:'+labelColor+'">'+labelText+'</span>'));
			}
		});
*/

		
	});	
	
	
});
})(jQuery);