
var player = null;
var currentItem = -1;
var current_item_id = 0;




function playerReady(thePlayer) {




	if(player = window.document[thePlayer.id]){

		playAway();

	}


}

function queue(seconds){
	 jwplayer().seek(seconds);
}



function playAway(){
	$(document).oneTime(500, function() { 
        addListeners();
	    try {
		    playlistHandler(player);
	    } catch(err) {
		    player.addControllerListener('PLAYLIST','playlistHandler');
	    }
    }); 

};

function playlistHandler(obj) {
    var arr = obj.playlist;
 	
        if(item_id){
            obj.sendEvent('ITEM',  item_id);
        }
        obj.sendEvent('PLAY', 'true');        


};


function addListeners() {
	    if (player) {
		    player.addControllerListener("ITEM", "itemListener");
		    return true;
	    } else {
		    setTimeout("addListeners()",100);
	    }
}



function itemListener(obj) {
    /*
	if (obj.index != currentItem) {
 		previousItem = currentItem;
		currentItem = obj.index;

        current_item_id = item_index[currentItem];
        
        aj_get_podcast_download(item_index[currentItem],item_type); 
        aj_get_related_documents(item_index[currentItem],item_type);
		get_about_this(item_index[currentItem],item_type);
        start_comments_feed(item_index[currentItem],item_type);
        
	}
	*/
}

function get_about_this(id,type){
	var about_this;
	if(type=='stream'){
		$.getJSON("/ajax/stream_json.php?id=" + id,
        function(data){
        	about_this = '';
        	// about this copy
        	if(data.stream_menu_title){
				about_this = "<strong>"+data.stream_menu_title+"</strong><br />";
        	}
        	
        	if(data.stream_title){
				about_this+= data.stream_title;
        	}
        	
        	if(data.stream_description){
				about_this+= "<br /><br />"+data.stream_description;
        	}
        	$('#about_this_right_inner').html(about_this);
        	
        	
        	var embed_direct = '&lt;embed src=&quot;http://www.policyreview.tv/newplayer/player805.swf&quot; width=&quot;560&quot; height=&quot;340&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; flashvars=&quot;file=http://www.policyreview.tv/single_video_' + conf_id + '_' + id + '.xml&amp;autostart=false&amp;plugins=stream,testslideshow,captions&quot; /&gt;';
        	var embed_iframe = '&lt;iframe src=&quot;http://www.policyreview.tv/embed/' + conf_id + '/' + id + '&quot; width=&quot;560&quot; height=&quot;340&quot; id=&quot;player_iframe&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;';
        	// embed code
        	var embed_html='<div class="right_titles"><h3>Embed Code</h3></div><div id="embed_code_right_inner">IFRAME:<br />' + embed_iframe + '<br /><br />EMBED:<br />' + embed_direct + '</div>';
        	$('#embed_code').html(embed_html); 

        	
        
        });
        
        
        
        
        
	}
	if(type=='podcast'){
		$.getJSON("/ajax/podcast_json.php?id=" + id,
        function(data){
        	about_this = '';
        	if(data.podcast_title){
				about_this = "<strong>"+data.podcast_title+"</strong><br />";
        	}
        	
        	if(data.podcast_menu_title){
				about_this+= data.podcast_menu_title;	
        	}

        	if(data.podcast_description ){
				about_this+= "<br /><br />"+data.podcast_description;
        	}        	
        	
        	$('#about_this_right_inner').html(about_this);

            var embed_html='<div class="right_titles"><h3>Embed Code</h3></div><div id="embed_code_right_inner">&lt;iframe src=&quot;http://www.policyreview.tv/embed_podcast/' + conf_id + '/' + id + '&quot; width=&quot;560&quot; height=&quot;340&quot; id=&quot;player_iframe&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;</div>';
            
           
            $('#embed_code').html(embed_html); 
            
        });
	}
}






