
$().ready(function() {
	
	//full screen informant
	$('.nqtfullscreen').live('click', function() {
		alert($(this).attr('title'));
		return false;
	});
	
	if ($('#nqtvideo').length > 0) {
	
		var mediaplayer = $f("nqtvideo", {src: baseurl + "/../plugins/flowplayer/etc/swf/flowplayer.swf", wmode: 'opaque'}, {
			// configure both players to use rtmp plugin 
			clip: { 
				autoPlay: true,
				 // all clips come from the same location
				baseUrl: baseurl + "/../plugins/nqt/data/flv/",
				onResume: function()  {
					if (!this.isFullscreen()) {
						this.toggleFullscreen();		
					}				
				}
			 }, 
			// here is our rtpm plugin configuration 
			plugins: {  
				controls: null
			} 
			// install HTML controls inside element whose id is "hulu"
		}).controls('nqtplayer');	
		
		$('#global .video-queue .video a').unbind('click').live('click', function() {
			
			var currentIndex = $(this).parent().index() -1 ;
			if ( _current > currentIndex )
			{
				if (_current - 1 < -1) return false;
				_current = _current - 1;
				_queuelist();
				
				$(".video-carousel").animate({
					marginLeft : "+=143"
				}, 300);
			}
			else if ( _current < currentIndex )
			{
				if (_current + 1 > $('.video-queue .video').length-2) return false;
				
				_current = _current + 1;
				_queuelist();
				
				$(".video-carousel").animate({
					marginLeft : "-=143"
				}, 300);
			}
			
			$("#nqtvideo").css('background', 'url('+ $(this).attr('snapshot') +') no-repeat center center');
			
			//unload player first
			if (mediaplayer.isLoaded()) {
				mediaplayer.unload();
			}
			
			//update clip url
			mediaplayer.getClip(0).update({
				url: $(this).attr("href")
			});
			
			//information
			$.get($(this).attr('info'), function(msg) {
				$('#col2').html(msg);
				$('.raty').each(function () {
					   el = $(this);
					   var _hints = $(el).attr('hints').split('|');	
					   if ($.trim($(this).html()) == '') {
						   $(this).raty({
								path: baseurl + '/../plugins/nqt/etc/images/rating/',
								start: $(el).attr('rate'),
								hintList: _hints,
								onClick: function(score) {
									this.readOnly = true;
									$.ajax({
										url: this.attr('url'),
										data: 'score=' + score,
										type: 'post'
									});
								}
							});
					   }
				});
			});
			
			//rating
			$.get($(this).attr('rating'), function(msg) {
				$('#nqtrating').html(msg);
			});
			
			return false;
		});
		
		//show informations
		if ($.trim($('#col2').html()) == '') {
			$('.video-queue .video a').eq(_current).click();
		}

		$f("nqtvideo").onStart(function() {
			if ($('.video-queue .video a.selected').attr('stats')) {
				//add statistics
				$.get($('.video-queue .video a.selected').attr('stats'));
			}
		});
		
		$f("nqtvideo").onFinish(function() {
			mediaplayer.unload();
		});
	}
});
