cAPI = function() {

	this.init = function(evt) {

		if (APL_LOGGED != '' && APL_LOGGED == 'admin') {
			js = new API.createElement('script', 'JSscript' + (Math.random() + 100), 'absolute', -5, 18, 0, 0, 1);
			js.setAttribute('src', APL_ROOT + 'js/SEO.js');
			document.body.appendChild(js);			
		}
		
		API.editing = '';
		API.button = '';
		API.menuTimer = '';
		Element.hide('systemWorking');
		API.maxZ = 100;
		API.idGen = 1;
		API.mx = 0;
		API.my = 0;
		
		API.rememberList = getCookie('rememberList');
		if (!API.rememberList) API.rememberList = new Array();
		disp = API.rememberList;
		if (disp) if (disp.indexOf('%3A') != -1) {
			re = /%3A/gi;
			disp = disp.replace(re, ":");
			re = /%2C/gi;
			disp = disp.replace(re, ',');
			API.rememberList = new Array();
			while (disp != '') {
				a1 = disp.indexOf(":");
				a2 = disp.indexOf(",");
				API.rememberList[disp.substr(0, a1)] = disp.substr(a1 + 1, a2 - a1 - 1);
				disp = disp.substr(a2 + 1);
			}
		}

		API.rememberList[API.rememberList.length] = window.location;
		setCookie('rememberList', API.rememberList.serializeC(), null, '/');

		API.fixLayout();
		API.control();

		var AJAXrequests = {
			onCreate: function(){
				Element.show('systemWorking');
			},

			onComplete: function() {
				if(Ajax.activeRequestCount == 0){
					Element.hide('systemWorking');
					API.hooks();
				}
			}
		};

		Ajax.Responders.register(AJAXrequests);
		API.throbber('systemWorking');

		API.hooks('start');

		o = new API.createElement('div', API.AJAXTarget = 'AJAXTarget', 'absolute', 0, 220, 300, 150, 10);
		o.innerHTML = '&nbsp;';
		o.style.backgroundColor = 'white';
		o.style.border = '1px solid black';
		o.style.overflow = 'hidden';
		o.style.display = 'none';
		document.body.appendChild(o);
		
		API.parseContent();
		
	};
	
	this.parseContent = function() {
		jQuery('.shopTitle a, .floorplanImage map area, .floorImage a').each(function(i){
			if (this.href != '' && this.target!='_blank') {
				this.onclick = function(){
					API.loadContent(this.href);
					return false;
				};
			};
		});
		jQueryThickBox();
		jQuery("#parsingLink").hide();
	};
	
	this.loadContent = function(url) {
		if(document.getElementById("parsingLink") === null){
			jQuery("body").append("<div id='parsingLink'>&nbsp;</div>");
		}
		jQuery("#parsingLink").show();
		jQuery.get(url, {},
	  		function(data){
	  			res = data;
				find = '<div id="floorplan_div">';
				res = res.substr(res.indexOf(find) + find.length);
				find = '</div><!-- floorplan -->';
				res = res.substr(0, res.indexOf(find));
				jQuery('#floorplan_div').html(res);
				
				API.parseContent();
	  		});
  	};

	this.altText = function(text) {
		if (!document.getElementById('mouseHover')) return;
		obj = $('mouseHover');
		if (!text) {
			obj.innerHTML = '';
			obj.style.display = 'none';
			setTimeout(function(){
				 $('mouseHover').style.display = 'none';
			}, 500);
			setTimeout(function(){
				 $('mouseHover').style.display = 'none';
			}, 1000);
		} else {
			obj.style.left = (API.mx + 10) + 'px';
			obj.style.top = (API.my + 10) + 'px';
			obj.style.zIndex = API.maxZ++;
			obj.innerHTML = text;
			setTimeout(function(){
				 if ($('mouseHover').innerHTML != '') $('mouseHover').style.display = 'block';
			}, 3000);
		}

	};

	this.hooks = function(start) {
		setTimeout(function() {
			API.fixLayout();
		}, 50);
		
		if (!document.getElementById('APLLayout')) return;
		if (!start) {} else {
			if (typeof jQueryThickBox != 'undefined') jQueryThickBox();
			jQuery('ul.floorplanImageMap li').ifixpng(); 
		}
	};

	this.aDown = function(evt) {
		var obj = Event.element(evt);
		alert(obj.parentNode.nodeName);
	};

	this.control = function() {

		if (APL_LOGGED != '' && APL_LOGGED == 'admin') {
			Event.observe('APLLayout', 'click', API.clicked, false);
			Event.observe('APLLayout', 'contextmenu', API.clicked, false);
			Event.observe('APLLayout', 'dblclick', API.dblclicked, false);
		} else {
		}
		Event.observe('APLLayout', 'mousemove', API.move, false);
		Event.observe(window, 'unload', function() {
			Event.stopObserving('APLLayout', 'click', API.clicked, false);
			Event.stopObserving('APLLayout', 'contextmenu', API.clicked, false);
			Event.stopObserving('APLLayout', 'dblclick', API.dblclicked, false);
			Event.stopObserving('APLLayout', 'mousemove', API.move, false);
			$('APLLayout').focus();
		}, false);

	};

	this.fixLayout = function() {

	};

	this.clicked = function(e) {

	    if (e.which == null)
	       API.button = (e.button < 2) ? "left" :
	                 ((e.button == 4) ? "middle" : "right");
	    else
	       API.button = (e.which < 2) ? "left" :
	                 ((e.which == 2) ? "middle" : "right");

		if (API.button != 'right' && e.type != 'contextmenu') return;

	    if (e.preventDefault) {
	        e.preventDefault();
	    } else {
	        e.returnValue = false;
		};
		Event.stop(e);

		var x = Event.pointerX(e) - 10;
		var y = Event.pointerY(e) - 10;
		var id = Event.element(e).getAttribute('id');
		if (id == '') {
			now = new Date;
			var id = 'GeneratedID_' + now.getTime();
		};
		setTimeout(function(){
			API.clickedAfter(x, y, Event.element(e));
		}, 1);


		return false;

	};

	this.clickedAfter = function(x, y, child) {

		if (API.button == 'right') {

			var block = API.findParentHasClass(child, 'PageBlock');
			if (typeof block != 'undefined') {
				var id = API.findParentHasClass(child, 'editable');

				if (typeof id != 'undefined')
					API.contextM(x, y, block, id);
				else
					API.contextM(x, y, block);

			};

		};

	};

	this.contextM = function(x, y, block, id) {

		if (!block) return;

		o = new API.createElement('ul', API.activeMenu = 'AdminEditMenu', 'absolute', x, y, 0, 0, API.maxZ++);
		o.style.backgroundColor = 'Silver';
		o.style.display = 'none';
		o.style.border = '1px solid black';
		o.style.margin = o.style.padding = '0px';
		o.style.overflow = 'hidden';

		document.body.appendChild(o);
		Effect.Appear(o);

		tpl = '<li onclick="setTimeout(function(){Element.remove(API.activeMenu);}, 1);" style="cursor: pointer; padding: 2px 10px 2px 2px;"><a  onmouseover="this.style.backgroundColor=\'#eee\';API.menuTimer = \'no\';" onmouseout="this.style.backgroundColor=\'\';API.menuTimer = \'yes\';menuTimer();" style="text-decoration: none; color: black;" href="javascript:void(0);" onclick="';

		if (!id) {} else {
			if ($(id).getAttribute('type_id') == 1) o.innerHTML = tpl + 'API.editElement($(\'' + id + '\'));">editovat prvek</a></li>';
			o.innerHTML += tpl + 'API.deleteElement(\'' + id + '\');">vymazat prvek</a></li>';
			o.innerHTML += '<li><hr/></li>';
		};

		o.innerHTML += tpl + 'API.addElement(\'' + block + '\');">vložit prvek</a></li>';
		o.innerHTML += tpl + 'API.addModule(\'' + block + '\');">vložit modul</a></li>';

		o.innerHTML += '<li><hr/></li>';
		o.innerHTML += tpl + 'API.sortingStart();">přesunout prvky</a></li>';

		Event.observe(API.activeMenu, 'mouseout', function(e) {
			var size = Element.getDimensions(API.activeMenu);
			var x = $(API.activeMenu).offsetLeft;
			var y = $(API.activeMenu).offsetTop;
			if ((Event.pointerY(e) < y && Event.pointerY(e) > y + size.height) && (Event.pointerX(e) < x && Event.pointerX(e) > x + size.width)) {
				API.menuTimer = 'yes';
			} else {
				API.menuTimer = 'no';
			};
		}, true);

		menuTimer = function() {
			setTimeout(function() {
				if (API.menuTimer == 'yes' && document.getElementById(API.activeMenu)) Effect.Fade(API.activeMenu);
			}, 2000);
		};

		return false;

	};

	this.dblclicked = function(evt) {
		var child = Event.element(evt);
		var id = API.findParentHasClass(child, 'editable');
		if (id != null) {
			var tmp = $('APLDebug').innerHTML;
			$('APLDebug').innerHTML = 'ID : ' + id +'<br/>class : ' + $(id).className;
			setTimeout(function() {
				$('APLDebug').innerHTML	= tmp;
			}, 2000);
			Event.stop(evt);
			API.editElement($(id));
		};
	};

	this.move = function(evt) {
		if (!Event) return;
		var child = Event.element(evt);
		API.mx = Event.pointerX(evt);
		API.my = Event.pointerY(evt);
		var id = API.findParentHasClass(child, 'editable');
		if (id != null) {
			API.moveHack(id);
			setTimeout(function() {
				if (document.getElementById(id)) {
					$(id).parentNode.style.border = '';
					$(id).parentNode.style.margin = '0px';
				}
			}, 1000);
			Event.stop(evt);
		};
	};

	this.moveHack = function(obj) {
		$(obj).parentNode.style.border = '2px dotted black';
		$(obj).parentNode.style.margin = '-2px';
	};

	this.findParentHasClass = function(obj, cls) {

		if (!obj) return;

		if ($(obj).className && Element.hasClassName(obj, cls)) {
			return $(obj).getAttribute('id');
		} else {
			return API.findParentHasClass(obj.parentNode, cls);
		}

	};

	this.logged_in = function(url) {
		setTimeout(function(){
			if (!url) url = '';
			raw_url = APL_ROOT + APL_LNG + '/';
			url = raw_url + url;
			new Ajax.Request(url, {
			    method:'post',
			    onSuccess: function(transport){
			      var response = transport.responseText || "no response text";
					  window.location.replace(raw_url);
			    },
			    onFailure: function(){ alert('Something went wrong...') }
			  });
  		}, 1000);
	};

};

cAPI.prototype.goBack = function() {

	if (!API.rememberList) {} else {
		if (API.rememberList.length > 0) {
			url = API.rememberList[API.rememberList.length - 2];
			API.rememberList.pop();
			API.rememberList.pop();
			setCookie('rememberList', API.rememberList.serializeC(), null, '/');
			if (typeof url != 'undefined') window.location.replace(url);
		}
	}

};

cAPI.prototype.sendForm = function(obj, target) {
	pars = Form.serialize(obj);
	url = obj.getAttribute('action');
	Element.update(target, '');
	var myAjax = new Ajax.Updater(
					{success: target}, 
					url, 
					{
						method: 'post',
						evalScripts : true,
						parameters: pars,
						asynchronous : true
					});
	return false;
};

cAPI.prototype.loadURL = function(url, target) {

	if (!document.getElementById('APLContentBox')) return;
	if (!target) target = 'APLContentBox';

	if (!url) return;

	raw_url = url;

	API.rememberList[API.rememberList.length] = raw_url;
	setCookie('rememberList', API.rememberList.serializeC(), null, '/');

	url = APL_ROOT + 'get/?url=' + url;// + '&TB_iframe=true&modal=true&height=400&width=600';
	new Ajax.Updater(
					{success: target},
					url,
					{
						method: 'post',
						evalScripts : true,
						encoding : 'utf-8',
						asynchronous : true,
						onSuccess: function() {setTimeout(function() {if (typeof jQueryThickBox != 'undefined') tb_init("#APLContentBox a.thickbox");}, 10);}
					});
};

cAPI.prototype.addModule = function(id) {

	API.hideBadStuff();

	API.browser = new API.getBrowserInfo();
	API.page = new API.getPageInfo();
	var c = Builder.node('div', {
		id: 'addModuleBlockPage',
		style: 'position: absolute; background: black; top: 0px; left: 0px; width: ' + API.page.x2 + 'px; height: ' + API.page.y2 +'px; z-index: ' + (API.maxZ++) + '; margin: 0px; padding: 0px; overflow: hidden;'
	});
	document.body.appendChild(c);
	API.setOpacity(c, 30);

	w = 400; h = 80;
	var c = Builder.node('div', {
		id: 'addModuleBlockPageSelect',
		style: 'position: absolute; text-align: center; display:  none; background: white; top: ' + (API.page.y50 - (h / 2)) + 'px; left: ' + (API.page.x50 - (w / 2)) + 'px; width: ' + w + 'px; height: ' + h + 'px; z-index: ' + (API.maxZ++) + '; margin: 0px; padding: 0px; overflow: hidden;'
	});
	document.body.appendChild(c);
	c.innerHTML = '<p>vyberte modul pro vložení: <select id="addModuleSelect" name="data"> </select></p>';
	c.innerHTML += '<p><input onclick="API.saveModule(\'' + id + '\');" type="button" value=" OK "/>&nbsp;&nbsp;&nbsp;<input type="button" value=" storno " onclick="Effect.Fade(\'addModuleBlockPage\');Effect.Fade(\'addModuleBlockPageSelect\');API.showBadStuff();"/></p>';
	Effect.Appear(c);

	url = APL_ROOT + 'json/getModules/';
	new Ajax.Request(url, {
		method:'post',
		onSuccess: function(transport){
			var json = transport.responseText.evalJSON();
			if (typeof json !=' undefined' && json.length > 0) {
				el = $('addModuleSelect');
				for (i = 0; i < json.length; i++) {

					var row = new Option(json[i], json[i]);
					el.options[el.options.length] = row;

				};
			};
		}
	});

};

cAPI.prototype.saveModule = function(id) {

	pars = Form.Element.serialize('addModuleSelect');

	url = APL_ROOT + 'admin/saveModule/?id=' + id;

	var myAjax = new Ajax.Updater(
					{success: API.AJAXTarget},
					url,
					{
						method: 'post',
						evalScripts : true,
						parameters: pars,
						asynchronous : true
					});
};

cAPI.prototype.deleteElement = function(id) {

	if (id.indexOf("Element_") == -1) return;

	if (!confirm('Opravdu vymazat prvek?')) return;

	url = APL_ROOT + 'admin/deleteElement/?id=' + id;

	var myAjax = new Ajax.Updater(
					{success: API.AJAXTarget},
					url,
					{
						method: 'post',
						evalScripts : true,
						asynchronous : true
					});
	return false;


};

cAPI.prototype.addElement = function(block) {

	if (block.indexOf("APL") == -1) return;

	blockIn = block.substr(0, block.indexOf("Box"));

	id = 'Element_new_' + blockIn;

	html = '<div id="' + id + '" class="editable">&nbsp;</div>';

	new Insertion.Bottom(blockIn, html);

	API.editElement($(id));


};

cAPI.prototype.editElement = function(obj) {

	if (obj.id.indexOf("Element_") == -1) return;
	if (API.editing.indexOf("Element_") != -1 && API.editing != $(obj).id) {
		if (document.getElementById(API.editing)) {
			if (typeof preSaveBoxOver == 'function') {
				preSaveBoxOver();
				setTimeout('preSaveBoxTimer()', 5000);
			};
			for (i = 0; i < 8; i++) {
				setTimeout(function(){
					$(API.editing).style.backgroundColor = 'red';
					API.setOpacity($(API.editing), 50);
				}, i*300);
				setTimeout(function(){
					$(API.editing).style.backgroundColor = '';
					API.setOpacity($(API.editing), 100);
				}, (i*300) + 200);
				i++;
			}
		}
		return;
	};

	if ($(obj).getAttribute('type_id') > 1) {
		return;
	};

	if (document.getElementById('preSaveBox')) Element.remove('preSaveBox');

	obj = $(obj);

	win = Element.getDimensions(document.body);
	o = new API.createElement('div', API.active = 'AdminEditArea', 'absolute', 40, 20, win.width-40, 400, 10);
	o.innerHTML = '<form onsubmit="API.previewElement(\'' + obj.id + '\');return false;"><textarea id="AdminEditElementTextArea" style="width: ' + (win.width - 80) + 'px; height: ' + (win.height - 40) + 'px;">' + obj.innerHTML + '</textarea></form>';

	document.body.appendChild(o);

	tinyMCE.addMCEControl($('AdminEditElementTextArea'), 'AdminEditElementTextArea');

	setTimeout(function() {
		tinyMCE.execCommand('mceCleanup', tinyMCE.getEditorId('AdminEditElementTextArea'));
	}, 250);


	API.hideBadStuff();

};

cAPI.prototype.previewElement = function(id, callBack) {

	$(id).innerHTML = tinyMCE.getContent();

	tinyMCE.removeMCEControl(tinyMCE.getEditorId('AdminEditElementTextArea'));

	Element.remove(API.active);

	API.editing = id;

	if (!callBack) {
		API.preSaveElement(id);
	} else {
		API.preSaveElement(id, callBack);
	}

	API.showBadStuff();
};

cAPI.prototype.preSaveElement = function (id, callBack) {

		win = Element.getDimensions(document.body);
		w = 400;
		h = 50;
		c = new API.createElement('div', 'preSaveBox', 'absolute', (win.width / 2) - (w / 2), 0, w, h, API.maxZ++);
		c.style.backgroundColor = 'Silver';
		c.style.position = 'fixed';
		c.style.border = '1px solid black';
		c.style.margin = c.style.padding = '0px';
		c.style.overflow = 'hidden';
		image = APL_ROOT + '/themes/images/flip_down.gif';

		document.body.appendChild(c);

		c.innerHTML = '<p class="aCenter" style="margin: 5px;">Uložit provedené změny?</p>';

		c.onmouseover = preSaveBoxOver = function () {
			if (!document.getElementById('preSaveBox')) return;
			c = $('preSaveBox');
			c.style.height = '50px';
			c.style.background = 'Silver';
		};

		c.onmouseout = preSaveBoxTimer = function () {
			if (!document.getElementById('preSaveBox')) return;
			c = $('preSaveBox');
			c.style.height = '7px';
			c.style.background = 'Silver url(' + image + ') no-repeat bottom center';
		};

		onclick = "API.saveElement('" + id + "');";
		onclick1 = "API.saveElement('" + id + "', true);";

		butt = new API.createElement('p', 'previewButtons', 'absolute', 0, 0, w, h, API.maxZ++);
		butt.innerHTML = '<input type="button" value=" OK " style="cursor: pointer" onclick="' + onclick + '">&nbsp;&nbsp;&nbsp;<input type="button" value=" OK a obnovit" style="cursor: pointer" onclick="' + onclick1 + '">&nbsp;&nbsp;&nbsp;<input type="button" value=" Storno " style="cursor: pointer" onclick="window.location.reload();">';

		butt.style.textAlign = 'center';
		butt.style.top = (h - 32) + 'px';

		c.appendChild(butt);

		setTimeout('preSaveBoxTimer()', 5000);

};

cAPI.prototype.saveElement = function(id, reload) {


		tmp = $(id).innerHTML.escapeHTML();

		new Insertion.Top(document.body, '<form method="post" id="SaveDataForm" class="none"><textarea name="data">' + tmp + '</textarea>');

		while (!document.getElementById('SaveDataForm')) {
			void(0);
		};

		reloadURL = function() {
			window.location.reload();
		};

		pars = Form.serialize('SaveDataForm');

		url = APL_ROOT + 'admin/saveElement/?id=' + id;

		if(!reload) {
			var myAjax = new Ajax.Updater(
						{success: API.AJAXTarget},
						url,
						{
							method: 'post',
							evalScripts : true,
							parameters: pars,
							asynchronous : true
						});
		} else {
			var myAjax = new Ajax.Updater(
						{success: API.AJAXTarget},
						url,
						{
							method: 'post',
							evalScripts : true,
							parameters: pars,
							asynchronous : true,
							onSuccess: reloadURL
						});
		};

		Element.remove('SaveDataForm');
		return false;

};

cAPI.prototype.successSave = function() {

	API.editing = '';

	if (document.getElementById('preSaveBox')) Element.remove('preSaveBox');
	if (document.getElementById('AlertBoxSaveElement')) Element.remove('AlertBoxSaveElement');

	setTimeout(function() {
		if (document.getElementById('AlertBoxSaveElementText')) Effect.Fade('AlertBoxSaveElementText');
		if (document.getElementById('SEO_iframeText')) Effect.Fade('SEO_iframeText');
	}, 2000);

};

cAPI.prototype.throbber = function(id) {

		if (!id) return;

		if (document.getElementById(id)) Element.update(id, '<p class="aCenter" style="margin-top: 25px;"><img alt="" src="' + APL_ROOT + 'themes/images/throbber.gif"/></p>');

};

cAPI.prototype.createElement = function(element, id, position, x, y, w, h, zindex) {

	if (document.getElementById(id)) {
		Element.remove(id);
	}

	el = document.createElement(element);
	el.id = id;
	el.setAttribute('id', id);
	el.style.position = position;
	if (x < 0) {
		el.style.right = (0 - x) + 'px';
	} else {
		el.style.left = x + 'px';
	}
	if (y < 0) {
		el.style.bottom = (0 - y) + 'px';
	} else {
		el.style.top = y + 'px';
	}
	if (w == 0) {
		el.style.width = 'auto';
	} else {
		el.style.width = w + 'px';
	}
	if (h == 0) {
		el.style.height = 'auto';
	} else {
		el.style.height = h + 'px';
	}
	el.style.visibility = 'visible';
	el.style.display = 'block';
	el.style.zIndex = zindex;

	return el;

}

cAPI.prototype.setOpacity = function(obj, opac) {

		if (!obj) return;

		if (obj.getAttribute('id')) if (document.getElementById(obj.getAttribute('id'))) {

			obj.style.opacity = opac / 100;
			obj.style.filter = 'alpha(opacity='+opac+')';

		}

};

cAPI.prototype.showBadStuff = function() {

	ar = $$('object');
	for (i = 0; i < ar.length; i++) {
		ar[i].style.visibility = 'visible';
	};

};

cAPI.prototype.hideBadStuff = function() {

	ar = $$('object');
	for (i = 0; i < ar.length; i++) {
		ar[i].style.visibility = 'hidden';
	};

};

cAPI.prototype.sortingStart = function() {

	API.sorting = new Object();
	API.sorting.blocks = [ ];
	API.sorting.els = [ ];
	$$('.PageBlock').each(function(node) {
		id = node.childNodes[1].id;
		obj = node;
		x = obj.offsetLeft; y = obj.offsetTop;
		var padding = 'margin: 0px; padding: 0px;';
		nid = 'BlockID_' + id;
		var c = Builder.node('ul', {
			id: nid,
			style: padding + ' border: 0px solid yellow; position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + obj.getWidth() + 'px; height: ' + obj.getHeight() + 'px;'
		});//, [id]
		document.body.appendChild(c);
		API.sorting.blocks.push({
			block_id: id,
			ul_id: nid
		});
		ar = [ ];
		$$('#' + id + ' .editable').each(function(el) {
			var _nid = 'ElementID_' + el.id;
			obj = el.parentNode;
			x = obj.offsetLeft; y = obj.offsetTop;
			var _c = Builder.node('li', {
				id: _nid,
				onmouseover: 'Element.addClassName(this, \'dragHover\');',
				onmouseout: 'Element.removeClassName(this, \'dragHover\');',
				style: 'cursor: move; position: relative; display: block; margin: 0px; padding: 0px; border: 1px dotted #222; left: '+ $(id).getStyle('padding-left') + '; width: ' + obj.getWidth() + 'px; height: ' + obj.getHeight() + 'px;'
			});//, [el.id]
			$(nid).appendChild(_c);
			ar.push({
				id: el.id,
				li_id: _nid
			});
			$(_nid).update(el.innerHTML);

		});
		API.sorting.els.push(ar);
	});

	for (i = 0; i < API.sorting.blocks.length; i++) {

		$(API.sorting.blocks[i].block_id).remove();
		Sortable.create(API.sorting.blocks[i].ul_id, {scroll:window, dropOnEmpty:true, overlap:'vertical', hoverclass:'dragHover', onUpdate:function(obj){

			$('preSaveBox').show();
			preSaveBoxOver();
			setTimeout('preSaveBoxTimer()', 5000);

			onclick = "API.editing = '';API.saveSorting('" + obj.id + "');";
			onclick1 = "API.editing = '';API.saveSorting('" + obj.id + "', true);";

			$('previewButtons').innerHTML = '<input type="button" value=" OK " style="cursor: pointer" onclick="' + onclick + '">&nbsp;&nbsp;&nbsp;<input type="button" value=" OK a obnovit" style="cursor: pointer" onclick="' + onclick1 + '">&nbsp;&nbsp;&nbsp;<input type="button" value=" Storno " style="cursor: pointer" onclick="window.location.reload();">';

		}, containment:[API.sorting.blocks[i].ul_id], constraint:'vertical', ghosting:false});

	};

	win = Element.getDimensions(document.body);
	w = 400;
	h = 50;
	c = new API.createElement('div', 'preSaveBox', 'absolute', (win.width / 2) - (w / 2), 0, w, h, API.maxZ++);
	c.style.backgroundColor = 'Silver';
	c.style.position = 'fixed';
	c.style.border = '1px solid black';
	c.style.margin = c.style.padding = '0px';
	c.style.overflow = 'hidden';
	c.style.display = 'none';
	image = APL_ROOT + '/themes/images/flip_down.gif';

	document.body.appendChild(c);

	c.innerHTML = '<p class="aCenter" style="margin: 5px;">Uložit provedené změny?</p>';

	c.onmouseover = preSaveBoxOver = function () {
		if (!document.getElementById('preSaveBox')) return;
		c = $('preSaveBox');
		c.style.height = '50px';
		c.style.background = 'Silver';
	};

	c.onmouseout = preSaveBoxTimer = function () {
		if (!document.getElementById('preSaveBox')) return;
		c = $('preSaveBox');
		c.style.height = '7px';
		c.style.background = 'Silver url(' + image + ') no-repeat bottom center';
	};

	onclick = "API.editing = '';API.saveSorting(obj);";

	butt = new API.createElement('p', 'previewButtons', 'absolute', 0, 0, w, h, API.maxZ++);
	butt.innerHTML = '<input type="button" value=" OK " style="cursor: pointer" onclick="' + onclick + '">&nbsp;&nbsp;&nbsp;<input type="button" value=" Storno " style="cursor: pointer" onclick="window.location.reload();">';

	butt.style.textAlign = 'center';
	butt.style.top = (h - 32) + 'px';

	c.appendChild(butt);


};

cAPI.prototype.saveSorting = function(id, reload) {

	$('preSaveBox').show();
	API.editing = 'seq';

	reloadURL = function() {
		window.location.reload();
	};

	url = APL_ROOT + 'admin/saveSequence/';

	pars = Sortable.serialize(id);

		if(!reload) {
			new Ajax.Updater(
				{success: API.AJAXTarget},
				url, {
					method:'post',
					evalScripts : true,
					parameters: pars,
					asynchronous : true
				});
		} else {
			new Ajax.Updater(
				{success: API.AJAXTarget},
				url, {
					method:'post',
					evalScripts : true,
					parameters: pars,
					asynchronous : true,
					onSuccess: reloadURL
				});
		};
};

cAPI.prototype.ParseInt = function(s) {
	var ret = parseInt(s);
	return (isNaN(ret) ? 0 : ret);
}

cAPI.prototype.getBrowserInfo = function() {
		
		this.ver = navigator.appVersion;
		this.agent = navigator.userAgent;
		this.dom = document.getElementById ? 1 : 0;
		this.opera5 = this.agent.indexOf("Opera 5") > -1;
		this.opera = this.agent.indexOf("Opera") > -1;
		this.ie5 = (this.ver.indexOf("MSIE 5") > -1 && this.dom && !this.opera5) ? 1 : 0;
		this.ie6 = (this.ver.indexOf("MSIE 6") > -1 && this.dom && !this.opera5) ? 1 : 0;
		this.ie7 = (this.ver.indexOf("MSIE 7") > -1 && this.dom && !this.opera5) ? 1 : 0;
		this.ie4 = (document.all && !this.dom && !this.opera5) ? 1 : 0;
		this.ie = this.ie5 || this.ie6 || this.ie7;
		this.mac = this.agent.indexOf("Mac") > -1;
		this.ns6 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0;
		this.ns4 = (document.layers && !this.dom) ? 1 : 0;
		this.bw = (this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);
		return this;
				
};
	
cAPI.prototype.getPageInfo = function() {

		if (API.ParseInt(API.maxZ) < 100) API.maxZ = 100;
		this.x1 = 0;this.y1 = 0;
		this.x2 = (API.browser.ie7)?document.documentElement.clientWidth:(API.browser.ns6) ? innerWidth : document.body.clientWidth;
		this.y2 = (API.browser.ie7)?document.documentElement.clientHeight:(API.browser.ns6) ? innerHeight : document.body.clientHeight;
		this.x50 = Math.round(this.x2 / 2);
		this.y50 = Math.round(this.y2 / 2);		
		
};

cAPI.prototype.stylize = function(o) {
		o.style.backgroundColor = 'white';
		o.style.border = '1px solid black';
		o.style.padding = '0px';
		o.style.margin = '0px';
		o.style.fontSize = '7pt';
		o.style.fontFamily = 'Verdana';
		o.style.overflow = 'hidden';
		return o;
};

cAPI.prototype.setIdOpacity = function(id, opac) {
		if (!API.browser.ie) {
			$(id).style.opacity = opac / 100;	
		} else {
			$(id).style.filter = 'alpha(opacity='+opac+')';
		}
};

var API = new cAPI();

Event.observe(window, 'load', API.init, false);

Array.prototype.serializeC = function (){
   var temp = '';
   for(var vars in this){
      if(!(this[vars] instanceof Function)){
         temp += vars + ':' + this[vars] + ',';
      }
   }
   return temp;
   return temp.substr(0, temp.length - 1);
};
 
