tar_xs ={
	init:function(){
		if($("object[type='application/x-xstandard']").length>0){
			$("form").each(function(){
				tar_xs.events(this);
			});
		}
	},
	events:function(elem){
		$(elem).bind("submit",function(){
			$(elem).find("object[type='application/x-xstandard']").each(function(){
				var applid=$(this).attr("id").replace("xstd-","hdn-");
				if(!($(this).val()=="")){
					$(this).EscapeUnicode=true;
					var getval=$(this).val();
				}else{
					var getval=$(this).find("textarea").val();
				}
				$("#"+applid).val(getval);
			});
		});
	},
	buttons:{
		"fullscreen":function(elem,id){
			document.getElementById(id).ToolbarWysiwyg=document.getElementById(id).ToolbarWysiwyg.replace("fullscreen","restore-down");
			$(elem).attr("id","fullsize_editor");
			tar_xs.helpers.fullscreen.position(elem,"size");
			$(window).resize(function(){
				tar_xs.helpers.fullscreen.position($("#fullsize_editor"),"resize");
			}).scroll(function(){
				tar_xs.helpers.fullscreen.position($("#fullsize_editor"),"scroll");
			});
			
		},
		"restore-down":function(elem,id){
			document.getElementById(id).ToolbarWysiwyg=document.getElementById(id).ToolbarWysiwyg.replace("restore-down","fullscreen");
			$(window).unbind("resize").unbind("scroll");
			$(elem).removeAttr("style");
		}
	},
	helpers:{
		fullscreen:{
			position:function(elem,mode){
				var gotop=(0-Math.floor($(elem).offset().top))+$(window).scrollTop();
				var goleft=(0-Math.ceil($(elem).offset().left));
				var gowidth=parseInt($("body").outerWidth());
				var goheight=(typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.offsetHeight);
				if(mode!="size"){
					gotop=gotop+parseInt($(elem).css("top"));
					goleft=goleft+parseInt($(elem).css("left"));
				}
				$(elem).css({"top":gotop,"left":goleft,"width":gowidth,"height":goheight,"border-width":0});
			}
		}
	}
}

function xsButtonClicked(id,button,state) {
	if(button in tar_xs.buttons){
		tar_xs.buttons[button]($("#"+id).parent(),id);
	}
}

$(document).ready(function(){tar_xs.init()});
