var safegroup = {

	checkbox: {
		clicked: function(obj){
			var inp = obj.getElementsByTagName('input');
			if(inp.length) inp = inp[0];
			if(inp.value=="1"){
				inp.value="0";
				obj.className="checkbox0";
			}else{
				inp.value="1";
				obj.className="checkbox1";
			}
		}
	},
		
	employee: {
		lastOver: null,
		shownElement: null,
		show: function(element) {
			if ((window.secoya && secoya.editor && secoya.editor.currentElement) ||
				(window.editor && editor.currentEdit))
				return;
			if (this.lastOver && this.shownElement) {
				this.lastOver.appendChild(this.shownElement);
			}
			this.lastOver = element;
			this.shownElement = this.getContentChild(element);
			if (this.shownElement) {
				var info = document.getElementById('more_info');
				info.appendChild(this.shownElement);
			}
		},
		

		getContentChild: function(element) {
			var elms = element.getElementsByTagName('div');
			var found = null;
			for (var i = 0; i < elms.length && !found; i++) {
				if (elms[i].className == 'contact') {
					found = elms[i];
				}
			}
			return found;
		}
	},
	
	toggleHelp: function(UID){
			var elm =  document.getElementById(UID);
			if(elm.style.display=='none') elm.style.display='block';
			else elm.style.display='none';
	},

	autoScroll: (function(){
		var v, count = 0, fx, index = -1, run;
		function reset() {
			v = document.getElementById('video');
			count = !!core;
			index = 0;
			timeoutId = 0;
			if (v) {
				var divs = v.getElementsByTagName('div');
				for (var i = 0; i < divs.length; i++) {
					if (divs[i].className == 'item')
						count++;
				}
				var width = v.parentNode.offsetWidth;
				v.style.width = width * count + 'px';
				run = function(back) {
					if ((back && index == 0) || (!back && index == count-1)) {
						index = 0;
						fx.from = width * (count-1);
						fx.to = 0;
						if (back) {
							fx.to = fx.from;
							fx.from = 0;
							index = count;
						}
					} else {
						if (back) {
							fx.from = width*index;
							index--;
							fx.to = width*index;
						} else {
							fx.from = width*index;
							index++;
							fx.to = width*index;
						}
					}
					fx.start();
				};
				fx = new secoya.fx({
					from: 0,
					to: width,
					duration: 1,
					type: secoya.fx.power,
					callback: function(x) {
						v.style.marginLeft = -x + 'px';
					},
					finish: function() {
						timeoutId = setTimeout(function(){run();}, 5000);
					}
				});
				if (!core && count > 1) {
					timeoutId = setTimeout(function(){run();}, 5000);
				}
			}
		};
		lightCore.registerInit({initialize:function(){
			reset();
		}});
		function kill (){
			clearTimeout(timeoutId);
			if (count > 1)
			fx.resetToEnd();
			fx.finish = function(){};
		};
		return {
			reset: function() {
				reset();
			},
			kill: function() {
			},
			left: function() {
				if (run) {
					kill();
					if (count > 1)
						run(true);
				}
			},
			right: function() {
				if (run) {
					kill();
					if (count > 1)
						run();
				}
			}
		};
	})(),

	scroller: {
		elementId: null,
		element: null,
		position: 0,
		positions: {},
		intervalId: 0,
		scrollWait: 50,
		scrollIncrement: 10,

		prepareScroll: function(id, element) {
			this.element = null;
			this.elementId = id;
			if (typeof this.positions[id] == 'undefined')
				this.positions[id] = 0;

			this.position = this.positions[id];

			if (!element.onmouseout) {
				var me = this;
				element.onmouseout = function() {
					me.endScroll();
				}
				element.onmouseup = function() {
					me.endScroll();
				}
			}
		},

		scroll: function() {
			// hide the functions
		},

		scrollUp: function(id, element) {
			this.prepareScroll(id, element);
			this.startScrolling(this.scrollIncrement);
		},

		scrollDown: function(id, element) {
			this.prepareScroll(id, element);
			this.startScrolling(-this.scrollIncrement);
		},

		startScrolling: function(increment) {
			var me = this;
			this.intervalId = setInterval(function(){
				me.setPosition(me.position + increment);
			}, this.scrollWait);
		},

		endScroll: function() {
			clearInterval(this.intervalId);
			this.positions[this.elementId] = this.position;
		},

		getElement: function() {
			if (!this.element)
				this.element = document.getElementById(this.elementId);
			return this.element;
		},

		reset: function() {
			if (this.elementId)
				this.endScroll();
			this.elementId = null;
			this.positions = {};
			this.element = null;
		},

		setPosition: function(value) {
			var elm = this.getElement();
			if (value > 0) {
				value = 0;
			} else {
				var fullHeight = elm.scrollHeight + 50;
				var visibleHeight = elm.parentNode.clientHeight;
				if (fullHeight+value < visibleHeight) {
					value = Math.min(-(fullHeight-visibleHeight), 0);
				}
			}
			elm.style.marginTop = value + 'px';
			this.position = value;
		}
	}
};