var Visuals = Class.create();
Visuals.prototype =
{
	initialize: function( path_http )
	{
		//
		this.switchProcess = 0;
		this.path_http = path_http;

		this.small_loader = '<img src="' + this.path_http + 'img/small_loading.gif" border="0" alt="" />';
		this.big_loader = '<img src="' + this.path_http + 'img/loading.gif" border="0" alt="" />';
		this.mid_loader = '<img src="' + this.path_http + 'img/mid_loading.gif" border="0" alt="" />';
	},
	submitForm: function (form,id)
	{
		if ($(id))
		{
			$(id).update(this.big_loader);
		}
		setTimeout(
			function() {
				$(form).submit();
			}
			,0
		);
		return false;
	},
	menuSwitch: function (id) {
		var childList = 'child_' + id;
		var parentLi = 'parent_' + id;
		var obj_temp = this;
		if (obj_temp.switchProcess == 0 ) {
			obj_temp.switchProcess = 1;
			var swStatus = $(childList).getStyle('display');
			if ( swStatus == 'block') {
				new Effect.BlindUp(childList, {
						duration: 1,
						afterFinish: function() {
							obj_temp.switchProcess = 0;
							obj_temp.setMenuStatus(id, 0);
						}
					}
				);
			} else {
				new Effect.BlindDown(childList,
				{
					duration: 1,
					afterFinish: function() {
						obj_temp.switchProcess = 0;
						obj_temp.setMenuStatus(id,1);
					}
				}
			);

			}
		}
	},
	setMenuStatus: function (_name, value)
	{
		var uri = encodeURI( this.path_http + 'set_menu_status.ajax,' + _name + ',' + value);
		//alert(uri);
		new Ajax.Request(
				uri ,
			{
				onSuccess: function(t){
					//alert(t.responseText);
				},
		      	onFailure: function(t){alert(t.status);},
		      	onError: function(t){alert(t.status);},
		      	onComplete: function(t){}
			}
		);
	},
	imgPreloader: function (arr_img)
	{
		var imageArray = new Array();

		for(var i=0; i<arr_img.length; i++)
		{
			imageArray[i] = new Image();
			imageArray[i].src = arr_img[i];
		}
	},
	tooltip: function (textlabel)
	{
		var mode = 'tooltip';
		var key = 0;
		var uri = encodeURI(this.path_http + 'handler.ajax/' + mode + ',' +  key + ','  + textlabel);
		var tooltip_loader = '<img src="' + this.path_http + 'img/tooltip/tooltip_loading.gif" border="0" alt="" />';
		new Ajax.Request(
			uri , {
				onComplete: function(t){
					var tiptext = t.responseText;
					overlib(tiptext, LEFT,WIDTH, 360, HEIGHT, 50, PADX , 0,0, PADY, 0, 0)
					new Effect.Appear(key);
				}
			}
		);
	},
	switchView:function ( left, right ){

		var left_element = $(left).style;
		var right_element = $(right).style;
		if (right_element == 'none') {
			left_element.display = 'none';
			right_element.display = 'block';

		} else {
			left_element.display = 'block';
			right_element.display = 'none';
		}
	},
	changeColorPrev: function (id, element)
	{
		if (element.value.length == '4' || element.value.length == '7')
		{
		$(id).setStyle( {background: element.value});
		}
	},

	cloneElement: function (parentID)
	{
		var child_nodes = $(parentID).childNodes;
		if ( navigator.appName == 'Microsoft Internet Explorer') {
			var counter = child_nodes.length ;
		} else {
			var counter = child_nodes.length -2;
		}
		if ( counter > 0 ) {
			$( 'btn_reduce_' + parentID ).setStyle({ display: 'block'});
		}
		if ( counter <= 2 ) {
			var newId = ( Number(counter) + Number (1));
			var cloneID = parentID + '_' + counter;

			var div_selectbox = $(cloneID).cloneNode(true);

			$(div_selectbox).id = parentID + '_' + newId;
			$(div_selectbox).value = '';
			$(parentID ).appendChild(div_selectbox);
		}
	},
	removeElement: function (parentID) {
		var child_nodes = $(parentID).childNodes;
		if ( navigator.appName == 'Microsoft Internet Explorer') {
			var counter = child_nodes.length +1;
			var link = $(parentID).childNodes[1];
		} else {
			var counter = child_nodes.length -1;
			var link = $(parentID).childNodes[counter];
		}
		if (counter > 1) {
			$(parentID).removeChild(link);
		}

		if (counter == 3) {
			$( 'btn_reduce_' + parentID ).setStyle({ display: 'none'});
		}
	},
	formDefault: function(_this,focused,defstr)
	{
		if (focused) {
			if (defstr && _this.value == defstr) _this.value = "";
		} else {
			if (defstr && _this.value == "") _this.value = defstr;
		}
	},
	closeBgLayer: function() {
		new Effect.Fade('bg_layer',{ duration: 0.2, from: 0.8, to: 0.0 });
		new Effect.Fade('bg_layer_content',{ duration: 0.2, from: 0.8, to: 0.0 });
	},
	showBgLayer: function() {
		var arr_size = this.getPageSize();
		var arr_scroll = this.getPageScroll();
		$('div_content').update('<img src="' + this.path_http + 'img/loading.gif" style="margin-top: 50px;margin-bottom: 50px;" />');
		$('bg_layer').style.height = arr_size[1]+'px';
		new Effect.Appear('bg_layer', { duration: 0.2, from: 0.0, to: 0.8 });
		$('bg_layer_content').style.marginTop = (arr_scroll[1]-100) + 'px';
		new Effect.BlindDown('bg_layer_content');
	},
	getPageScroll: function() {
           var y_scroll;

           if (self.pageYOffset){
                y_scroll = self.pageYOffset;
           } else if (document.documentElement && document.documentElement.scrollTop) {
           	// Explorer 6 Strict
                y_scroll = document.documentElement.scrollTop;
           } else if (document.body) {// all other Explorers
                y_scroll = document.body.scrollTop;
           }

           arr_page_scroll = new Array('',y_scroll)
           return arr_page_scroll;
	},
	getPageSize: function() {
		var x_scroll, y_scroll;
		var window_width, window_height;
		var page_width, page_height;

		if (window.innerHeight && window.scrollMaxY) {
			x_scroll = document.body.scrollWidth;
			y_scroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) {
		// all but Explorer Mac
                x_scroll = document.body.scrollWidth;
                y_scroll = document.body.scrollHeight;
           } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
                x_scroll = document.body.offsetWidth;
                y_scroll = document.body.offsetHeight;
           }


           if (self.innerHeight) {     // all except Explorer
                window_width = self.innerWidth;
                window_height = self.innerHeight;
           } else if (document.documentElement && document.documentElement.clientHeight) {
           	// Explorer 6 Strict Mode
                window_width = document.documentElement.clientWidth;
                window_height = document.documentElement.clientHeight;
           } else if (document.body) { // other Explorers
                window_width = document.body.clientWidth;
                window_height = document.body.clientHeight;
           }

           // for small pages with total height less then height of the viewport
           if(y_scroll < window_height)  {
                page_height = window_height;
           } else {
                page_height = y_scroll;
           }

           // for small pages with total width less then width of the viewport
           if(x_scroll < window_width) {
                page_width = window_width;
           } else {
                page_width = x_scroll;
           }
           arr_page_size = new Array(page_width,page_height,window_width,window_height)
           return arr_page_size;
      },
	clipBoard: function(id,clip_text,input_width) {
		var width = 250;
		if(typeof input_width != 'undefined')
		{
			width = input_width;
		}

	  	var bool_cur = (this.id_cur != id) ? true : false;

	  	// zuvor geöffnete ablage schließen
	  	if(this.id_cur != '')
	  	{
	  		$(this.id_cur).update(this.str_inner);
	   		$(this.id_cur).onclick = this.on_click;

			this.id_cur = '';
			this.on_click = '';
			this.str_inner = '';

			// wenn overlib verwendet wird muss diese funktion aufgerufen werden das es nicht zu fehlern kommt
			if(typeof nd == 'function')	{nd();}
		}
		if(bool_cur)
		{
			var str_link = clip_text;
			this.str_inner = $(id).innerHTML;
			this.id_cur = id;
			this.on_click = $(id).onclick;
			$(id).onclick = '';

			var first_node = $(id).firstChild;
			var input_node = Builder.node('input', {value: str_link, style: 'width:' + width + 'px;', onclick: 'this.select();'});
			$(id).replaceChild(input_node,first_node);

			var img_href = Builder.node('img',{src: this.path_http + 'img/icons/btn_clipboard_close.png', border: '0', alt: ''});
			img_href.onclick =  this.on_click;
			var space = document.createTextNode(' ');
			$(id).appendChild(space);
			$(id).appendChild(img_href);
		}
	},
	imagePopUp : function (url,b,h) {
		var eigenschaften,sbreite,shoehe,fenster,b,h;
		var FestePosition = "ja";  // "ja" oder "nein" eintragen
		VonLinks = 20;
		VonOben = 20;
		if(FestePosition == "ja") {
			x = VonLinks;
			y = VonOben;
		} else {
			var ns6 = (!document.all && document.getElementById);
			var ie4 = (document.all);
			var ns4 = (document.layers);

			if(ns6||ns4) {
				sbreite = innerWidth;
				shoehe = innerHeight;
			} else if(ie4) {
				sbreite = document.body.clientWidth;
				shoehe = document.body.clientHeight;
			}

			alert("festgestellte Höhe: " + shoehe);
			x = (sbreite-b)/2;
			y = (shoehe-h)/2;

			}
			eigenschaften="left="+x+",top="+y+",screenX="+x+",screenY="+y+",width="+b+",height="+h+",menubar=no,toolbar=no,statusbar=0";
			fenster=window.open("","",eigenschaften);
			fenster.focus();
			fenster.document.open();
			with (fenster) {
			  document.write("<html><head>");
			  document.write('<scr' + 'ipt type="text/javascr' + 'ipt" language="JavaScr' + 'ipt">');
			  document.write("function click() { window.close(); } ");
			  document.write("document.onmousedown=click ");
			  document.write('</scr' + 'ipt>');
			  document.write("<title>klick to close</title></head>");
			  document.write("<" + "body onblur='window.close()';");
			  document.write("marginwidth='0' marginheight='0' leftmargin='0' topmargin='0'>");
			  document.write("<img src='"+ url +"' border='0'>");
			  document.write("</body></html>");
			  fenster.document.close();
			}

	}
}