function hideRecorder(_recorderPlacehoderId){
	var flashcontentDiv = jQuery("#"+_recorderPlacehoderId);
	flashcontentDiv.hide();
	flashcontentDiv.html("");
	jQuery(".buttons_"+_recorderPlacehoderId).toggle();
	jQuery("#textComment").show();
	return false;
}


function showRecorder(_videoType, _title, _recorderPlacehoderId){
	var flashcontentDiv = jQuery("#"+_recorderPlacehoderId);
	
	if (flashcontentDiv){
		switch(_videoType){
			case "post":
				// resize flash content container
				flashcontentDiv.css("width","300px");
		 		flashcontentDiv.css("height","270px");
				//alert(_title);
				// push flash widget
				var so = new SWFObject(recorderVersion, "sobject", "300", "270", "9", "#ffffff");
				so.addVariable("title", _title);
				so.addVariable("allowAnonymous", 1);
				so.addParam("allowScriptAccess","always");
				so.addVariable("recState", "post");
				so.addVariable("blog_id", "www.yokway.com");
				so.addVariable("blog_name", "Yokway");
				so.useExpressInstall('swfobject/expressinstall.swf');
				so.write(_recorderPlacehoderId);
				
				// toggle video show / hide buttons
				jQuery(".buttons_"+_recorderPlacehoderId).toggle();
				jQuery("#textComment").hide();
				flashcontentDiv.show();
			break;
			case "comment":
			break;
		}
	}
	return false;
}

function showThumbnail(_thumbnail, _playerPlacehoderId) {
	hideRecorder(_playerPlacehoderId);
	var playerPlacehoder = jQuery("#"+_playerPlacehoderId);
	playerPlacehoder.css("height","40px");
	playerPlacehoder.html("<img height='40' src='"+_thumbnail+"'>");
	playerPlacehoder.show();
}

// This function is called by the seesmic player when user clicks on the "close button"
// showFlag = fase 
function see_play_video(videoId, showFlag){
	if (!showFlag){
		// hide player corresponding to this videoId...
		// show the thumbnail instead...
		// player shoud be in "#videoPlayerContainer_<videoId>"
		// thumbnail shoud be in "#videoThumbContainer_<videoId>"
		jQuery("#videoPlayerContainer_"+videoId).hide();
		jQuery("#videoThumbContainer_"+videoId).show();
		jQuery("#videoPlayerContainer_"+videoId).html("");
	} else {
		// hide thumbnail corresponding to this videoId...
		// show the player instead...
		// player shoud be in "#videoPlayerContainer_<videoId>"
		// thumbnail shoud be in "#videoThumbContainer_<videoId>"
		jQuery("#videoThumbContainer_"+videoId).hide();
		var videoPlayerContainer = jQuery("#videoPlayerContainer_"+videoId);
		if (videoPlayerContainer){
			seesmic.player.createPlayer(videoPlayerContainer[0], videoId, true, true);
			videoPlayerContainer.show();						
		} else {
			alert("Error occured : could not find video container for "+videoId);
		}
		
	}
}
// recording functions...
function hideRecorder2(_videoType,_recorderPlacehoderId,_thread_id){
	switch(_videoType){
		case 'post':
			var flashcontentDiv = jQuery("#"+_recorderPlacehoderId);
			flashcontentDiv.hide();
			flashcontentDiv.html("");
			jQuery(".buttons_"+_recorderPlacehoderId).toggle();
			jQuery("#textComment").show();
			return false;
			break;
		default:
			var flashcontentDiv = jQuery("#"+_recorderPlacehoderId);
			flashcontentDiv.hide();
			flashcontentDiv.html("");
			jQuery(".buttons_"+_recorderPlacehoderId).toggle();
			itemBlock(_thread_id).find("#commentinput").show();
			return false;
	}
}

function showRecorder2(_videoType, _title, _recorderPlacehoderId, _thread_id, _thread_name){
	var flashcontentDiv = jQuery("#"+_recorderPlacehoderId);
	
	if (flashcontentDiv){
		switch(_videoType){
			case "post":
				// resize flash content container
				flashcontentDiv.css("width","300px");
		 		flashcontentDiv.css("height","270px");
				//alert(_title);
				// push flash widget
				
				seesmic.player.createRecorder(flashcontentDiv[0], 'Yokway', '');
				// toggle video show / hide buttons
				jQuery(".buttons_"+_recorderPlacehoderId).toggle();
				jQuery("#textComment").hide();
				flashcontentDiv.show();
			break;
			default :
				// this is a comment recording...
				// _videoType = id of the item
				jQuery("#commentinput").hide();
				jQuery(".buttons_"+_recorderPlacehoderId).toggle();
				seesmic.player.createRecorder(flashcontentDiv[0], "Yokway", _thread_id);
				
				flashcontentDiv.show();				
			break;
		}
	}
	return false;
}




// called by seesmic recorder when video has been published.
// videoUri -> the url of the published video
// title -> the title of the video
// url_thumbnail -> the thumbnail of the video
// recState : that's where the magic is...
//	if (recState == "post"):
// 		the video is a post video
//  if (recState == "<somethingelse>")
// 		the video is a comment video and the recState is the item id
//  

//function videoFromRecorder(videoUri, title, url_thumbnail, recState, hasTitle)
function videoFromRecorder(videoUri, title, url_thumbnail, recState,hasTitle)
{
	if(recState=="post") {
		newVideo = '{seesmic_video:{';
			newVideo += '"url_thumbnail":{"value":"' + url_thumbnail + '"}';
			newVideo += '"title":{"value":"'+title+'&nbsp;"}';
			newVideo += '"videoUri":{"value":"' + videoUri + '"}';
		newVideo += '}}';
		
		if (document.getElementById("edButtonHTML")) {
			if(document.getElementById("edButtonHTML").tagName=="INPUT") {
				document.getElementById("edButtonHTML").click();
			}
			else {
				if(document.getElementById("edButtonHTML").onclick!=undefined) {
					document.getElementById("edButtonHTML").onclick();
				}
			}
		}

		
		
		//seesmicPageTracker._trackPageview("/post_video.html&blog="+escape(document.domain));
		jQuery("input[name='videoCommentThumbnail']").val(url_thumbnail);
		jQuery("input[name='videoCommentUri']").val(videoUri);
		jQuery("input[name='videoCommentTitle']").val(title);
		jQuery("input[name='videoCommentPartner']").val("seesmic");
		

		setTimeout("showThumbnail('"+url_thumbnail+"','flashcontent')", 1500);

				
	} else {
		// the video is a comment video
		// get the comment form fields
		
		//alert(title+" "+videoUri+" "+url_thumbnail);
		
		var videoCommentTitle = jQuery("#videoCommentTitle");
		var videoCommentUri = jQuery("#videoCommentUri");
		var videoCommentThumbUrl = jQuery("#videoCommentThumbUrl");
		videoCommentTitle.val(title);
		videoCommentUri.val(videoUri);
		videoCommentThumbUrl.val(url_thumbnail);
		
		//alert(title+" "+videoUri+" "+url_thumbnail);
		
		// then post the comment...
		saveComment();
		
	}

	
	return 'posted'
}
