<?php

/**
 * FormCkeditor
 *
 * @author Arkadiusz Rychlik <a.rychlik at eppe.com.pl>
 */
class Eppe_View_Helper_FormCkeditor extends Zend_View_Helper_FormTextarea  {

	public function FormCkeditor($name, $value = null, $attribs = null) {

		$html = <<<EOF
			<script>
				$(function(){
					ajx.loader.show();
			
					var formCkeditor$name = {
						init: function() {
							CKEDITOR.replace('$name');
							CKEDITOR.instances.$name.on('change',function(){
								$('textarea#$name').html(CKEDITOR.instances.$name.getData());
							});
							CKEDITOR.instances.$name.on('instanceReady', function(){
								ajx.loader.hide();
							});
						}
					};
			
					if(typeof CKEDITOR == "undefined"){
						window.CKEDITOR_BASEPATH = "/vendors/ckeditor/";
						$.getScript("/vendors/ckeditor/ckeditor.js", function() {
							formCkeditor$name.init();
						});	
					}
					else{
						formCkeditor$name.init();
					}
								
				});
			</script>
EOF;

		return $html . $this->formTextarea($name, $value, $attribs);

	}

}
