/**
 * Animation Player
 */
var MODE_STREET = 1;
var MODE_MAP = 2;
var MODE_CANVAS = 2;

var Player = {
	playingAction: null,
	playing: false,
	execHead: function (){this.head();},
	execStop: function (){this.pause();},
	execPlay: function (){this.play();},
	execPeek: function (){this.peek();},
	execNext24h: function (){
		urlInfo.next24h();
	},
	execPrev24h: function (){
		urlInfo.prev24h();
	},
	execOrbitMapWorld: function () {
		wSatMap.hide();
		wWorldMap.show();
	},
	execOrbitMapLocal: function () {
		wWorldMap.hide();
		wSatMap.show();
	},
	setIndicator: function () {
		var positionCount = 1;
		if (SatMap.getSelectedSat() && SatMap.getSelectedSat().getSelectedSchedule()) positionCount = SatMap.getSelectedSat().getSelectedSchedule().positions.length;
		$('indicator').style.width = ((scheduleIndex*1.0/Math.max(1,positionCount-1)) *310) + 'px';
	},
	head: {
		
	},
	reset: function (){
		if (Player.playingAction)
			clearInterval(Player.playingAction);
		Player.playingAction = null;
		this.playing = false;
		scheduleIndex = 0;
		this.setIndicator();
		wSatMap.reset();
	},
	stop: function (){
		clearInterval(Player.playingAction);
		Player.playingAction = null;
		this.playing = false;
	},
	play: function (){
		this.playing = true;
		showDetail();
		this.execOrbitMapLocal();
		if (Player.currentMode != MODE_STREET) {
			SatMap.checkStreet(map.getCenter());
		}
		else {
			this.execStartPlay();
		}
	},
	execStartPlay: function () {
		if (this.playingAction == null) {
			Player.playingAction = setInterval(function(){
				if (!Player.playing) return;
				SatMap.getSelectedSat().see(scheduleIndex);
				scheduleIndex += 1;
			}, 300);
		}
	},
	currentMode: MODE_STREET,
	peek: function () {
		SatMap.getSelectedSat().seePeek();
	},
	head: function (){
		scheduleIndex = 0;
		SatMap.getSelectedSat().see(scheduleIndex);
	},
	pause: function (){
		this.playing = false;
	},
	execSaveHome: function (){ urlInfo.saveHome() },
	execGotoHome: function (){ urlInfo.gotoHome() },
	execEarthFullScreen: function (){ wEarth.fullScreen()},
	execExitEarthFullScreen: function (){ wEarth.exitFullScreen()},
	execShowUrl: function (){ 
		$('inputUrl').value = urlInfo.getUrl();
			
		var areaOffset = Element.cumulativeOffset($('showUrlIcon'));
	    $('linkDialog').style.top = (areaOffset[1]-10) + 'px';
	    $('linkDialog').style.left = (areaOffset[0]) + 'px';
		Effect.Appear($('linkDialog'),{direction:'top-left'});
	},
	execHideUrl: function () {$('linkDialog').hide()},
	hide: function (){Element.hide('controlPanel')},
	show: function (){Effect.SlideDown('controlPanel',{duration: 0.5});}
}
var MenuPanel = function () {
	this.modeList = false;
	this.modeDetail = true;
	this.modeTwitter = false;
}
MenuPanel.prototype = {
	execListMode: function (){
		this._turnOffAll();
		this.modeList = true;
		wEarth.hide();
	    $('satDetailPanel').hide();
	    $('satListPanel').show();
		
		wSatMap.escape();
		wWorldMap.escape();
		wEarth.hide();
		
		$('tabSatDetail').className = '';
		$('tabSatSelect').className = 'selected';
	},
	execDetailMode: function (){
		this._turnOffAll();
		this.modeDetail = true;
		var closeIcon = $('buttonCloseStreet');
		wEarth.show();
	    $('satListPanel').hide();
	    $('satDetailPanel').show();
		
		wSatMap.restore();
		wWorldMap.restore();
		
		$('tabSatDetail').className = 'selected';
		$('tabSatSelect').className = '';
		wEarth.show();
	},
	execTwitterMode: function (){
		this._turnOffAll();
		this.modeTwitter = true;
	},
	_turnOffAll: function () {
		this.modeList = false;
		this.modeDetail = false;
		this.modeTwitter = false;
	},
	isCurrentModeList: function (){ return this.modeList },
	isCurrentModeDetail: function (){ return this.modeDetail },
	isCurrentModeTwitter: function (){ return this,modeTwitter }
};
