css="<style type='text/css'>";
css+="div.edit img {cursor:pointer;cursor:hand;float:left;display:block;border:1px dotted #ccc;}";
css+="div.edit {clear:both;padding:10px;min-height:110px;}";
css+="</style>";
document.write(css);
function inputImage()
	{
	this.inputName=null; // jmeno tohoto objektu - instance inputImage
	this.total=0; // celkem zobrazeno obrazku
	this.max=255; // maximalni pocet polozek |W
	this.baseWeb="/"; // domovska slozka webu |W
	this.baseDir="modules/imce/file_imce.php?guid="; // cesta k obaryku bez konkretniho GUID
	this.emptyImg="nextmedia_extension/images/defaultni_obrazek.png"; // cestak praznemu obarazku
	this.imgPostfix="&thumbnail=1"; // parametr pro nahled
	this.baseWidth=130; // sirka obrazku miniatury |W
	this.baseHeight=100; //  vyska obrazku miniatury |W
	this.splitter=":"; // oddelovac GUID fotografii v db
	
	this.parse = function(iname)
		{
		this.inputName="inputImage_"+iname;
		inp = document.getElementsByTagName("input");
		for (this.i=0;this.i<inp.length;this.i++)
			{
			if (inp[this.i].name.indexOf(iname)!=-1)
				 {
				 obal=document.createElement("div");
 				 obal.style.backgroundColor="#eee";
 				 obal.style.padding="10px";
 				 inp[this.i].parentNode.appendChild(obal);
				 inp[this.i].style.visibility="hidden";
				 if (inp[this.i].value!="")
				 		{
					 if (inp[this.i].value!="") defsrc=this.baseWeb+this.baseDir+inp[this.i].value+this.imgPostfix;
					 this.arrSrc=inp[this.i].value.split(this.splitter);
					 
					 for (this.j=0;this.j<this.arrSrc.length;this.j++)
						 {
						 this.addImgBox(inp[this.i],this.arrSrc[this.j]);
						 }
					 }
				 this.addImgBox(inp[this.i],false);
				 }
			}
		}
	this.parseLinks = function(rodic)
		{
		inp = document.getElementsByTagName("input");
		lnk ="";
		for (this.k=0;this.k<inp.length;this.k++)
			{
			if (inp[this.k].className=="file_location")
			 {
			 if (inp[this.k].value!="") lnk+=inp[this.k].value+this.splitter;
			 }
		 }
 	  lnk=lnk.substring(0,lnk.length-1); // odstranit posledni dvojtecku
	  rodic.parentNode.getElementsByTagName("input")[0].value=lnk;
		}
	this.addImgBox = function(rodic,url)
			 	 {
			 	 this.total++;
			 	 if (this.total>this.max) return false;
			 	 rodic=rodic.parentNode.getElementsByTagName("div")[0]; // 1. div pozadovaneho input
				 if (!url)
						{
						turl=this.baseWeb+this.emptyImg;
						url="";
						}
			 	 else turl=this.baseWeb+this.baseDir+url+this.imgPostfix;;
			 	 obal=document.createElement("div");
		 		 obal.className="edit";
							 		  				 
		 		 img_preview=document.createElement("img");
				 img_preview.setAttribute("src",turl);
				 img_preview.setAttribute("width",this.baseWidth);				 
				 img_preview.setAttribute("height",this.baseHeight);
				 img_preview.setAttribute("alt",img_preview.src);
				 img_preview.style.display="block";
				 img_preview.onclick=new Function(this.inputName+".showDlg(this.parentNode.getElementsByTagName(\"input\")[0]);");
				 obal.appendChild(img_preview);
				 
				 tmp="this_"+this.genRandStr(16);
				 if (document.uniqueID) // MSIE nedokaze nastavit atr. NAME a VISIBILITY zpusobuje error
					 {
					 txt_url=document.createElement("<input type='text' name='"+tmp+"'>");
					 }
				 else
				 	 {
					 txt_url=document.createElement("input");
					 txt_url.setAttribute("type","text");
					 txt_url.setAttribute("name",tmp);
					 txt_url.style.visibility="hidden";
					 }
				 txt_url.setAttribute("value",url);
				 txt_url.setAttribute("id",tmp);
				 txt_url.setAttribute("defValue",url);
				 txt_url.className="file_location";
				 txt_url.onfocus=new Function(this.inputName+".changeImg(this);");
				 txt_url.onchange=new Function(this.inputName+".changeImg(this);");
				 txt_url.style.width="0";
				 txt_url.style.height="0";
				 txt_url.style.borderWidth="0";
				 txt_url.style.backgroundColor="transparent";
				 txt_url.style.color="#eee";
				 txt_url.style.cursor="default";
				 
				 obal.appendChild(txt_url);
				 
		 		 btn_submit=document.createElement("input");
				 btn_submit.setAttribute("type","button");
				 btn_submit.setAttribute("value","Procházet");
				 btn_submit.onclick=new Function(this.inputName+".showDlg(this.parentNode.getElementsByTagName(\"input\")[0]);");
				 obal.appendChild(btn_submit);

		 		 btn_delete=document.createElement("input");
				 btn_delete.setAttribute("type","button");
				 btn_delete.setAttribute("value","Žádný");
				 btn_delete.onclick=new Function("this.parentNode.getElementsByTagName('input')[0].value='';"+this.inputName+".changeImg(this.parentNode.getElementsByTagName('input')[0]);");
				 obal.appendChild(btn_delete);
				 rodic.appendChild(obal);
				 
				 br=document.createElement("hr");
				 br.style.clear="both";
				 br.style.visibility="hidden";
				 rodic.appendChild(br);
				 return true;
				 }
	this.changeImg = function(obj)
		{
		if (obj.value.length>16)
			{
			obj.value=obj.value.substring(obj.value.length-16); // poslednich 16 znaku
			}

		imgsrc=this.baseWeb+this.emptyImg;
		if (obj.value!="")
			{
			imgsrc=this.baseWeb+this.baseDir+obj.value+this.imgPostfix;
			if (obj.getAttribute('defValue')=="")
				 {
				 obj.setAttribute("defValue",obj.value);
			 	 this.addImgBox(obj.parentNode.parentNode);
			 	 }
			 }
	  img=obj.parentNode.getElementsByTagName("img");
	  img[0].src=imgsrc;
		this.parseLinks(obj.parentNode.parentNode);
		}
	this.showDlg = function(elname)
		{
		imceImageBrowser(elname.name, elname.value, "txtLnkUrl", window);
		}
	this.genRandStr = function(delka)
		{
		znaky="abcdefghijklmnopqrstuvwxyz123456789";
		var retezec;
		retezec="";
		for (var x=0; x <= delka; x++)
			{
			retezec+=znaky.charAt(Math.round(Math.random()*(znaky.length-1)));
			}
		return retezec;
		}
	}

