// JavaScript Document
var editor_content = "";
var currentFrame = "";
var pageContentData = "";
var cssPath = "";

function setContent(html_content)
{
	editor_content = html_content;
	//var objFrame = window.frames[0];
	//alert("objFrame.name: " + currentFrameName + " | " + pageContentData);
	if(currentFrame != null)
	{
		if ( currentFrame.contentDocument ) { // DOM
			currentFrame.setContent(html_content);
			if(currentFrame.getContent() == editor_content)
			{
				editor_content = "";
			}
	    } else if ( currentFrame.contentWindow ) { // IE win
			currentFrame.contentWindow.setContent(html_content);
			if(currentFrame.contentWindow.getContent() == editor_content)
			{
				editor_content = "";
			}
		}
		/*
		currentFrame.setContent(html_content);
		if(currentFrame.getContent() == editor_content)
		{
			editor_content = "";
		}
		*/
	}
}

function getIsReady()
{
	var objFrame = window.frames[0];
	var is_ready = objFrame.isEditorReady();
	if(is_ready == true)
	{
		getFlashMovie("admin").getIsReadyCallback();
	}				
}

function getInitial()
{
	var objFrame = window.frames[0];
	var editor_content = objFrame.getContent();
	getFlashMovie("admin").getInitialCallback(editor_content);
}

function getContent()
{
	var objFrame = window.frames[0];
	var editor_content = objFrame.getContent();
	getFlashMovie("admin").getContentCallback(editor_content);
}

function resetContent()
{
	var objFrame = window.frames[0];
	var editor_content = objFrame.getContent();
	getFlashMovie("admin").getResetCallback(editor_content);
}
/*
function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
*/

function getFlashMovie(movieName) {
	if (window.document[movieName]) {
    	return window.document[movieName];
	}
  
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
  		if (document.embeds && document.embeds[movieName]) {
			return document.embeds[movieName];
		}
	} else { // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	    return document.getElementById(movieName);
  	} 	
}

function getMediaPlayerPreview(obj) {
	tb_show(obj.title, obj.url + "&height=" + obj.height + "&width=" + obj.width + "&swfpath=" + obj.swfpath + "&TB_iframe=true", "");
}

function getVideoPreview(obj) {
	tb_show(obj.title, obj.url + "&height=" + obj.height + "&width=" + obj.width + "&videopath=" + obj.videopath + "&videowidth=" + obj.videowidth + "&videoheight=" + obj.videoheight + "&TB_iframe=true", "");
}

function getImagePreview(obj) {
    tb_show(obj.title, obj.url + "&height=" + obj.height + "&width=" + obj.width + "&imagepath=" + obj.imagepath + "&imagewidth=" + obj.imagewidth + "&imageheight=" + obj.imageheight + "&TB_iframe=true", "");
}

function getImageEditor(obj) {
    tb_show(obj.title, obj.url + "&height=" + obj.height + "&width=" + obj.width + "&serviceurl=" + obj.serviceurl + "&assetpath=" + obj.assetpath + "&imageid=" + obj.imageid + "&imageformatid=" + obj.imageformatid + "&formatwidth=" + obj.formatwidth + "&formatheight=" + obj.formatheight + "&formatdirectory=" + obj.formatdirectory + "&TB_iframe=true", "");
}

function closeImageEditor() {
	alert('closeImageEditor()');
	getFlashMovie("admin").getCloseImageEditorCallback();
	tb_remove();
}

function getHtmlEdit(obj) {
	pageContentData = obj.pagecontentdata;
	cssPath = obj.csspath;
	tb_show(obj.title, obj.url + "?height=" + obj.height + "&width=" + obj.width + "&TB_iframe=true", "");			
	currentFrame = $('#TB_iframeContent');
	currentFrame.load(function() {	// wait for iframe to load
		currentFrameName = this.name;
		setEditorContent();
	});
}

function saveHtmlEdit() {
	//alert('saveHtmlEdit()');
	getFlashMovie("admin").getSaveHtmlCallback();
}

function closeHtmlEdit() {
	tb_remove();
}

function popupClosed() {
	currentFrameName = "";
	getFlashMovie("admin").getClosePopupCallback();
}

function setEditorContent()
{
	setContent(pageContentData);
}
