

(function($){
	
	//function which loads a video into an element
	function placePlayer(sUrl,width,height,id)
	{
		var params = {
				quality: "high",
            	wmode: "transparent"	,
				allowScriptAccess: "always"
			};
			
			var attributes = {
        		id: id  
			};
			
			swfobject.embedSWF(sUrl,id, width, height,"8",null,null, params, attributes);	
	}
	
	$(document).ready(function(){
	
		
		//format mark up
		$('#youtube-video,#youtube-player .thumbs,#thumbs-holder').addClass('js');
		
		//Insert fLash video
        $('a.youtube-video').click(function($e){//click event for links
			$e.preventDefault();
			if($(this).hasClass('youtube-current'))return;
			$('a.youtube-video').removeClass('youtube-current');
			$(this).addClass('youtube-current');
			$('#youtube-video').html($('<div id="video-placeholder"></div>'));
			var sUrl = ($(this).attr('href') && $(this).attr('href').length > 0) ? $(this).attr('href') : null;
			var dims = ($(this).attr('rel') && $(this).attr('rel').length > 0 && $(this).attr('rel').match(/\,/gi) != null) ? $(this).attr('rel').split(',') : null;
			if(sUrl && dims)placePlayer($(this).attr('href'),$(this).attr('rel').split(',')[0],$(this).attr('rel').split(',')[1],'video-placeholder');	
		}).eq(0).click();
		
		setTimeout(function(){
			$('#youtube-player .thumbs').jScrollPane({scrollbarWidth:10, scrollbarMargin:10});
		},500);
		
	});	
			
})(jQuery);
