// <Class definitions>
var System = new Class({
	os: null,
	bandwidth: null,
	scheduler: null,
    player: null,
    timer: null,    	
    eventHandlers: null,
    events: null,
    frames: null,
    categories: null,
    	
    currentCategoryId: -1,
    currentVideolistId: -1,
    currentVideoId: -1,
    fastPlay: false,
    fastRev: false,
    isSoundOn: true,
    freeNavigation: false,
    currentClipIndex: -1,
    currentContentId: -1,
    currentMainContentId: -1,
    currentPushUrlIndex: null,
    currentTab: null,
    stopController: false,
    isTemporaryPlaylist: false,
    reloadOnStop: true,
    backToSchedule: true,
    scheduleFrameToUpdate:'schedule',
    defaultScheduleId: -1,
    singleScheduleFrame: false,
    
    webcast: null,
    
    playerConfig: null,
    
    reloadParams: null,
    
    styleInfo:null,
    
    listeners:null,

	noClickResetTimer: null,
	noClickResetDuration: null,
	noLoopForSchedule:false,
	
	_startSearchPerformed: false,
	_searchPerformed: false,
	_isSearchTab: false,
	_videoIndex: -1,
	_videoIsClickt: true,
	_leavingStartIndex: false,
	_startSitemapIndex: false,
    
 	initialize: function(timer){
 		this.os = browser_getPlatform();
    	this.eventHandlers = new Hash();
    	this.events = new Array();
    	this.frames = new Hash();
    	this.categories = new Array();
    	this.currentPushUrlIndex = new Hash();
    	this.styleInfo = new Hash();
    	this.playerConfig = new Object();
    	
    	this.webcast = new Object();
    	this.webcast.lastPushed = new Hash();
    	this.webcast.lastPushedType = new Hash();
    	this.webcast.stopPush = new Hash();
    	
    	this.webcast.pushOnDemandFrame = new Array();
    	this.webcast.pushOnDemandObject = new Array();
    	this.webcast.pushOnDemandObjectType = new Array();
    	this.webcast.pushOnDemandTime = new Array();
    	
	    this.webcast.popupSlideWindow = new Hash();
	    this.webcast.popupSlideWidth = new Hash();
	    this.webcast.popupSlideHeight = new Hash();
	    
	    this.reloadParams = new Object();
	    this.reloadParams.names = new Array();
	    this.reloadParams.values = new Array();
    	
    	this.listeners = new Array();
    	this.timer = timer;
    	if ( $type(this.timer) == 'object' ) {
    		timer.go();
    	}
	},
		
	addListener: function(listener){
		this.listeners.push(listener);
	},
  
  
  	// add an EventHandler (js-Function), defined in window 'theWindow' (or player-toppage if not set), if not already exists 
  	addEventHandler: function(nameOfFunction, theWindow){
		if ($type(nameOfFunction) == 'function') {
			if ( !$defined(this.eventHandlers.get(nameOfFunction)) ) {
	    		this.eventHandlers.set(nameOfFunction,nameOfFunction);
	    	}
	    }
    	else {
    		if ( $type(theWindow) != 'object' ) {
    			theWindow = self;
    		}
			var func = theWindow[nameOfFunction];
        	if ( $type(func) == 'function' && !$defined(this.eventHandlers.get(nameOfFunction)) )
	          this.eventHandlers.set(nameOfFunction,func);
      	}
    },
    
    
    // get an EventHandler
    getEventHandler: function(nameOfFunction){
      	return this.eventHandlers.get(nameOfFunction);
    },
    
    
    // make a frame known to the system, with a internalName, the id of the frame-object, url, and whether 
    // the frame is a tab (special frame)
    addFrame: function(internalName, id, url, reloadOnChangePlaylist, isTab) {
    	var frameData = new Hash();
    	frameData.set('id',id);
    	frameData.set('url',url);
    	frameData.set('reloadOnChangePlaylist',reloadOnChangePlaylist);
    	frameData.set('isTab',isTab);
    	frameData.set('reloadParamNames',[]);
    	frameData.set('reloadParamValues',[]);
    	this.frames.set(internalName,frameData);
    },
    
    
    // set an array of parameter names / values for a frame, added on frame-reload
    // the frame is a tab (special frame)
    addFrameReloadParams: function(internalName, paramNameArray, paramValueArray) {
    	var frame = this.frames.get(internalName);
    	if ( $defined(frame) ) {
    		frame.get('reloadParamNames').extend(paramNameArray);
    		frame.get('reloadParamValues').extend(paramValueArray);
    	}
    },
	
	// Search	
	getIndexSearchPerformed: function() {			
		return this._startSearchPerformed;
	},    
		
	setIndexSearchPerformed: function(pVal) {			
		this._startSearchPerformed = pVal;
	},

	getSearchPerformed: function() {			
		return this._searchPerformed;
	},    
		
	setSearchPerformed: function(pVal) {			
		this._searchPerformed = pVal;
	},
	
	setSearchTab: function(pVal) {
		this._isSearchTab = pVal;
	},
	
	getSearchTab: function() {
		return this._isSearchTab;
	},
	
	getVideoIndex:function() {
		return this._videoIndex;
	},    
	
	setVideoIndex:function(pVal) {
		this._videoIndex = pVal;
	},	
	
	getVideoIsClickt:function() {
		return this._videoIsClickt;
	},    
	
	setVideoIsClickt:function(pVal) {
		this._videoIsClickt = pVal;
	},
	
	getStartIsLeaving:function() {
		return this._leavingStartIndex;
	},    
	
	setStartIsLeaving:function(pVal) {
		this._leavingStartIndex = pVal;
	},
	
	getStartSitemapIndex:function() {
		return this._startSitemapIndex;
	},    
	
	setStartSitemapIndex:function(pVal) {
		this._startSitemapIndex = pVal;
	},	

    // make a category known to the system
    addCategory: function(categoryId) {
    	this.categories.push(categoryId);
    },
    

    // add an event to the system
    addEvent: function(event) {
    	this.events.push(event);
    },
    
    
    // remove all events
    clearEvents: function() {
    	this.events = new Array();
    },
    
    
    // add 
    addStyleInfo: function(name, value) {
    	this.styleInfo.set(name,value);
    },
    
    
    // set the url of a frame
    setFrameUrl: function(internalName, url) {
    	var frameObj = this.frames.get(internalName);
    	if ( frameObj ) {
    		var idOrName = frameObj.get('id');
    		if ( document.all && document.frames[idOrName] ) {
				frames[idOrName].location.href=url;
			}
			else if ( document.getElementById && document.getElementById(idOrName) ) {
				document.getElementById(idOrName).src=url;
			}
			else if ( document.layers && document.layers[idOrName] ) {
				document.layers[idOrName].load(url, 254);
			}
    	}
    },
    
    
    // reload a frame, add parameter names/values as array
    reloadFrameUrl: function(internalName, paramArray, valueArray) {
    	var frameObj = this.frames.get(internalName);
    	if ( frameObj ) {
    		var url;
    		if ( ($type(paramArray) == 'array'  || $type(paramArray) == 'object' && $defined(paramArray.length)) && 
    			 ($type(valueArray) == 'array' || $type(paramArray) == 'object' && $defined(paramArray.length)) ) {
    			url = buildUrlWithParams(frameObj.get('url'),paramArray.extend(frameObj.get('reloadParamNames')),
    						 						valueArray.extend(frameObj.get('reloadParamValues')));
    		} 
    		else {
    			url = frameObj.get('url');
    		}
    		this.setFrameUrl(internalName, url);
    	}
    },
    
    
    // switch to tab (show/hide frame); add/remove css-class styleInfo['tabClassActive'] to corresponding  
    // tab-elements with id <styleInfo['tabIdPrefix']>_<tabName> if values are set and elements exist
    switchTab: function(tabName, storeCurrent) {
    	var cssIdPrefix = this.styleInfo.get('tabIdPrefix');
    	var cssClass = this.styleInfo.get('tabClassActive');
    	
    	var tabFrame = this.frames.get(tabName);
    	if ( tabFrame && tabFrame.get('isTab') == true ) {
    		this.frames.each(function(frame, frameName) {
				if ( frame.get('isTab') == true ) {
					var id = frame.get('id');
  					if ( $(id) ) {
  						var frameUrl = $(id).src;
  						var isSystemUrl = $pick(frameUrl.length, 0) > 0 && 
  							( frameUrl.charAt(0) == '/' ||  frameUrl.indexOf(window.location.hostname) > 0 ); 
  						
  						if ( frameName == tabName ) {
  							if ( isSystemUrl && $defined(frames[id]) && $type(frames[id].onSwitch) == 'function' ) {
  								eval(frames[id].onSwitch());
  							}
  							$(id).setStyles('visibility:visible; display:block;');
  							if ( cssClass && cssIdPrefix && $(cssIdPrefix+frameName) ) {
  								$(cssIdPrefix+frameName).addClass(cssClass);
  							}
  						}
  						else {
  							if ( isSystemUrl && $defined(frames[id]) && $type(frames[id].onUnSwitch) == 'function' ) {
  								eval(frames[id].onUnSwitch());
  							}
  							$(id).setStyles('visibility:hidden; display:none;');
  							if ( cssClass && cssIdPrefix && $(cssIdPrefix+frameName) ) {
  								$(cssIdPrefix+frameName).removeClass(cssClass);
  							}
  						}
					}
				}
			});
    	}
    	if ( $pick(storeCurrent,true) ) {
    		this.currentTab = tabName;
    	}
    },
    
    
    // highlight a tab
    highlightTab: function(tabName) {
    	var cssIdPrefix = this.styleInfo.get('tabIdPrefix');
    	var cssClass = this.styleInfo.get('tabClassActive');
    	
    	var tabFrame = this.frames.get(tabName);
    	if ( tabFrame && tabFrame.get('isTab') == true ) {
    	
    		this.frames.each(function(frame, frameName) {
				if ( frame.get('isTab') == true ) {
					var id = frame.get('id');
  					if ( $(id) ) {
  						if ( frameName == tabName ) {
  							if ( cssClass && cssIdPrefix && $(cssIdPrefix+frameName) ) {
  								$(cssIdPrefix+frameName).addClass(cssClass);
  							}
  						}
  						else {
  							if ( cssClass && cssIdPrefix && $(cssIdPrefix+frameName) ) {
  								$(cssIdPrefix+frameName).removeClass(cssClass);
  							}
  						}
					}
				}
			});
			this.currentTab = tabName;
    	}
    },
    
    
    // switch to current tab if set
    switchToCurrentTab: function() {
    	if ( this.currentTab && this.currentTab != '' ) {
    		this.switchTab(this.currentTab);
    	}
    },
    
    
    // Switch to a tab, and load videolist
    switchVideolistTab: function(tabName, videolistId) {
		if ( this.currentVideolistId != videolistId ) {
			this.setVideolist(videolistId,1,true);
			this.switchTab('schedule');
			this.highlightTab(tabName);
		}
		else {
			this.switchTab('schedule');
			this.highlightTab(tabName);
		}
		this.currentTab = tabName;
	},
	
	
	// Switch to schedule tab, load schedule if in videolist
	switchScheduleTab: function() {
		if ( this.currentVideolistId > -1 ) {
			this.setVideolist(-1,-1,this.noLoopForSchedule);
			this.currentVideolistId = -1;
			this.currentCategoryId = -1;
			this.switchTab('schedule');
		}
		else {
			this.switchTab('schedule');
		}
		this.currentTab = 'schedule';
	},
    
    
    // highlight a category
    highlightCategory: function(categoryId) {
    	var cssIdPrefix = this.styleInfo.get('catIdPrefix');
    	var cssClass = this.styleInfo.get('catClassActive');
		for ( var i=0; $type(this.categories) == 'array' && cssIdPrefix && cssClass && i<this.categories.length; i++ ) {
			var elemId = cssIdPrefix + this.categories[i];
			if ($(elemId)) {
				if ( this.categories[i] == categoryId ) {
					$(elemId).addClass(cssClass);
				}
				else {
					$(elemId).removeClass(cssClass);
				}
			}
		}
	},
	
    
    // change to category, add/remove css-class styleInfo['catClassActive'] to elements with
    // id <styleInfo['catIdPrefix']>_<catId> if values are set and elements exist
    // sortBy: 'publishDate' or 'creationDate'
    // sortFrom: skip entry 0 to sortFrom from sorting
    setCategory: function(categoryId, sortBy, sortFrom,idx) {
    	idx = ($defined(idx)) ? idx : 1;
    	this.highlightCategory(categoryId);
		// reset player and stop controller-sync
		if ( this.player) {
			this.player.halt();
			this.player = undefined;
		}
		this.listeners.each(function(listener) {
			if(listener.onBeforeChangeCategory){
				listener.onBeforeChangeCategory(categoryId);
			}
		});
		this.frames.each(function(frame, frameName) {
			if ( $pick(frame.get('reloadOnChangePlaylist'),false) ) {

				var frameUrl = frame.get('url') + '?category=' + categoryId + '&clip=' + idx + '&rand= ' + Math.random();
				if(this.playerConfig.playerVersion){
					frameUrl = frameUrl + '&playerVersion=' + this.playerConfig.playerVersion;
				}
				if ( $defined(sortBy) ) {
					frameUrl += '&sortBy='+sortBy;
				}
				if ( $defined(sortFrom) ) {
					frameUrl += '&sortFrom='+sortFrom;
				}
				this.setFrameUrl(frameName, frameUrl);
			}			
		}, this);
		this.currentCategoryId = categoryId;
		if ( this.currentVideolistId > -1 ) {
			this.currentVideolistId = -1;
			this.switchTab('schedule');
		}
	},
	
	
	showTabCategory: function(categoryId) {
    	this.highlightCategory(categoryId);
		this.switchTab('cat'+categoryId);
	},
	
	
	// change to videoist
    setVideolist: function(videolistId, clip, noLoop) {
    	// reset player and stop controller-sync
		if ( this.player) {
			this.player.stop();
			this.player.halt();
		}
		this.frames.each(function(frame, frameName) {
			if ( $pick(frame.get('reloadOnChangePlaylist'),false) ) {
				var noLoopValue = noLoop;
				if ( !$pick(this.singleScheduleFrame,false) ) {
					noLoopValue = true;
					if ( frameName == 'player' || frameName == 'controller' ) {
						noLoopValue = noLoop;
					} 
					else if ( frameName == 'schedule' ) {
						noLoopValue = this.noLoopForSchedule;
					}
				}
				var paramNames = ['schedule_id','noLoop','rand'].extend(frame.get('reloadParamNames'));
				var paramValues =  [videolistId, noLoopValue, Math.random()].extend(frame.get('reloadParamValues'));
				if ( clip > -1 && ($pick(this.singleScheduleFrame,false) || !frame.get('isTab') || frameName == this.currentTab) ) {
					paramNames.push('clip');
					paramValues.push(clip);
				}
				if ( clip < 0 ) {
					paramNames.push('live');
					paramValues.push(true);
				}
				if(this.playerConfig.playerVersion){
					paramNames.push('playerVersion');
					paramValues.push(this.playerConfig.playerVersion);
				}
				
				var url = buildUrlWithParams(frame.get('url'), paramNames, paramValues);
				this.setFrameUrl(frameName, url);
			}
		}, this);
		if ( this.currentCategoryId > -1 ) {
			this.currentCategoryId = -1;
			this.highlightCategory(-1);
		}
		this.currentVideolistId = videolistId;
	},
		
	
	// jump to clip in schedule which is "Live" at this point 
	backToLive: function() {
		// in category or special-playlist, reload whole player
		if ( this.currentCategoryId > -1 || this.currentVideolistId > -1 || this.isTemporaryPlaylist ) {
			this.currentCategoryId = -1;
			this.currentClipIndex = -1;
			this.reloadPlayer(undefined,['live'],['true']);
		}
		else { 
			this.freeNavigation = false;
			this.reloadFrameUrl('schedule', ['live'],['true']);
		}
	},
	
	
	// reload the player with url and a given language
	reloadPlayer: function(url, paramNames, paramValues) {
		var paramArray = new Array();
		var valueArray = new Array();
		
		if ( this.currentVideoId > -1 ) {
			paramArray.push('video');
			valueArray.push(this.currentVideoId);
		}
		if ( this.currentClipIndex > -1 ) {
			paramArray.push('clip');
			valueArray.push(this.currentClipIndex);
		}
		
		if ( this.currentCategoryId > -1 ) {
			paramArray.push('category');
			valueArray.push(this.currentCategoryId);
		}
		if ( this.currentVideolistId > -1 ) {
			paramArray.push('schedule_id');
			valueArray.push(this.currentVideolistId);
			paramArray.push('noLoop');
			valueArray.push(true);
		}
		if ( this.currentTab ) {
			paramArray.push('tab');
			valueArray.push(this.currentTab);
		}
		if ( !$defined(url) ) {
			var topFrame = this.frames.get('top');
			if ( $defined(topFrame) ) {
				url = topFrame.get('url');
			}
		}
		if ( $defined(paramNames) && $defined(paramValues) ) {
			paramArray.extend(paramNames);
			valueArray.extend(paramValues);
		}
		if ( $defined(this.reloadParams.names) && $defined(this.reloadParams.values) ) {
			paramArray.extend(this.reloadParams.names);
			valueArray.extend(this.reloadParams.values);
		}
		setUrlWithParams(url, paramArray, valueArray);
	},
	
	addReloadPlayerParams: function(name,value) {
		if( !$defined(this.reloadParams.names)){
			this.reloadParams.names = new Array();
		}
		if( !$defined(this.reloadParams.values)){
			this.reloadParams.values = new Array();
		}
		var index = this.reloadParams.names.indexOf(name);
		if (index < 0) {
			this.reloadParams.names.push(name);
			this.reloadParams.values.push(value);
		}
		else {
			this.reloadParams.values.splice(index,1,value);
		}
	},
	
	removeReloadPlayerParams: function(name) {
		var index = this.reloadParams.names.indexOf(name);
		if (index > -1) {
			this.reloadParams.names.splice(index,1);
			this.reloadParams.values.splice(index,1);
		}
	},
	
	playSearchEntries: function(pVideo) {

		this.player.setCurrentClip(pVideo);
	},
	
	
	// reload the player with url and a given locale
	changeLanguage: function(language, url) {
		var newUrl = url;
		if ( !$defined(newUrl) ) {
			var topFrame = this.frames.get('top');
			if ( $defined(topFrame) ) {
				newUrl = topFrame.get('url');
			}
		}
		
		var videoInfoIdx = newUrl.indexOf('_v_');
		if (videoInfoIdx > -1) {
			var endIdx = newUrl.indexOf('/',videoInfoIdx);
			if (endIdx > -1) {
				var videoInfo = newUrl.substring(videoInfoIdx,endIdx);
				var langIdx = videoInfo.lastIndexOf('_')+1;
				if (langIdx > 0 && langIdx < videoInfo.length) {
					newUrl = newUrl.substring(0,langIdx+videoInfoIdx) + language + newUrl.substring(endIdx) + '?locale=' + language;
				}
			}
		}
		this.reloadPlayer(newUrl);
	},
	
	
	// jump to clip with given index
	setClip: function(clip) {
		if ( this.player && this.player.getNumClips() >= clip ) {
			this.listeners.each(function(listener) {
				if(listener.onBeforeChangeClip){
					listener.onBeforeChangeClip();
				}
			});
			this.player.setCurrentClip(clip);
			this.listeners.each(function(listener) {
				if(listener.onClipChanged){
					listener.onClipChanged();
				}
			});
			_setClipTry = 0;
		}
		else {
			_setClipTry++;
			if ( _setClipTry < 10 ) {
				window.setTimeout('system.setClip('+clip+')', 200);
				return;
			}
			else {
				_setClipTry = 0;
			}
		}
	},
	
	
	// start Videolist and jump to clip with given index
	setVideolistAndClip: function(idx, videolistId, noLoop) {
		this.freeNavigation=false;
    	if ( this.player ) {
    		if ( $defined(videolistId) && this.currentVideolistId != videolistId ) {
    			this.setVideolist(videolistId,idx,noLoop);
    			if ( $defined(this.currentTab) ) {
    				this.scheduleFrameToUpdate=this.currentTab;
    			}
    		}
    		else {
    			this.player.setCurrentClip(idx);
    		}
    	}
	},
	
	
	// play given video(s)
	playVideos: function(videoArray) {
		var paramArray = [];
		for (var i=0; i<videoArray.length; i++) {
			paramArray.push('video');
		}
		this.currentCategoryId=-1;
		this.currentVideolistId=-1;
		this.currentVideoId=-1;
		this.currentClipIndex=-1;
		this.currentTab=undefined;
		this.reloadPlayer(undefined,paramArray,videoArray);
	},
	
	
	// play given video
	playVideo: function(video) {
		this.playVideos([video]);
	},
	
	
	// add pushframe for onDemand pushing
	addPushOnDemand: function(internalFrameName, pushObjectArray, pushTimeArray, initialPushObject, pushObjectTypeArray, initialPushObjectType) {
		var pushFrame = this.frames.get(internalFrameName);
		if ( $defined(pushFrame) && pushObjectArray.length == pushTimeArray.length ) {
			this.webcast.pushOnDemandFrame.push(internalFrameName);
			this.webcast.pushOnDemandObject.push(pushObjectArray);
			if ( $defined(this.webcast.pushOnDemandObjectType) ) {
				this.webcast.pushOnDemandObjectType.push(pushObjectTypeArray);
			}
			this.webcast.pushOnDemandTime.push(pushTimeArray);
			if ( $defined(initialPushObject) ) {
				this.webcast.lastPushed.set(internalFrameName, initialPushObject);
				if ( $defined(initialPushObjectType) ) {
					this.webcast.lastPushedType.set(internalFrameName, initialPushObjectType);
				}
			}
		}
	},
	
	
	// open popup for pushframe (e.g. slide in large; live and onDemand). default is 800x600
	openPushPopup: function(frameName, width, height) {
		var slideFrame;
		if ( frameName ) {
			slideFrame = this.frames.get(frameName);
		}
		if ( ! $defined(slideFrame) ) {
			return;
		}
		
		var url = slideFrame.get('url');
		if ( this.webcast.popupSlideWidth.get(frameName) <= 0 ) {
			this.webcast.popupSlideWidth.set(frameName, $pick(width,800));
			this.webcast.popupSlideHeight.set(frameName, $pick(height,600));
		}
		var lastPushedId = this.webcast.lastPushed.get(frameName);
		var lastPushedType = this.webcast.lastPushedType.get(frameName);
		if ( lastPushedId ) {
			url += '?pushObjectId='+lastPushedId+'&pushObjectType='+lastPushedType+'&';
		}
		else {
			url += '?';
		}
		url += 'width='+this.webcast.popupSlideWidth.get(frameName)+'&height='+this.webcast.popupSlideHeight.get(frameName);
		var opts = 'width='+this.webcast.popupSlideWidth.get(frameName)+',height='+this.webcast.popupSlideHeight.get(frameName)+',resizable=yes,toolbar=no,location=no,directories=no,scrollbars=no,status=no,menubar=no';
		this.webcast.popupSlideWindow.set(frameName, window.open(url, 'popup_'+frameName, opts));
	},
	
	
	// PLAYER FUNCTIONS
	// play/pause
	player_playpause: function() {
		if ( this.player ) {
			if ( this.fastPlay ) {
				this.player.play();
				this.fastPlay=false;
			}
			else {
				if ( this.fastRev ) {
					this.player.play();
					this.fastRev=false;
				} 
				else {
					if ( this.player.isPlaying() ) {
						this.player.pause();
					} else {
						this.player.play();
					}
				}
			}
		}
	},
	
	
	// fast forward moved to javascripts.js using the events mouseover,mousedown,mouseup,mouseout
	player_fforward: function() {
		/* if ( this.player ) {
			this.player.fastForward();
			this.fastRev=false;
			this.fastPlay=true;
		}*/
	},
	
	
	// fast reverse moved to javascripts.js using the events mouseover,mousedown,mouseup,mouseout
	player_freverse: function() {
		/* if ( this.player ) {	      
			this.player.fastReverse();
	        this.fastPlay=false;
	        this.fastRev=true;
		}*/
	},
	
	
	// fullscreen
	player_fullscreen: function() {
		if ( this.player ) {
			this.player.setFullScreen();
		}
	},
	
	
	// toggle mute 
	player_mute: function() {
		if ( this.player ) {
			this.player.changeMute(true);
		}
	},
	
	// increase volume
	player_vol_inc: function() {
		if ( this.player) {
			// check whether to change soundOn / soundOff			
			var muteState = this.player.getMute();
			if(muteState){
				this.player_mute();
				this.isSoundOn = true;
			}
			this.player.changeVolume(2);
		}
	},
	
	// decrease volume
	player_vol_dec: function() {
		if ( this.player) {
			// check whether to change soundOn / soundOff			
			var muteState = this.player.getMute();
			if(muteState){
				this.player_mute();
				this.isSoundOn = true;
			}
			this.player.changeVolume(-2);
			if(!muteState && this.player.getVolume() == 0){
				this.player_mute();
				this.isSoundOn = false;
			}
		}
	},

	// pause player on timeout (no click-update for set period of time)
	noClickStatusCheck: function(){
		if( this.player ) {
			var timer = this.noClickResetTimer;
			var duration = this.noClickResetDuration;
			var timeout = timer + duration;
			var now = new Date().getTime();
			var isPlaying = this.player.isPlaying();
			if(timer != null && duration != null && isPlaying && timeout < now) {
				this.player_playpause();
			}
		}
	},
	
	// reset start time for timeout
	noClickUpdateTimer: function(){
		this.noClickResetTimer = new Date().getTime();
	}
	    
});

// </Class definitions>


// <Functions>
function browser_getPlatform(agent)
{
   if (!agent) { agent = navigator.userAgent; }
   var platform = 'unknown'
   if      (agent.indexOf('Win') != -1)   { platform = 'win'; }
   else if (agent.indexOf('Mac') != -1)   { platform = 'mac'; }
   else if (agent.indexOf('IRIX') != -1)  { platform = 'irix'; }
   else if (agent.indexOf('Linux') != -1) { platform = 'linux'; }
   else if (agent.indexOf('BSD') != -1)   { platform = 'bsd'; }
   return platform;
}


// WACTIMER BEGIN
// --------------------------------------------------------------
// WACTimerHandler

function WACTimerHandler(aName, aTimeout) {
  this.name    = aName;
  this.timeout = aTimeout;
}


function WACTimerHandlerDoIt() {
  alert("abstract function WACTimerHandler.doIt() called");
}

function WACTimerHandlerToString() {
  return this.name + "[" + this.timeout + "]: abstract";
}

WACTimerHandler.prototype.doIt     = WACTimerHandlerDoIt;
WACTimerHandler.prototype.toString = WACTimerHandlerToString;



// --------------------------------------------------------------
// WACTimerEvalHandler

function WACTimerEvalHandler(aName, aTimeout, anObject, aFunction) {
  this.name    = aName;
  this.timeout = aTimeout;
  this.obj     = anObject;
  this.func    = aFunction;
}


function WACTimerEvalHandlerDoIt() {
  this.obj.eval(this.func);
}

function WACTimerEvalHandlerToString() {
  return this.name + "[" + this.timeout + "]:" + typeof this.obj + " " + this.func;
}

WACTimerEvalHandler.prototype.doIt     = WACTimerEvalHandlerDoIt;
WACTimerEvalHandler.prototype.toString = WACTimerEvalHandlerToString;



// --------------------------------------------------------------
// WACTimer

function WACTimer(aName, anInterval) {
  this.name              = aName;
  this.interval          = anInterval;
  this.count             = 0;
  this.handlers          = new Object();
}

function WACTimerGo() {
  this.doIt();
}

function WACTimerRegisterHandler(handler) {
  this.handlers[handler.name] = handler;
}


function WACTimerUnregisterHandler(handler) {
  if (handler) {
    if (handler.name)
      this.handlers[handler.name] = null;
    else
      this.handlers[handler] = null;
  }
}

function WACTimerDoIt() {
  for (handlerName in this.handlers) {
    var handler = this.handlers[handlerName];
    if (handler && !(this.count % Math.round(handler.timeout / this.interval)))
      handler.doIt();
  }
  this.count++;
  window.setTimeout(this.name + ".doIt()", this.interval);
}


function WACTimerToString() {
  var str = this.name + "[" + this.interval + "|" + this.count + "]<br>\n";
  var ii;
  for (ii in this.handlers)
    str += this.handlers[ii].toString() + "<br>\n";
  return str;
}

WACTimer.prototype.registerHandler   = WACTimerRegisterHandler;
WACTimer.prototype.unregisterHandler = WACTimerUnregisterHandler;
WACTimer.prototype.go                = WACTimerGo;
WACTimer.prototype.doIt              = WACTimerDoIt;
WACTimer.prototype.toString          = WACTimerToString;
// WACTIMER END
// </Functions>


// Variables
var topTimer = undefined;
if ( $defined(parent) ) {
	try {
		if ( $defined(parent.topTimer) ) {
			topTimer = parent.topTimer;
		}
	} catch(e) { }
}
if ( !$defined(topTimer) ) {
	topTimer = new WACTimer("topTimer", 50);
}

var system = undefined;
if ( $defined(parent) ) {
	try {
		if ( $defined(parent.system) ) { 
			system = parent.system;
		}
	} catch(e) { }
}
if ( !$defined(system) ) {
	system = new System(topTimer);
}
var _setClipTry = 0;
