
var fp;

$(document).ready(function(){

	// LINKS TO SWAP PICTURES
	$('.brandxPictureNav a').click(changeImage);
	$('a#article_image_1').click();

//	// TURN LINKS INTO GRAPHICS
//	$('.replace_flash').media({ });

//	// LOAD VIDEO LINKS INTO FLOWPLAYER VIDEO
//	setFlowplayer();
//	$('a.video').click(changeVideo);
//	$("a.video:first").click();
	
});

//function setFlowplayer() {
//	fp = flowplayer("article_player", "/flash/flowplayer.commercial-3.1.4.swf", {
////		key: '#$3db08959b2043e846be',
//		plugins: {
//			controls: {
//				url: '/flash/flowplayer.controls-3.1.4.swf',
//				backgroundColor: '#141717',
//				backgroundGradient: 'medium',
//				progressColor: '#FF9900',
//				sliderColor: '#444444',
//				buttonOverColor: '#FF9900',
//				volumeSliderColor: '#B7CCCD',
//				bufferColor: '#333333',
//				tooltipTextColor: '#FFFFFF',
//				autoHide: 'always',
//				height: 25,
//				autoPlay: true
//			}
//		},
//		logo: {
//			url: '/images/PA.png',
//			top: 10,
//			right: 10,
//			opacity: 1.0,
//			fullscreenOnly: false,
//			displayTime: 5,
//			fadeSpeed: 3000,
//			linkUrl: 'http://www.pressassociation.com'
//		},
//	clip: {
//		autoPlay: true,
//		autoBuffering: true
//	}});
//}

//function changeVideo() {
//
//	var href = $(this).attr('href');
//	setTimeout(
//		function() {
//			fp.play(href);
//		},
//		50
//	);
//	return false;
//}

function changeImage() {
	var imgs	= $('.brandxPictures img');
	var num		= parseInt($(this).children('span').eq(0).text());
	var link	= $('a#article_image_' + num);
	var img		= $('img#article_image_' + num);
	// set all to same level
	imgs.css('z-index',1);
	// elevate desired image
	img.css('z-index',1 + imgs.size());
	// set the picture number
	$('#pictures .brandxPicturesOf span').text(num);
	// set caption to alt tag of current image
	$('.brandxCaption').html('<p>'+img.attr('alt')+'</p>');
	// set the prev
	var prev = $('#pictures .brandxPictureNav .prev');
	if(num==1) {
		prev.css('visibility','hidden');
	} else {
		prev.css('visibility','visible');
		var a = prev.children('a').eq(0);
		var href = link.prev().attr('href');
		a.attr('href',href);
		var span = a.children('span').eq(0);
		span.text(num - 1);
	}
	// set the next
	var next = $('#pictures .brandxPictureNav .next');
	if(num==imgs.size()) {
		next.css('visibility','hidden');
	} else {
		next.css('visibility','visible');
		var a = next.children('a').eq(0);
		var href = link.next().attr('href');
		a.attr('href',href);
		var span = a.children('span').eq(0);
		span.text(num + 1);
	}
	return false;
}
