$(function() {

	$('a.video_link').each(checkvideo);
	flashReady();
});

function checkvideo()
{
	$(this).data('href',$(this).attr('href'));
	$(this).removeAttr('target');
	$(this).attr('href','javascript:void(0);');
	$(this).click(loadvideo);	
}

function loadvideo()
{
	window.open($(this).data('href'), 'video_popup', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=740,height=640,left = 0,top = 0');
}

function flashReady()
{
	$('#showcase-films li').each(function() {
		$(this).children('a').attr('rel', $(this).attr('class').match(/\d+/));
		$(this).children('a').addClass('poster_link');
		$(this).children('a').attr('href', 'javascript:void(0);');
		$(this).children('a').click(flashClick);
		
			//alert($(this).attr('class').match(/\d+/));
	});	
}

function flashClick()
{
	//if (document.getElementById("post-images")) { 
	//	document.getElementById("post-images").flashJumpToID($(this).attr('rel'));
	//}
	
	$('a.video_link').each(function() { $(this).unbind(); });
	
	$('#showcase-films li').removeClass('current_page_item');
	$(this).parent().addClass('current_page_item');
	
	getFlashMovie('postimages').flashClick($(this).attr('rel'));
	var json = $.parseJSON(textElements);
	for (var a=0; a<json.elements.length; a++)
	{
		if (json.elements[a].id==$(this).attr('rel'))
			$('#film_content').html('<h1>'+json.elements[a].title+'</h1>'+json.elements[a].content+'<br /><br /><a class="video_link" rel="video" target="_blank" href="http://www.itsmyshout.co.uk/videoplayer.php?filename='+json.elements[a].videolink+'"><img height="20" width="133" alt="Watch Film" title="Watch Film" src="cms/wp-content/uploads/2010/04/hn-watch-film.png"></a>');	
	}
	$('a.video_link').each(checkvideo);
	
	
}

function getFlashMovie(movieName) {   
	var isIE = navigator.appName.indexOf("Microsoft") != -1;   return (isIE) ? window[movieName] : document[movieName];  
}  

//function formSend() {   var text = document.htmlForm.sendField.value;   getFlashMovie("ExternalInterfaceExample").sendTextToFlash(text);     }    function getTextFromFlash(str) {   document.htmlForm.receivedField.value = "From Flash: " + str;   return str + " received";  }
