var video;

$(function() {

	var bPlaying = false;
	
	var wrapper		= $('#videocontrols-wrapper');
	var controls	= $('#videocontrols');
	var panel		= $('#videocontrols-panel');
	
	if($.browser.msie) {
		$(wrapper).addClass('ie');
	}
	
	video = {
	
		panel: panel,
		
		controls: {
		
			button:		$(panel).find('.videocontrols-button'),
			progress:	$(panel).find('.videocontrols-progress'),
			slider:		$(panel).find('.videocontrols-progress-slider'),
			bar:		$(panel).find('.videocontrols-progress-bar'),
			pointer:	$(panel).find('.videocontrols-progress-bar-pointer')
		
		},
		
		update: function(n) {
			video.controls.slider.css('width', n + '%');
			
			if(n == 0) {
				bPlaying = false;
				video.controls.button.removeClass('active');
			}
		}
	
	};
	
	var timer;
	$(wrapper).hover(
		function() {
			if(bPlaying) {
				timer = false;
				
				$(controls).stop(true).animate({
					opacity: 1
				}, 500);
			}
		},
		function() {
			if(bPlaying) {
				timer = true;
				
				setTimeout(function() {
					if(!timer) return false;
					
					$(controls).stop(true).animate({
						opacity: 0
					}, 500);
				}, 1000);
			}
		}
	);
	
	
	video.controls.button.click(function() {
		if(!bPlaying) {
			bPlaying = true;
			$(this).addClass('active');
			player1.sendEvent("PLAY", true);
		} else {
			bPlaying = false;
			$(this).removeClass('active');
			player1.sendEvent("PLAY", false);
		}
	});

});