	function slideSwitch() {
		var $active = $('#slideshow IMG.active');

		if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

		var $next =  $active.next().length ? $active.next()
			: $('#slideshow IMG:first');

		$active.addClass('last-active');

		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
			});
	}
$(document).ready(function(){
	$('.youtube_video').click( function() {
		window.location = $('#webroot').val()+'index.php/our-stories/our-videos?video='+$(this).children().attr('src');
	
	});
	
	$('#results_tab').click( function() {
		$('#league_results_tabs').attr('style', 'background-image: url(/images/league_results_1.png);');
		$(this).removeClass('linked');
		$('#scorers_tab').addClass('linked');
		$('#cards_tab').addClass('linked');	
		$('#results_table').show();		
		$('#scorers_table').hide();	
		$('#cards_table').hide();	
	});
	$('#scorers_tab').click( function() {
		$('#league_results_tabs').attr('style', 'background-image: url(/images/league_results_2.png);');
		$(this).removeClass('linked');
		$('#results_tab').addClass('linked');
		$('#cards_tab').addClass('linked');
		$('#results_table').hide();		
		$('#scorers_table').show();	
		$('#cards_table').hide();
	});
	$('#cards_tab').click( function() {
		$('#league_results_tabs').attr('style', 'background-image: url(/images/league_results_3.png);');
		$(this).removeClass('linked');
		$('#results_tab').addClass('linked');
		$('#scorers_tab').addClass('linked');
		$('#results_table').hide();		
		$('#scorers_table').hide();	
		$('#cards_table').show();	
	});

	// Execute this after the site is loaded.
	$(function() {
		// Find list items representing folders and turn them
		// into links that can expand/collapse the tree leaf.
		$('#res li.folder').each(function(i) {
			// Temporarily decouple the child list, wrap the
			// remaining text in an anchor, then reattach it.
			var sub_ul = $(this).children().remove();
			$(this).wrapInner('<a/>').find('a').click(function() {

				if($(this).attr('style') == 'color: black;'){
					$(this).attr('style', 'color: 0099cc;');
					$(this).parent().attr('style', 'background-image: url(/images/arrow2.jpg);');
				}
				else {
					$(this).attr('style', 'color: black;');
					$(this).parent().attr('style', 'background-image: url(/images/arrow3.jpg);');
				}
				
				//$(this).parent().parent().attr('style', 'border-bottom: 1px dashed #999999;');
				sub_ul.toggle();
				
			});
			$(this).append(sub_ul);
		});

		// Hide all lists except the outermost.
		$('#res ul ul').hide();
	});
	



		$(function() {
		
			if ( !$('#mainlevelmainnav li:eq(0)').hasClass( 'mainlevel_currentmainnav' )) { 
				$('#mainlevelmainnav a.mainlevelmainnav').width('190px');
				$('#mainlevelmainnav a.mainlevel_activemainnav').width('190px');
				$('#mainlevelmainnav a.mainlevel_currentmainnav').width('190px');
			}
			if ( $('.sublevelmainnav').length ) { 
					
					$('.sublevelmainnav a').width('180px');
					$('.sublevel_activemainnav a').width('180px');
					$('.sublevel_currentmainnav a').width('180px');
					
			}
			if ( $('.sublevel_activemainnav .sublevel_currentmainnav').length || $('.mainlevel_activemainnav .sublevel_currentmainnav .sublevelmainnav').length ){ 
					
					$('.sublevelmainnav a').width('180px');
					$('.sublevel_activemainnav a').width('180px');
					$('.sublevel_currentmainnav a').width('180px');
					$('.sublevel_currentmainnav .sublevelmainnav a').width('170px');
					$('.sublevel_activemainnav .sublevelmainnav a').width('170px');
					$('.sublevel_activemainnav .sublevel_currentmainnav a').width('170px');
					
					
			}
	});


	$(function() {
		setInterval( "slideSwitch()", 5000 );
	});

	$("a.single_image").fancybox();

		$('.next-image').click( function() {
			$( '#'+$(this).parent().parent().attr("id")+' li' ).hide();
			//alert($(this).parent().parent().attr("id"));
			$( '#'+$(this).parent().parent().attr("id")+' li:eq(0)' ).clone(true).appendTo('#'+$(this).parent().parent().attr("id") + ' ul');
			$( '#'+$(this).parent().parent().attr("id")+' li:eq(0)' ).remove();
			$( '#'+$(this).parent().parent().attr("id")+' li:eq(0)' ).show();			
			$( '#'+$(this).parent().parent().attr("id")+' li:eq(1)' ).show();
			$( '#'+$(this).parent().parent().attr("id")+' li:eq(2)' ).show();
			
			//alert($(this).parent().parent().attr("id"));
			
			return false;
		});

		$('.prev-image').click( function() {
			$( '#'+$(this).parent().parent().attr("id")+' li' ).hide();
			
			$( '#'+$(this).parent().parent().attr("id")+' li:last').clone(true).prependTo('#'+ $(this).parent().parent().attr("id") + ' ul');
			$( '#'+$(this).parent().parent().attr("id")+' li:last').remove();
			$( '#'+$(this).parent().parent().attr("id")+' li:eq(0)' ).show();			
			$( '#'+$(this).parent().parent().attr("id")+' li:eq(1)' ).show();
			$( '#'+$(this).parent().parent().attr("id")+' li:eq(2)' ).show();

			return false;
		});

	$('.galcon').each(function(index) {
		$gal = $(this).attr('value');
		$id = $(this).attr('id');
		
	
	$(this).jflickrfeed({
		limit: 20,
		qstrings: {
			id: $gal
		},//<a href="{{image_b}}"></a> #container_'+$('#artid').val()+' 
		itemTemplate: '<li><a href="" class="bordered_image_link"><img src="../../phpthumb/phpThumb.php?src={{image_b}}&w=120&h=80&zc=1" alt="<strong>" class="resizeme gallery_image" name="{{image_b}}" value="{{image_b}}" style="border:2px solid white;" title="{{title}}" tags="{{tags}}" description="{{description}}"/></a></li>'
	}, function(data) {
		$(this).children('li').hide();
		$(this).children('li:lt(3)').show();
		//$(".resizeme").aeImageResize({height: 135, width: 135});
		if($(document).getUrlParam("imgsrc")==null) {
			//alert($('.galcon img').eq(0).attr('name'));
			$('#main_image_holder').empty();
			$('#main_image_holder').append('<img src="../../phpthumb/phpThumb.php?src='+$('.galcon img:eq(0)').attr('name')+'&w=461&h=327" id="main_image" />');
			$('#main_image_holder').append('<div style="text-align:left;margin-top:10px;"><p>'+$('.galcon img:eq(0)').attr('alt')+'</p></div>');
			$('#main_text_holder').empty();
			$('#main_text_holder').append('<p class="blue_title" style="font-size:18px;margin-top:15px;margin-bottom:10px;">'+$('.galcon img:eq(0)').attr('title')+'</p>');
			$('#main_text_holder').append('<p>'+$('.galcon img:eq(0)').attr('description')+'</p>');
			$('#main_text_holder').append('<div style="border-top:1px dashed #999999; border-bottom:1px dashed #999999;padding-top:20px;padding-bottom:20px;margin-top:20px;"><img src="../../../images/tags.png" style="float:left;margin-right:10px;" /><p class="blue_title">'+$('.galcon img:eq(0)').attr('tags')+'</p></div>');
		} else {
			$('#main_image_holder').empty();
			$('#main_image_holder').append('<img src="../../phpthumb/phpThumb.php?src='+$(document).getUrlParam("imgsrc")+'&w=461&h=327" id="main_image" />');
			/*$('#main_image_holder').append('<div style="text-align:left;margin-top:10px;"><p>'+$('.galcon img:eq(0)').attr('alt')+'</p></div>');
			$('#main_text_holder').empty();
			$('#main_text_holder').append('<p class="blue_title" style="font-size:18px;margin-top:15px;margin-bottom:10px;">'+$('.galcon img:eq(0)').attr('title')+'</p>');
			$('#main_text_holder').append('<p>'+$('.galcon img:eq(0)').attr('description')+'</p>');
			$('#main_text_holder').append('<div style="border-top:1px dashed #999999; border-bottom:1px dashed #999999;padding-top:20px;padding-bottom:20px;margin-top:20px;"><img src="../../../images/tags.png" style="float:left;margin-right:10px;" /><p class="blue_title">'+$('.galcon img:eq(0)').attr('tags')+'</p></div>');*/
		}
			
		$( '.resizeme').click( function() {
		//alert($(this).parent().parent().parent().attr("id"));
			$('#main_image_holder').empty();
			$('#main_image_holder').append('<img src="../../phpthumb/phpThumb.php?src='+$(this).attr('name')+'&w=461&h=327" id="main_image" />');
			$('#main_image_holder').append('<div style="text-align:left;margin-top:10px;"><p>'+$(this).attr('alt')+'</p></div>');
			//#$('#' + $(this).parent().parent().parent().attr("id") +' img').attr('style','border:2zpx solid white;');
			
			//$('.gallery_image').attr('style','border:2px solid white');
			//$(this).attr('style','border:2px solid red');
			//$("#main_image").aeImageResize({height: 520, width: 520});
			//alert($(this).attr('alt'));
			
			$('#main_text_holder').empty();
			$('#main_text_holder').append('<p class="blue_title" style="font-size:18px;margin-top:15px;margin-bottom:10px;">'+$(this).attr('title')+'</p>');
			$('#main_text_holder').append('<p>'+$(this).attr('description')+'</p>');
			$('#main_text_holder').append('<div style="border-top:1px dashed #999999; border-bottom:1px dashed #999999;padding-top:20px;padding-bottom:20px;margin-top:20px;"><img src="../../../images/tags.png" style="float:left;margin-right:10px;" /><p class="blue_title">'+$(this).attr('tags')+'</p></div>');
			
			return false;
		}); 


		

	});
	});
	
	
	$('#flickr_widget').jflickrfeed({
		limit: 6,
		qstrings: {
			id: '16835679@N06'
		},
		itemTemplate: '<a href="http://www.flickr.com/photos/shootback/" target="_blank"><img src="{{image_s}}" alt="{{title}}" style="padding-left:6px;padding-bottom:6px;margin:5px;"/></a>'
	}, function(data) {
		$('#flickr_widget img').hide();
		$('#flickr_widget img:lt(6)').show();
	});
	

	$('.frontgalcon').each(function(index) {
		$gal = $(this).attr('value');
		
		$('#frontpage_snapshots').jflickrfeed({
			limit: 20,
			qstrings: {
				id: $gal
			},//<a href="{{image_b}}"></a>
			itemTemplate: '<li><a href="'+$('#webr').val()+'index.php?option=com_content&view=article&id=50&Itemid=58&gallerytag=shootback&imgsrc={{image_b}}" class="bordered_image_link"><img src="../../phpthumb/phpThumb.php?src={{image_b}}&w=234&h=135&zc=1" alt="{{title}}" style="border:2px solid white;" class="snapshots" value="{{image_b}}" /></a></li>'
		}, function(data) {
			$('#frontpage_snapshots li').hide();
			$('#frontpage_snapshots li:lt(2)').show();
			//$(".snapshots").aeImageResize({height: 150, width: 300});

			
			
			//$( '.snapshots').click( function() {
			//	
			//	alert($(this).attr('alt'));
			//	return false;
			//});

			$( '#next-image').click( function() {
				$( '#frontpage_snapshots li' ).hide();
				
				$("#frontpage_snapshots li:eq(0)").clone(true).appendTo("#frontpage_snapshots");
				$("#frontpage_snapshots li:eq(0)").remove();
				$( '#frontpage_snapshots li:eq(0)' ).show();			
				$( '#frontpage_snapshots li:eq(1)' ).show();
				
				
				return false;
			});

			$( '#prev-image').click( function() {
				
				$( '#frontpage_snapshots li' ).hide();
				
				$("#frontpage_snapshots li:last").clone(true).prependTo("#frontpage_snapshots");
				$("#frontpage_snapshots li:last").remove();
				$( '#frontpage_snapshots li:eq(0)' ).show();			
				$( '#frontpage_snapshots li:eq(1)' ).show();
				

				return false;
			});
			
		});
	});

});
