

	
	var currentState = "NONE"; 
  	var previousState = "NONE"; 
  	var filmName = "unknown";
  	
	function playerReady(thePlayer) {
		var player = document.getElementById(thePlayer.id);
		if(player)
		{
			player.addModelListener("STATE", "on_state");

		}
		
	}


	function on_state(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
		currentState = obj.newstate; 
		previousState = obj.oldstate; 
		if (currentState == "PLAYING" && previousState == "BUFFERING") {
			
			ns_onclick(this,'',filmName,'clickout');
			
		}
	}

  
  function RenderWeverTags()
  {
	RenderStreamTags();
	RenderTwitterTags();
  }
  
  function RenderTwitterTags()
  {
	var tagcount = 0;
	$("wevertag[mode='twitter']").each(function () {
		
		var placeholderID = "twitter_" + tagcount;
		var preloaderID = "preloader_" + tagcount;
		
		var username = "";
		var numtweets = 0;
		var loadertext = "Bezig met laden...";
		var slidein = "false";
		var showheading = "true";
		var headingtext = "Twitter";
		var showprofilelink = "true";
		var showprofileimage = "false";
		
		if($(this).attr("username")){
			username = $(this).attr("username");
		}
		if($(this).attr("numtweets")){
			numtweets = $(this).attr("numtweets");
		}
		if($(this).attr("loadertext")){
			loadertext = $(this).attr("loadertext");
		}
		if($(this).attr("slidein")){
			slidein = $(this).attr("slidein");
		}
		if($(this).attr("showheading")){
			showheading = $(this).attr("showheading");
		}
		if($(this).attr("headingtext")){
			headingtext = $(this).attr("headingtext");
		}
		if($(this).attr("showprofilelink")){
			showprofilelink = $(this).attr("showprofilelink");
		}
		if($(this).attr("showprofileimage")){
			showprofileimage = $(this).attr("showprofileimage");
		}
		
		if(username.length > 0)
		{
		
		$(this).wrap("<div class='twitterbox' id='" + placeholderID +"'><p>Twitter: Please install Flash Player and enable javascript</p></div>");
		// hide container element
		
		var wrapper = $("#"+placeholderID);
		wrapper.empty();
		wrapper.hide();
	
		// add heading to container element
		if(showheading=="true")
			wrapper.append("<h2>" + headingtext + "</h2>");
			
			//add profileimage
		if(showprofileimage=="true")
			wrapper.append("<div id='profileImage'><img src='http://purl.org/net/spiurl/" + username + "' alt='Twitter User' /></div>");
			
		wrapper.append('<ul id="twitter_update_list"><li></li></ul>');
			$("ul#twitter_update_list").hide();

		// add preLoader to container element
		var pl = $('<p id="'+preloaderID+'">' + loadertext + '</p>');
		
		wrapper.append(pl);

		// add Twitter profile link to container element
		if(showprofilelink=="true")
			wrapper.append('<a id="profileLink" href="http://twitter.com/' + username+ '">Volg op Twitter: http://twitter.com/' + username + '</a>');
		

		// show container element
		wrapper.show();
		
		$.getScript("http://twitter.com/javascripts/blogger.js");
		$.getScript("http://twitter.com/statuses/user_timeline/" + username + ".json?callback=twitterCallback2&count=" + numtweets, function() {
			// remove preLoader from container element
			$(pl).remove();

			// show twitter list
			if (slidein == "true") {
				$("ul#twitter_update_list").slideDown(1000);
			}
			else {
				$("ul#twitter_update_list").show();
			}

			// give first list item a special class
			$("ul#twitter_update_list li:first").addClass("firstTweet");

			// give last list item a special class
			$("ul#twitter_update_list li:last").addClass("lastTweet");
		});
	
	}//if username > 0
		tagcount++;
	});
	
	
  }
  
  function RenderStreamTags()
  {
	
	var tagcount = 0;
	$("wevertag[mode='stream']").each(function () {
		
		
		var placeholderID = "placeholder_" + tagcount;
		var playerID = "player_" + tagcount;
		
		var params = {
			allowfullscreen:"true", 
			allowscriptaccess:"always",
			wmode:"opaque"
		}
		var attributes = {
			id:playerID,  
			name:playerID
		}
	
		
		var flashvars = {};
		flashvars.repeat = "false";
		flashvars.width = "320";
		flashvars.height = "240";		
		flashvars.stretching = "exactfit";		
		
		flashvars.autostart = "false";
		flashvars.controlbar = "none";
		
		
		if($(this).attr("image")){
			flashvars.image = $(this).attr("image");
			flashvars.image = flashvars.image.replace("**","//");
		}
		
		if($(this).attr("width")){
			flashvars.width = $(this).attr("width");
		}
			
		if($(this).attr("height")){
			flashvars.height = $(this).attr("height");
		}
		
		if($(this).attr("file")){
			flashvars.file = $(this).attr("file");
			
			//check if old rtmp link is used
			var urlStart = flashvars.file.substring(0,7);
			
			if(urlStart.toLowerCase() == "rtmp://")
				{
					flashvars.file = "wever/" + $(this).attr("id") + ".flv";					
					flashvars.streamer = "rtmp://www.streaming.wur.nl/vod/";
					flashvars.type = "rtmp";
				}
			
			
		}
		else
		{
			if($(this).attr("id")){
				flashvars.file = "wever/" + $(this).attr("id");
				flashvars.streamer = "rtmp://www.streaming.wur.nl/vod/";
				flashvars.type = "rtmp";
			}
		
		}
		
		
		if($(this).attr("autostart"))
			flashvars.autostart = $(this).attr("autostart");
		if($(this).attr("shownavigation"))
		{
			switch($(this).attr("shownavigation"))
			{
				case "false":
					flashvars.controlbar = "none";
					break;
				case "true":					
					flashvars.controlbar = "bottom";
					break;
				case "bottom":					
					flashvars.controlbar = "bottom";
					break;
				case "over":					
					flashvars.controlbar = "over";
					break;
					
			}
		}
		if($(this).attr("repeat"))
			flashvars.repeat = $(this).attr("repeat");
			
	
	

		filmName = "VIDEO$" + flashvars.file.replace("/","_") + "$" +  document.location.href;
		
		
		
		$(this).wrap("<div id='" + placeholderID +"'><p>Please install Flash Player and enable javascript</p></div>");

		swfobject.embedSWF("/wever.internet/scripts/swfobject/player.swf", placeholderID, flashvars.width, flashvars.height, "9.0.0", false, flashvars, params, attributes);
		
		tagcount++;
		
		
	
		
		
	});

  }
  