jQuery(document).ready(function($){

var init = function(){
	layout.adjust();
	preview.display();
	menu.action();
	$('#kzms2txt').keyup(function(){preview.display();});
	$(window).resize(function(){layout.adjust();});
}

var layout = {
	adjust:function(){
		var tmpH = (($(window).height()-$('#header').height())/2)-13;
		$('#kzms2txt,#kzms2preview').height(tmpH);
	}
}

var menu = {
	action:function(){
		$('#nav1').click(function(){
			var msg = window.prompt('edit file name.\nand download this file',$('#header > h1 > strong:first').text());
			if(msg!=null){
				window.open('getFile.php?name='+msg+'&content='+encodeURI($('#kzms2txt').val()));
				$('#header > h1 > strong:first').text(msg);
				$('title:first').text($('#header > h1 > strong:first').text());
			}
			return false;
		});
		$('#nav2').click(function(){
			var tmpFz = parseInt($('#kzms2txt,#kzms2preview').css('font-size'));
			var msg = window.prompt("edit font size.",tmpFz);
			if(msg!=null)$('#kzms2txt,#kzms2preview').css('font-size',msg+'px');
			return false;
		});
		$('#nav3').click(function(){
			zen_textarea.showInfo();
			return false;
		});
		$('#nav4').click(function(){
			if(window.confirm('kzms2 zen-coding editor are powered by kzms2.\ngo to kzms2.com?')){
				window.open('http://kzms2.com');
			}
			return false;
		});
	}
}

var preview = {
	display:function(){
		var tmpHTML = $('#kzms2txt').val();
		$('#kzms2preview').contents().find('html').html(tmpHTML);
	}
}

init();

});
