/**
 * HTML5 Videók eseményeinek nyomonkövetése
 *  
 * Kell hozzá egy működő GA mérőkód: "_gaq" típusú
 */
var video_handler = {

	   debug: false,
	   log_row: 0,
	   video: null,
	   monitor: null,
	   video_name: null,
	   category: 'video_html5',
	   
	   /**
	    * Rátesszük a videóra az esemény figyelőket 
	    */
	   init: function(id) {
	//alert(typeof(_gaq));
			if (typeof(_gaq) == "undefined") {
				alert('Nincs beágyazva megfelelő Google Analitycs mérőkód!');
			}
            this.video   = document.getElementById(id);
            if (this.debug) {
	            this.monitor = document.getElementById('monitor');
            }
            
            this.video.addEventListener("play", this.videoPlay, false);
            this.video.addEventListener("pause", this.videoPause, false);
            this.video.addEventListener("ended", this.videoEnded, false);
            
            this.log('Inint OK');
            
            this.video.play();
            
	   },
	   
	   /**
	    * Debughoz logolunk a kimenetre.
	    * Kell hozzá egy id='monitor' elem
	    */
       log: function(msg) {
            if (this.debug) {
			    this.log_row++;
			    this.monitor.innerHTML += this.log_row + '. ' + msg + '<br/>';
            }
	   },
	   /**
	    * Play / Videó indítás figyelő
	    */
	   videoPlay: function() {
	        if (this.currentTime == 0) {
	        	_gaq.push(['_trackEvent', video_handler.category, 'Loaded', video_handler.video_name]);
	        	video_handler.log('Start video' + ': ' + video_handler.video_name);
	        }
	        else {
	        	video_handler.log('play event' + ': ' + video_handler.video_name);
	        }
	    },
	    
	    /**
	     * Pause figyelő
	     */
	    videoPause: function() {
	    	video_handler.log('pause event' + ': ' + video_handler.video_name);
	    },
	    
	    /**
	     * Végigjátszás figyelő
	     */
	    videoEnded: function () {
	    	_gaq.push(['_trackEvent', video_handler.category, 'Ended', video_handler.video_name]);
	    	video_handler.log('End video' + ': ' + video_handler.video_name);
            
	    }
}
