// ----------------------------------------------------------------------------------------------------
// Combo - das clevere CMS!
// Copyright (c) 1999-2006 by Marcus Ollas, Germany
// All Rights Reserved
// ----------------------------------------------------------------------------------------------------
var COMBO = {
    // --------------------------------------------------
    tickerContainer: null,
    tickerTimer: null,
    tickerAbstand: 15,
    insideContainer: null,
    marginTop: 0,
    leseZeit: 4000,
    moveTime: 20,
    management: false,
    // --------------------------------------------------
    setTickerContainer: function(reference) {
        COMBO.tickerContainer = reference;
    },
    // --------------------------------------------------
    setTickerAbstand: function(abstand) {
        COMBO.tickerAbstand = abstand;
    },
    // --------------------------------------------------
    moveTicker: function() {
        if (!COMBO.tickerContainer)
            return ;

		if (COMBO.insideContainer) {
            window.setTimeout("COMBO.moveTicker()",COMBO.moveTime);
			return ;
		}
        var entries = COMBO.tickerContainer.getElementsByTagName("DIV");
        if (COMBO.marginTop == -(entries[0].offsetHeight + COMBO.tickerAbstand)) {
            var first = entries[0];
            COMBO.tickerContainer.replaceChild(entries[1],first);
            first.style.marginTop = 0;
            COMBO.tickerContainer.appendChild(first);
            COMBO.marginTop = 0;
            COMBO.startTicker();
        }
        else {
            COMBO.marginTop-- ;
            entries[0].style.marginTop = COMBO.marginTop;
            window.setTimeout("COMBO.moveTicker()",COMBO.moveTime);
        }
    },
    // --------------------------------------------------
	enterTicker: function() {
       	COMBO.insideContainer = true;
    },
    // --------------------------------------------------
	exitTicker: function() {
       	COMBO.insideContainer = false;
    },
    // --------------------------------------------------
    startTicker: function() {
        if (COMBO.tickerContainer)
            COMBO.tickerTimer = window.setTimeout("COMBO.moveTicker()",COMBO.leseZeit);
    },
    // --------------------------------------------------
	isSafari: function() {
		return (navigator.userAgent.indexOf("Safari") != -1);
	},
    // --------------------------------------------------
    filename: function(value) {
    	if (value == null || value == "")
    		return "";
    	
    	var s = value.lastIndexOf("\\");
    	if (s == -1)
	    	s = value.lastIndexOf("/");
    	
    	return value.substr(s + 1);
    },
    // --------------------------------------------------
    cleanFilename: function(value) {
		if (value)
	    	value = value.replace(/ /g,"_");
    	return value;
    },
    // --------------------------------------------------
    currentRow: null,
    // --------------------------------------------------
	markRow: function(ref,objectId) {
		if (COMBO.currentRow) {
			COMBO.currentRow.className = 'Row' +
				((COMBO.currentRow.rowIndex % 2) ? 'Even' : 'Odd');
		}
		if (ref) {
			ref.parentNode.className = 'Selected';
			COMBO.currentRow = ref.parentNode;

			if (el = document.getElementById('naviMoveUp'))
				el.disabled = false;
			if (el = document.getElementById('naviMoveDown'))
				el.disabled = false;
			if (el = document.getElementById('naviMoveUpId'))
				el.value = objectId;
			if (el = document.getElementById('naviMoveDownId'))
				el.value = objectId;
			if (el = document.getElementById('parentElement'))
				el.value = objectId;
		}
	},
    // --------------------------------------------------
    // --------------------------------------------------
    activateContextMenu : function() {
    	document.oncontextmenu = function(ereignis) {
			if (!ereignis) {
				var ereignis = window.event;
				var x = ereignis.x;
				var y = ereignis.y;
			}
			else {
				var x = ereignis.pageX;
				var y = ereignis.pageY;
			}
			if (!ereignis.ctrlKey) {
				with(ComboPopup) {
					style.top = y;
					style.left = x;
	    			style.visibility = 'visible';
		    	}
		    	document.onkeydown = function(ereignis) {
	    			if (!ereignis) var ereignis = window.event;
	    			if (ereignis.keyCode == 27) {
	    				document.onkeydown = function(ereignis) {};
	    				document.onclick = function(ereignis) {};
		    			with(ComboPopup) {
			    			style.visibility = 'hidden';
							style.top = style.left = 0;
		    			}
		    		}
		    	};
		    	document.onclick = function(ereignis) {
    				document.onclick = function(ereignis) {};
   					document.onkeydown = function(ereignis) {};
	   				with(ComboPopup) {
    					style.visibility = 'hidden';
						style.top = style.left = 0;
					}
	    		};
   				return false;
   			}
   			return true;
    	};
    },
    // --------------------------------------------------
    // --------------------------------------------------
	pageLinkOver : function(ref) {
		return COMBO.handleMouseAction(ref,true);
	},
	pageLinkOut : function(ref) {
		return COMBO.handleMouseAction(ref,false);
	},
	handleMouseAction : function(ref,over) {
		var id = ref.id.substr(4);

		// check for and highlight map dots...
		var dot = document.getElementById("Dot" + id);
		if (dot) {
			dot.childNodes[0].src = over ? 'images/dot1.gif' : 'images/t1.gif';
			ref.style.color = over ? '#DC0067' : '#003C81';
		}
	},
    // --------------------------------------------------
    // --------------------------------------------------
	setManagement : function() {
		COMBO.management = true;
	},
    // --------------------------------------------------
    // --------------------------------------------------
	leavePage : function() {
		var request = null;

		if (COMBO.management)
			return ;

		// Microsoft Internet Explorer
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				// Mozilla/Firefox/Safari etc.
				try {
					request = new XMLHttpRequest();
				}
				catch(e) {}
			}
		}
		if (request) {
			var url = document.location.href;
			url += (url.indexOf('?') == -1 ? '?' : '&') + 'ajaxAction=leavePage';
			// request synchron (!) senden
			request.open('GET',url,false);
			request.send(null);
		}
	},
    // --------------------------------------------------
    // Management Functions
    // --------------------------------------------------
	management : {
		page : {
			nameChanged : function(elRef,neu) {
				// 2006-09-17 marcus@ollas.de
				// Nach Seitennamen?nderung ggf. Titel anpasssen
				if (elRef && elRef.value && elRef.value.length > 0) {
					var elDeutsch = document.getElementById("title_0");
					if (elDeutsch) {
						if (elDeutsch.value.length == 0 || confirm("Titel '" + elDeutsch.value + "' mit Seitennamen ersetzen?"))
							elDeutsch.value = elRef.value;
					}
				}
			}
		},
		navigation : {
			linkedPageChanged : function(selRef,neu) {
				// 2006-09-17 marcus@ollas.de
				// Bei neuen Navigationspunkten:
				// wenn der deutsche Titel leer ist, den Seitennamen vorschlagen!
				if (selRef && neu) {
					var elDeutsch = document.getElementById("eldeutsch");
					if (elDeutsch) {
						if (elDeutsch.value.length == 0 || confirm("Seitennamen im Navigationspunkt verwenden?")) {
							var inner = selRef.options[selRef.selectedIndex].innerHTML;
							elDeutsch.value = inner.replace(/&nbsp;/g,"");
						}
					}	
				}
			}
		}
	},
    // --------------------------------------------------
    // gallery: COMBO Image Gallery Functions
    // --------------------------------------------------
    gallery : {
    	id : null,
    	current : 0,
    	images : null,
    	details : null,
    	// ------------------------------
	    init : function(id,images,details) {
    	// ------------------------------
			COMBO.gallery.id = id;
			COMBO.gallery.images = images;
			COMBO.gallery.details = details;
    	},
    	// ------------------------------
    	getImage : function() {
    	// ------------------------------
	    	return document.getElementById("GalleryImage" + COMBO.gallery.id);
    	},
    	// ------------------------------
    	getText : function() {
    	// ------------------------------
	    	return document.getElementById("GalleryText" + COMBO.gallery.id);
    	},
    	// ------------------------------
    	back : function() {
    	// ------------------------------
	    	if (COMBO.gallery.current > 0)
   				COMBO.gallery.show(--COMBO.gallery.current);
    		return false;
	    },
    	// ------------------------------
    	next : function() {
    	// ------------------------------
	    	if (COMBO.gallery.current < COMBO.gallery.images.length - 1)
    			COMBO.gallery.show(++COMBO.gallery.current);
    		return false;
    	},
    	// ------------------------------
    	show : function(index) {
    	// ------------------------------
    		if (index > -1 && index < COMBO.gallery.images.length &&
    		                  index != COMBO.gallery.current) {
    			COMBO.gallery.current = index;
    			if (img = COMBO.gallery.getImage()) {
    				img.src = COMBO.gallery.images[COMBO.gallery.current];
    				img.alt = COMBO.gallery.details[COMBO.gallery.current];
    			}
    			if (txt = COMBO.gallery.getText())
    				txt.innerHTML = COMBO.gallery.details[COMBO.gallery.current];
    		}
    		return false;
    	},
    	// ------------------------------
    	thumbOver : function(imageRef,src) {
    	// ------------------------------
//    		dpos = imageRef.src.lastIndexOf('.');
//    		imageRef.src = imageRef.src.substr(0,dpos) + ".over" + imageRef.src.substr(dpos);
			imageRef.src = src;
    	},
    	// ------------------------------
    	thumbOut : function(imageRef,src) {
    	// ------------------------------
			imageRef.src = src;
    	},
    	// ------------------------------
    	diashow : {
    		imageRef : null,
    		parentRef : null,
    		images : null,
    		currentIndex : 0,
    		opacity : 1.0,
    		pause : 5000,
    		steps : 0.05,
    		delay : 60,
    		random : false,	// not implemented yet :(
    		infinite : true,
	    	// ------------------------------
	    	// ------------------------------
	    	next : function() {
	    		if (!COMBO.gallery.diashow.images)
	    			return null;

				if (++COMBO.gallery.diashow.currentIndex >= COMBO.gallery.diashow.images.length) {
					if (!COMBO.gallery.diashow.infinite)
						return null;
					COMBO.gallery.diashow.currentIndex = 0;
				}
				return COMBO.gallery.diashow.images[COMBO.gallery.diashow.currentIndex];
	    	},
	    	// ------------------------------
	    	// ------------------------------
	    	setOpacity : function(value) {
	    		if (COMBO.gallery.diashow.imageRef) {
					COMBO.gallery.diashow.imageRef.style.filter = 'alpha(opacity=' + (value * 100) + ')';	// IE
					COMBO.gallery.diashow.imageRef.style.opacity = value;									// Gecko
				}
	    	},
	    	// ------------------------------
	    	// ------------------------------
			fadeOut : function() {

				if (COMBO.gallery.diashow.opacity > 0.0) {
					COMBO.gallery.diashow.setOpacity(COMBO.gallery.diashow.opacity -= COMBO.gallery.diashow.steps);
					window.setTimeout("COMBO.gallery.diashow.fadeOut()",COMBO.gallery.diashow.delay);
				}
				else if ((src = COMBO.gallery.diashow.next()) != null) {
					COMBO.gallery.diashow.setOpacity(COMBO.gallery.diashow.opacity = 0.0);
					COMBO.gallery.diashow.imageRef.src = src;
					window.setTimeout("COMBO.gallery.diashow.fadeIn()",COMBO.gallery.diashow.pause);
				}
			},
	    	// ------------------------------
	    	// ------------------------------
			fadeIn : function() {
				if (COMBO.gallery.diashow.opacity < 1.0) {
					COMBO.gallery.diashow.setOpacity(COMBO.gallery.diashow.opacity += COMBO.gallery.diashow.steps);
					window.setTimeout("COMBO.gallery.diashow.fadeIn()",COMBO.gallery.diashow.delay);
				}
				else if ((src = COMBO.gallery.diashow.next()) != null) {
					COMBO.gallery.diashow.setOpacity(COMBO.gallery.diashow.opacity = 1.0);
					COMBO.gallery.diashow.parentRef.style.background = 'url(' + src + ') no-repeat top left';
					window.setTimeout("COMBO.gallery.diashow.fadeOut()",COMBO.gallery.diashow.pause);
				}
			},
	    	// ------------------------------
	    	// ------------------------------
			init : function(images,pause,delay,steps,offset,random,infinite) {
				COMBO.gallery.diashow.images = images;
				COMBO.gallery.diashow.pause = pause;
				COMBO.gallery.diashow.delay = delay;
				COMBO.gallery.diashow.steps = steps;
				COMBO.gallery.diashow.currentIndex = offset;
				COMBO.gallery.diashow.random = random;
				COMBO.gallery.diashow.infinite = infinite;
			},
	    	// ------------------------------
	    	// ------------------------------
			checkReferences : function() {
				if (!COMBO.gallery.diashow.imageRef || !COMBO.gallery.diashow.parentRef) {
					COMBO.gallery.diashow.imageRef = document.getElementById("GalleryImage" + COMBO.gallery.id);
					COMBO.gallery.diashow.parentRef = document.getElementById("DiashowContainer" + COMBO.gallery.id);
					return false;
				}
				return true;
			},
	    	// ------------------------------
	    	// ------------------------------
			start : function() {
				// Referenzen pr?fen und ggf. 1/2 Sekunde warten...
				if (!COMBO.gallery.diashow.checkReferences()) {
					window.setTimeout("COMBO.gallery.diashow.start()",500);
					return ;
				}
				var src = COMBO.gallery.diashow.next();
				if (src) {
					COMBO.gallery.diashow.parentRef.style.background = 'url(' + src + ') no-repeat top left';
					window.setTimeout("COMBO.gallery.diashow.fadeOut()",COMBO.gallery.diashow.pause);
				}
			},
	    	// ------------------------------
	    	// ------------------------------
	    	wysiwygNPL : function(ref,id) {
	    		if (el = document.getElementById('random' + id))
	    			el.disabled = (!ref.checked);
	    		if (el = document.getElementById('labelRandom' + id))
	    			el.disabled = (!ref.checked);
	    		if (el = document.getElementById('infinite' + id))
	    			el.disabled = (!ref.checked);
	    		if (el = document.getElementById('labelInfinite' + id))
	    			el.disabled = (!ref.checked);
	    		if (el = document.getElementById('pause' + id))
	    			el.disabled = (!ref.checked);
	    		if (el = document.getElementById('labelPause' + id + '-1'))
	    			el.disabled = (!ref.checked);
	    		if (el = document.getElementById('step' + id))
	    			el.disabled = (!ref.checked);
	    		if (el = document.getElementById('delay' + id))
	    			el.disabled = (!ref.checked);
	    		if (el = document.getElementById('labelPause' + id + '-2'))
	    			el.disabled = (!ref.checked);
	    		if (el = document.getElementById('labelFading' + id + '-1'))
	    			el.disabled = (!ref.checked);
	    		if (el = document.getElementById('labelFading' + id + '-2'))
	    			el.disabled = (!ref.checked);
	    		if (el = document.getElementById('labelFading' + id + '-3'))
	    			el.disabled = (!ref.checked);
	    	}
    	}
    }
    // --------------------------------------------------
    // --------------------------------------------------
};
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
function markRow(ref)
{
}
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
