$(function(){$("ul#ticker01").liScroll();});
// transparent fix
/* $(document).ready(function(){$(document).pngFix();}); */ 

$(document).ready(function() {
	if ( $("#accordion").length ) {
		$("#accordion").accordion({
			autoHeight: false,
			collapsible: true,
			active: false
		});
	}

	//###   Remove landing page tag if present, for 404 page ###
	if ( $("#inner_left_full h1").html() == "Error 404" ) {$("#container").removeClass("landing-page");}

	//###   Homepage Slideshow   ###
	if ( $("#banner").length ) {
		$("#banner").cycle({
			timeout:		8000,
			pause:		1,
			random:		0,
			prev:		'#slideshow-back', 
			next:		'#slideshow-forward',
			cleartypeNoBg:	true,
			speed:		200
		});
		$("#slideshow-stop").click(function() {
			$("#banner").cycle("toggle");
			return false;
		});
	}

	//###   Sporting Calendar Slideshow   ###
	if ( $("#sporting-calendar").length ) {
		$("#sporting-calendar").cycle({
			timeout:		0,
			prev:		'#calendar-controls .previous', 
			next:		'#calendar-controls .next'
		});
	}

	//###   Even up the boxes on the content tables   ###
	$(".left div.half-box").each(function(index, value) {
		var $otherBox = $(this).parent().next().children("div.half-box");
		if ($otherBox.height() > $(this).height())
			$(this).height( $otherBox.height() );
		else
			$otherBox.height( $(this).height() );
	});

	//###   Even up the tabs in ImageLibrary & And add interaction to enlarge   ###
	if ( $("#library-header").length ) {
		var totalWidth = 798;
		var individualWidth = (totalWidth / $("#library-header .tabs li").length) - 24;
		if (individualWidth > 235)
			individualWidth = 235;
		$("#library-header .tabs li em").width(individualWidth);

		$(".info .enlarge a").click(function() {
			$(this).parent().parent().parent().next().children("a").click();
			return false;
		});
	}
	//###   Clickable banners   ###
	if ( $("#sub_banner").length ) {
		var link = $("#sub_banner").attr("rel");
		if (link != "" && link != undefined) {
			$("#sub_banner").click(function() {
				top.location.href = link;
			});
		}
	}
	$("#banner").children().each(function() {
		var child = $(this);
		var link = child.attr("rel");
		if (link != "" && link != undefined) {
			child.click(function() {
				top.location.href = link;
			});
		}
	});


});

$(document).ready(function() {
	var currentNum = $("#current-fact").html();
	if ( $("#current-fact").length ) {
		if (currentNum == "")
			 $("#current-fact").html(1);
		$("#did_you_know_top div p:nth-child(" + $("#current-fact").html() + ")").fadeIn("slow");
	}
	$("#next-fact").click(function() {
		$("#did_you_know_top div p:nth-child(" + $("#current-fact").html() + ")").hide();
		var totalFacts = $("#did_you_know_top div p").length;
		currentNum = $("#current-fact").html();
		currentNum++;
		if (currentNum > totalFacts)
			currentNum = 1;
		$("#current-fact").html(currentNum);
		$("#did_you_know_top div p:nth-child(" + $("#current-fact").html() + ")").fadeIn("slow");
	});

	//###############   PRETTYPHOTO, Zoom functionality throughout content   ###############
	if ($("a[rel^='prettyPhoto'] img").length) {
		$("a[rel^='prettyPhoto']")
			.prettyPhoto({
				showTitle: true,
				overlay_gallery: false,
				allow_resize: true,
				theme: "light_rounded",
				counter_separator_label: " of "
			})
			.append('<img src="/themes/site_themes/sportech/images/zoom.png" alt="" class="zoom" />')
			.each(function() {
				$(this).hover(function() {$(this).children('.zoom').fadeIn(250);}, function() {$(this).children('.zoom').fadeOut(250);});
			});

	} else {
		$("a[rel^='prettyPhoto']").prettyPhoto({
			showTitle: true,
			allow_resize: false,
			overlay_gallery: false,
			default_width: 900,
			default_height: 300,
			theme: "light_rounded",
			counter_separator_label: " of "
		});
	}

	//###############   Sports feed - box close button   ###############
	$('#live_sports_feed .close').click(function() {
		$("#live_sports_feed > div").toggle(0, function() {
			if ( $("#live_sports_feed").height() == 77 )
				$("#live_sports_feed").height(21);
			else
				$("#live_sports_feed").height(77);
		});
	});
});

$(document).ready(function() {
	//###   History Timeline ImageFlow   ###
	if ( $("#historyImageFlow").length ) {
		var historyTimeline = new ImageFlow();
		historyTimeline.init({
			ImageFlowID: 'historyImageFlow',
			circular: true,
			slider: false,
			opacity: true,
			imageFocusM: 1.25,		/* Factored size of Central (main) Image (lower is smaller) */
			imagesM:0.7,			/* Factored size ALL images (lower is larger): Ideally 0.7 */
			imageFocusMax: 1,		/* Number of images on each side */
			opacityArray:[10,4,2],		/* Make the images to the outside fade out - 1st = main image */
/*			reflectionP: 0.5,			 Makes the background images appear higher than the baseline (changing the number doesn't seem to do anything?!?) - comment out to return to baseline */
			xStep:80,				/* Gap between each additional image in the background */
			imagesHeight:.93,		/* Height of the containing box: 1.02 for baseline */
			imageCursor:'pointer'		/* Hand cursor for image mouseover */
		});

		$("#history-thumbs li").click(function() {
			historyTimeline .glideTo( $("#history-thumbs li").index($(this)) );
		});
//		$("#historyImageFlow .images").click(function() {
//			alert("hello");
//		});

		//###   Add the bottom of the History information panel   ###
		$("#historyImageFlow .caption").after('<span class="bottom"></span>');

		//###
		$("#history-thumbs img").each(function(index) {
			var captionText = $("#historyImageFlow .images img:eq("+index+")").attr("longdesc");
			var tempArray = captionText.split("<h2>");
			tempArray = tempArray[1].split("</h2>");
			$(this).next("p").html(tempArray[0]);
		});
	}
});

function load() {
	if ($("#map").length > 0) {
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("map"));
		        map.setCenter(new GLatLng(51.515541,-0.15244), 15);
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			test = '<p style="font-size:8pt;"><strong>Sportech plc </strong><br> 101 Wigmore Street<br>London<br> W1U 1QU</p>';
			map.openInfoWindowHtml(map.getCenter(), test);
		}
	}
}

