var currentState = null; 
var previousState = null; 
var currenTime = -1;
var player = null;
var params = {
	allowfullscreen:"true", 
	allowscriptaccess:"always"
}
var attributes = {
	id:"player1",  
	name:"player1"
}
function playerReady(thePlayer) {
	player = document.getElementById(thePlayer.id);
	addListeners();
}
function addListeners() {
	if(player) { 
		player.addModelListener("STATE", "stateListener");
		player.addModelListener('TIME',  'timeMonitor');
	}else{
		setTimeout("addListeners()",100);
	}
}
function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	currentState = obj.newstate; 
	previousState = obj.oldstate;
	if(currentState == 'PAUSED' || ((currentState == "COMPLETED") && (previousState == "PLAYING")))
		$.get(basename, {"ajax":1,"action":"video_state","currentState":currentState,"currentTime":currentTime,"video_id":video_id}, function(data){});
	if((currentState == "COMPLETED") && (previousState == "PLAYING")) {
		$("#player1").hide();
		$("#join").show();
	}
}
function timeMonitor(obj) {
	currentTime = obj.position;
}

$(document).ready(function(){
	$(".video_download").click(function(){
		$.get(basename, {'ajax':1,'action':'event','event':'video_download'}, function(){
			document.location.href = site_link;
		});
	// 	$("#player1").hide();
	// 	$("#join").show();
	// 	$(".video_download").hide();
	// 	return false;
	});	
	$(".download_leave").click(function(){
		$("#join").hide();
		$("#player1").show();
		$(".video_download").show();
		return false;
	});
	$(".join_button_sponsor").click(function(){
		$.get(basename, {'ajax':1,'action':'event','event':'video_complete_button'});
		document.location.href = affil_link;
	})
});