<?php

/**
 *
 * @author Peter Csubak (chuby)
 * @copyright Peter Csubak (chuby)
 */
class PImage extends PComponent{

	/** @CProperty */
	protected $src;
	/** @CProperty */
	protected $alt;
	/** @CProperty */
	protected $height;
	/** @CProperty */
	protected $width;
	/** @CProperty */
	protected $style;
	
	public static $evtOnClick = 1;
	public static $evtOnMouseOver = 2;
	public static $evtOnMouseOut = 3;
	public static $evtOnDoubleClick = 4;
	public static $evtOnAbort = 5;
	
	public function __construct($src="", $alt="", $height="", $width = "", $id = "", $cssclass = "", $style = "", $evtslock = ""){
		$this->src = $src;
		$this->alt = $alt;
		$this->width = $width;
		$this->height = $height;
		$this->id = $id;
		$this->cssclazz = $cssclass;
		$this->style = $style;
		$this->eventsLock = $evtslock;
	}
	
	public function render(){
		$res = "<img";
		
		if ($this->id != ""){
			$res .= " id=\"".$this->id."\"";
		}
		
		if ($this->cssclazz != ""){
			$res .= " class=\"".$this->cssclazz."\"";
		}
		
		if ($this->style != ""){
			$res .= " style=\"".$this->style."\"";
		}
		
		if ($this->alt != ""){
			$res .= " alt=\"".$this->alt."\"";
		}
		
		if ($this->src != ""){
			$res .= " src=\"".$this->src."\"";
		}
		
		if ($this->width != ""){
			$res .= " width=\"".$this->width."\"";
		}
		
		if ($this->height != ""){
			$res .= " height=\"".$this->height."\"";
		}
		
		if (is_array($this->activeEvents)){
			foreach ($this->activeEvents as $evtTypes){
				if ($evtTypes == self::$evtOnClick){   //TYPE			SENDEDFROM			BINDEDTO				LOCK
					$res .= " onclick=\"sendAjaxEvent('AjaxOnClick', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
				if ($evtTypes == self::$evtOnDoubleClick){
					$res .= " ondblclick=\"sendAjaxEvent('AjaxOnDoubleClick', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
				if ($evtTypes == self::$evtOnMouseOut){
					$res .= " onmouseout=\"sendAjaxEvent('AjaxOnMouseOut', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
				if ($evtTypes == self::$evtOnMouseOver){
					$res .= " onmouseover=\"sendAjaxEvent('AjaxOnMouseOver', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
				if ($evtTypes == self::$evtOnAbort){
					$res .= " onmouseover=\"sendAjaxEvent('AjaxOnAbort', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
			}
		}
		
		$res .= " />";
	}
	
}
?>