imgClass = function ()
{
	var uniqid;
	var response;
	var isIE;
	var formname;
	
	this.init = function (id, lang)
	{
		uniqid = id;
		isIE   = (navigator.appName=="Microsoft Internet Explorer") ? true : false;
		formname = lang;
	}
	
	this.progress = function ()
	{
		var path = "?module=pic&do=ajax&go=progressbar&uniqid="+uniqid;
		var req;
		
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			if (req.overrideMimeType) {
				req.overrideMimeType('text/xml');
			}
		} else if (window.ActiveXObject) { // IE
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		
		if (!req) {
			return false;
		}

		req.onreadystatechange = function()
		{
			if (req.readyState==4)
			{
				if (req.status == 200)
				{
					response = req.responseText;
					
					var data = eval ('('+ response + ')');
					document.getElementById("progress_current").innerHTML = data["CURRENT"];
					document.getElementById("progress_total").innerHTML = data["TOTAL"];
					document.getElementById("progress_bar").style.width = (data["PROGRESS"]*400)+"px";
				}
			}
		}

		req.open("GET",path,true);
		req.send(null)
	}
	
	this.timeout = function ()
	{
		this.progress ();
		this.timeLoop ();
	}
	
	this.timeLoop = function ()
	{
		window.setTimeout (function() { imgClass.timeout(); }, 1000, this);
	}

	this.openFile = function (id)
	{
		document.getElementById("file_"+id).dblclick();
	}
	
	this.createBox = function (id)
	{
		var W3CDOM = (document.createElement && document.getElementsByTagName);
		var agent = navigator.userAgent.toLowerCase();
		
		if (agent.indexOf ("firefox")<0) return;
		
		var fileBox = document.createElement ("div");
		fileBox.className = 'form_upfield';
		fileBox.id = 'fileb_'+id;

		fileBox.innerHTML = formname;
		
		var divclear = this.clearDiv();
		
		fileBox.appendChild (divclear);
		
		var input = document.getElementById ("file_"+id);
		input.className = "form_file";
		input.onchange = input.onmouseout = function () { imgClass.changeFile(id); }
		
		document.getElementById("up_"+id).appendChild (fileBox);
	}
	
	this.addUpField = function ()
	{
		var x = document.getElementsByTagName ("input");
		var t=0;
		for (var i=0;i<x.length;i++)
		{
			if (x[i].type != "file") continue;
			t++;
		}
		
		if (t < 5)
		{
			t++;
			
			var div = document.createElement ("div");
			div.className = "form_upload";
			div.id = "up_"+t;
			var file = document.createElement ("input");
			file.type = "file";
			file.id = "file_"+t;
			file.name = "file_"+t;
			
			var divclear = this.clearDiv();
			
			div.appendChild (file);
			div.appendChild (divclear);
			
			var parent = document.getElementById ("upForm");
			parent.appendChild (div);
			
			this.createBox (t);
			
			if (t>=5)
			{
				document.getElementById ("morepics").style.display = "none";
				document.getElementById("uppics").style.marginLeft=430+"px";
			}
		}
	}
	
	this.changeFile = function (id)
	{
		var agent = navigator.userAgent.toLowerCase();
		if (agent.indexOf ("firefox")<0) return;
		input = document.getElementById ("file_"+id);
		div = document.getElementById ("fileb_"+id);
		var value = input.value;
		if (value) {
			if (value.length > 40) value = value.substr(0,40)+"...";
			div.innerHTML = value;
		}
	}
	
	this.clearDiv = function ()
	{
		var divclear = document.createElement ("div");
		divclear.className = "clear";
		
		return divclear;
	}
	
	this.upload = function ()
	{
		var agent = navigator.userAgent.toLowerCase();
		if (document.getElementById("file_1").value != "")
		{
			var height = (window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight;
												 
			var width = document.getElementById ("upForm").offsetWidth;
			var div = document.getElementById ("waiting");
	
			div.style.display = "block";
			div.style.height = height+"px";
			div.style.width = "100%";
			
			document.getElementById ("progressbar_container").style.display = "block";
	
			if (agent.indexOf ("applewebkit")<0)
			{
				this.timeLoop();
				this.formSubmit();
			}
			else {
				this.chromeWorkAround();
			}
			
		} else {
			alert ("Sie haben keine Datei zum hochladen angegeben.");
		}
	}
	
	this.formSubmit = function ()
	{
		document.form_upload.submit();
	}
	
	this.chromeWorkAround = function ()
	{
		Bild = new Image();
		Bild.src = "gfx/ajax-loader.gif";
		document.getElementById("progressbar_container").innerHTML = "<img src='gfx/ajax-loader.gif' onload='imgClass.formSubmit()' border=0><br>waiting .."
		return true;
	}
	
	this.folderScrollDown = function ()
	{
		var _select = document.getElementById ("FOLDER_SCROLLDOWN");
		if (_select.style.display == "block")
		{
			_select.style.display = "none";
		} else {
			_select.style.display = "block";
		}
	}
	
	this.folderSelect = function (id)
	{
		var value = document.getElementById ("FOLDER_"+id).innerHTML;
		document.getElementById("FOLDER_SELECTED").innerHTML = value;
		document.getElementById("f_select").value = id;
		
		this.folderScrollDown();
	}
	
	this.EditSettingsImage = function (imageId)
	{
		var height = (window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight;
											 
		var width = document.getElementById ("upForm").offsetWidth;
		var div = document.getElementById ("waiting");

		div.style.display = "block";
		div.style.height = height+"px";
		div.style.width = "100%";
	}
}
