var Player={

	init:function() {
		Video.hideAllThumbContentTypes('relatedthumbs');
		Video.hideAllThumbContentTypes('popularthumbs');
		Player.refreshAd();
		Player.paginateLinks();
	},

	refreshAd:function() {
		if ($('#ad_mp')) Dom.del($('#ad_mp'));
		
		oDate=new Date();
		iRand=oDate.getTime();
		
		if (GLBAdSite == '')
			sAdcall='http://oas.absoluteradio.co.uk/RealMedia/ads/adstream_sx.ads/www.absoluteradio.co.uk/player/'+GLBAVSID+'/'+iRand+'@Right';
		else
			sAdcall='http://oas.absoluteradio.co.uk/RealMedia/ads/adstream_sx.ads/www.absoluteradio.co.uk/player/'+GLBAdSite+'/'+GLBAVSID+'/'+iRand+'@Right';
		
		sFrame='<iframe src="'+sAdcall+'" width="300" height="250" marginwidth="0" marginheight="0" frameborder="0" framespacing="0" scrolling="no"></iframe>';
		Dom.add($('#ad_container'),'div',{id:'ad_mp'},'inner_end');
		$('#ad_mp').innerHTML=sFrame;
	},

	love:function(i){
		if (fn_vip()) {
			Ajax.request('/_ajax2/player.php', '&mode=love&id=' + i, {mode:'GET'}, function(s){});
			vr.error.build({
				id:'error_inject',
				html:'Thanks... added to your loved items.',
				icon:'accept',
				alertclass:'alert_accept',
				rejigad:true,
				end:'214,246,190'
			});
		} else {
			vr.error.build({
				id:'error_inject',
				html:'You need to be a VIP to love this item',
				icon:'report',
				alertclass:'alert_error',
				rejigad:true,
				end:'214,246,190'
			});
		}
	},
	
	share:function() {
		var oParent = $('#container').parentNode;
		oParent.style.height = '353px';
		Anim.hide($('#container'));
	},
	
	SkipAd:function(){
		$('#mediaplayer').SkipAd();
	},
	
	selectQuality:function() {
		if (document.quality_form.quality[0].checked) sQuality='sd';
		else sQuality='hd';
		
		Ajax.request(
			'/_ajax2/media_player.php', 
			'&mode=setquality&quality=' + sQuality, 
			{mode:'GET'}, 
			function(s){
				Dom.del($('#video_screenshot'));
				Dom.del($('#bandwidth_detector'));
				s1.addVariable("autoplay","1");
				if (sQuality=='hd') s1.addVariable("hd","hd");
				s1.write('container');
			}
		);
	},
	
	checkBandwidth:function() {
		oDate=new Date();
		iStartTime=oDate.getTime();
		Ajax.request(
			'/_ajax2/media_player.php', 
			'&mode=checkbandwidth', 
			{mode:'GET'},
			function(s){
				oDate=new Date();
				iEndTime=oDate.getTime();
				iPut=(((46453*8)/1024)/((iEndTime-iStartTime)/1000))*.90;
				
				if (iPut<200) document.quality_form.quality[0].checked=true;
				else document.quality_form.quality[1].checked=true;
				
				Dom.del($('#bandwidth_detecting'));
				$('#container').style.display='';
				
			}
		);
	},
	
	playSDVideo : function()
	{
		Dom.del($('#video_screenshot'));
		Dom.del($('#bandwidth_detector'));
		s1.addVariable("autoplay","1");
		s1.write('container');
		
		Ajax.request(
			'/_ajax2/media_player.php', 
			'&mode=setignorecookie', 
			{mode:'GET'}
		);
	},
	
	ScrollToComment : function()
	{
		var input = $('#community_content');
		var top = Dom.pos(input, 'top');
		window.scrollTo(0, top);
		$('#addcomment').focus();
	},
	
	addComment:function() {
		sComment=$('#addcomment').value;
		Ajax.request(
			'/_ajax2/media_player.php', 
			'&mode=addcomment&id='+GLBAVSID+'&addcomment='+sComment,
			{mode:'POST',returnmode:'JSON'},
			function(o){
				if (o.error==0) {
					$('#addcomment').value='';
					$('#comments').innerHTML='Comments ('+o.totalcomments+')';
					Player.displayComments(1);
					Player.refreshAd();
				}
			}
		);
		
		return false;		
	},
	
	paginateLinks:function() {
		if ($('#paginate_container')) {
			aLinks=$('#paginate_container:a');
			for (i=0;i<aLinks.length;i++) {
				sLink=aLinks[i].href;
				sLink=sLink.substr(sLink.indexOf('page')+4);
				iPage=sLink.substr(0,sLink.indexOf('.html'));
				aLinks[i].href='javascript:Player.displayComments('+iPage+');';
			}
		}
	},
	
	displayComments:function(iPage) {
		Ajax.request(
			'/_ajax2/media_player.php', 
			'&mode=displaycomments&id='+GLBAVSID+'&page='+iPage,
			{mode:'GET',returnmode:'JSON'},
			function(o){
				$('#comments_container').innerHTML='';
				
				for (iComment=0;iComment<o.length-1;iComment++) {
					oComment=Dom.add($('#comments_container'),'div',{id:'shout_'+o[iComment].commentid},'inner_end');
					oComment.className='quickquote_outer mTop';

					sHTML='<a href="/vip/profile/'+o[iComment].author+'/">';
					sHTML+='<img src="http://www.absoluteradio.co.uk/images/users/'+o[iComment].author+'/lg/" width="48" height="48" class="borderpagepolaroid_medium floatLeft"></a>';
					sHTML+='<span class="quickquote_inner highlight"><span class="quickquote_speech highlight"></span><a href="/vip/profile/'+o[iComment].author+'/">'+o[iComment].author+'</a> said:';
					sHTML+='<blockquote class="quickquote_quote">'+o[iComment].comment+'</blockquote></span> ';
					sHTML+='<span class="tieDown"></span></div>';
					
					oComment.innerHTML=sHTML;
				}
				$('#paginate_container').innerHTML=o[o.length-1].pagination;
				Player.refreshAd();
			}
		);
	},
	
	hideTranscript : function() {
		Dom.css($('#transcript-hidden'), 'hide_me');
		Dom.add($('#transcript-hidden'), 'div', {id:'load-transcript', nodeClass:'load-more'}, 'outer_end');
		$('#load-transcript').innerHTML = '<a href="#" onclick="return Player.showTranscript();">Read more</a>';
	},
	
	showTranscript : function() {
		Dom.css($('#transcript-hidden'), '');
		Dom.del($('#load-transcript'));

		return false;
	}
};
