var starttime;
var videoClip;


function ShowVideoOverlay(video, videoWidth, videoHeight) {
	// detect jQuery exists and pause home cycle
	if (typeof($j)!="undefined")
	{ 
		if ($j('#home-cycle').length > 0) {
			$j('#home-cycle').cycle('pause');
		}
	}
	
	
	// GA Tracking
	pageTracker._trackEvent("Videos", "Overlay open", videoClip);
	
	videoClip = video;
	if (videoWidth == null){
		videoWidth = 512;
	}
	if (videoHeight == null){
		videoHeight = 288;
	}
	videoHeight += 24;
	//pageTracker._trackEvent('Videos', 'Play', videoClip);
	
	starttime = new Date().getTime();
	
	$('video_overlay_background').style.display='block';
	$('video_container').style.display='block';
	$('player').style.width=videoWidth+'px';
	$('player').style.height=videoHeight+'px';
	//var videoURL = "http://static.powershop.co.nz/video/" + videoClip;
	
	flowplayer("player",  "/flow/flowplayer-3.1.2.swf", { 
		clip: { 
			url: videoClip, 
			autoPlay: true,
			scaling: 'fit',
        // track start event for this clip         
        onStart: function(clip) {
			var elapsed = Math.round((new Date().getTime() - starttime) / 1000);
            pageTracker._trackEvent("Videos", "Play", videoClip, elapsed);  
        }, 
         
        // track pause event for this clip. time (in seconds) is also tracked        
        onPause: function(clip) {             
            pageTracker._trackEvent("Videos", "Pause", videoClip, parseInt(this.getTime()));         
        },                 
         
        // track stop event for this clip. time is also tracked         
        onStop: function(clip) {             
            pageTracker._trackEvent("Videos", "Stop", videoClip, parseInt(this.getTime())); 
        },                  
         
        // track finish event for this clip         
        onFinish: function(clip) {             
            pageTracker._trackEvent("Videos", "Finish", videoClip, parseInt(this.getTime()));         
        }              
    }
	
	}); 
	
}



function HideVideoOverlay() {
	// detect jQuery exists and resume home cycle
	if (typeof($j)!="undefined")
	{ 
		if ($j('#home-cycle').length > 0) {
			$j('#home-cycle').cycle('resume');
		}
	}
	
	flowplayer().stop();
	
	$('video_overlay_background').style.display='none';
	$('video_container').style.display='none';
	
	var elapsed = Math.round((new Date().getTime() - starttime) / 1000);
	
	// GA Tracking
	pageTracker._trackEvent('Videos', 'Overlay close', videoClip, elapsed);
}


