$(document).ready(function(){

	/*--LOAD VARS FROM PHP--*/

		var jsvars = new Array();		
		$('.jsvars').each(function(){
			jsvars[$(this).attr('name')] = $(this).val();
		});
	
	ts = Math.round(new Date().getTime() / 1000);
	swf_url = jsvars['flash'] + 'player_licensed_52.swf';
	xml_url = jsvars['base_url'] + 'assets/xml/temp/daily.xml?' + ts;
 	
 	if (navigator.userAgent.match(/iPad/i))
 	{
 		create_ipad_player();
 	}
	else if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
	{
		create_iphone_player();
	} else {
 		create_flash_player(swf_url, xml_url);
	}

});

	//var jsvars = new array();
	var player = null;
	
	function playerReady(thePlayer) {
		player = window.document[thePlayer.id];
		addListeners();
	}
	
	function addListeners() {
		if (player) { 
			player.addModelListener("STATE", "stateListener");
			player.addModelListener("TIME", "timeListener");
		} else {
			setTimeout("addListeners()",100);
		}
	}
	
	function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
		currentState = obj.newstate; 
		previousState = obj.oldstate; 
	}
	
	function timeListener(obj) {
		currentPosition = obj.position;
	}
	
	function create_flash_player(swf_url, xml_url) {
	    var flashvars = {
	            autostart:"false",
	            stretching:"uniform",
	            //plugins:"qualitymonitor-1",
	            plugins:"gapro-1",
	            "gapro.accountid":"UA-74996-16",
	            "gapro.idstring":"||title|| - ||author||",
	            controlbar:"bottom",
	            playlist:"right",
	            playlistsize:300,
	            "playlist.thumbs":"false",
	            dock:"true",
				volume:100,
	            shownavigation:"false",
	            displayclick:"fullscreen"
	    }
	    flashvars['file'] = xml_url;
	    var params = {
	            allowfullscreen:"true", 
	            allowscriptaccess:"always",
	            wmode:"transparent"
	    }
	    var attributes = {
	            id:"player1",
	            name:"player1"
	    }
	    swfobject.embedSWF(swf_url, "video_player", "958", "394", "9.0.115", false, flashvars, params, attributes);
	}
	
	function create_iphone_player() {
		var rewrite = '<video src="http://cdn.spiritflow.net/video/daily/daily_0023_100407/daily_0023_100407-640x360_900k.mov" width="958" height="538" poster="http://www.spiritflow.net/assets/images/temp/sfdailystill.jpg"></video>';
		$("#video_player_container").height(539);
		$("#video_player").html(rewrite);
	}
	
	function create_ipad_player() {
		var rewrite = '<video src="http://cdn.spiritflow.net/video/daily/daily_0023_100407/daily_0023_100407-640x360_900k.mov" width="958" height="538" poster="http://www.spiritflow.net/assets/images/temp/sfdailystill.jpg" controls></video>';
		$("#video_player_container").height(539);
		$("#video_player").html(rewrite);
	}