LSD.events.add(window, 'load', function() {
/*	var imgMap = LSD.dom.get('tag', 'img');
	if (imgMap) {
		for (var i = 0 ; i < imgMap.length ; i++) {
			var mapName = LSD.element.attribute(imgMap[i], 'usemap').substr(1);
			if (mapName != '') {
				var mapData = LSD.dom.get('tag', 'area', LSD.dom.get('name', mapName, 'map')[0] || false);
				if (mapData) {
					for (var j = 0 ; j < mapData.length ; j++) {
						if (mapData[j].href.substr(-1) != '#') {
							var area = LSD.dom.create('a');
							area.href = mapData[j].href;
						} else {
							var area = LSD.dom.create('div');
						}
						area.className = 'imageMap';
						(function() {
							var current = j;
							var currentImg = i;
							// Build pop-up
							area.popup = LSD.dom.create('div');
							area.popup.style.cssText = 'width: 200px; padding: 5px; position: absolute; background: #E4E4E4;';
							area.popup.innerHTML = mapData[current].title;
							LSD.animate.hide(area.popup);
							document.body.appendChild(area.popup);
							
							// Build Overlay
							var coords = mapData[j].coords.split(',');
							area.style.cssText = 'position: absolute; width: '+(coords[2]-coords[0])+'px; height: '+(coords[3]-coords[1])+'px; top: '+coords[1]+'px; left: '+coords[0]+'px; text-align: center; padding: 0; margin: 0; display: block;';
							LSD.animate.opacity(area, 30);
							LSD.events.add(area, 'mouseover', function(e) {
								var offset = (LSD.mouse.x(e)-LSD.page.scroll_x() > LSD.page.window_width()/2)?190:20;
								LSD.element.set_x(this.popup, LSD.mouse.x(e)-offset);
								LSD.element.set_y(this.popup, LSD.mouse.y(e)+15);
								LSD.animate.show(this.popup);
								this.style.background = '#8348B5';
//								this.style.border = '1px solid #333';
							});
							LSD.events.add(area, 'mouseout', function() {
								LSD.animate.hide(this.popup);
								this.style.background = 'none';
								this.style.border = 'none';
							});
							LSD.events.add(area, 'mousemove', function(e) {
								var offset = (LSD.mouse.x(e)-LSD.page.scroll_x() > LSD.page.window_width()/2)?190:20;
								LSD.element.set_x(this.popup, LSD.mouse.x(e)-offset);
								LSD.element.set_y(this.popup, LSD.mouse.y(e)+15);
							});
						})();
						LSD.dom.insert_last(area, imgMap[i].parentNode);
					}
				}
			}
		}
	}
*/

	var form = LSD.dom.get('class', 'anatomy', 'form');
	if (form[0]) {
		var my_project = LSD.dom.get('class', 'back', 'a')[0];

		form[0].start = function() {};
		form[0].success = function(results) {

			if (results.status != '1') {
				alert('Project Idea could not be updated.');
			}
			if (results.my_project == 0) {
				LSD.animate.hide(my_project);
			} else {
				if (LSD.style.get(my_project, 'display') == 'none') {
					LSD.animate.grow_y(my_project);
				}
			}
		};
		form[0].failure = function() { alert('Project Idea could not be updated.'); };
		form[0].finished = function() {};

		var labels = LSD.dom.get('tag', 'label', form[0]);
		for (var i = 0 ; i < labels.length ; i++) {
			// Stuff for submitting the form
			var input = LSD.dom.next_sibling(labels[i]);
			if (input && input.nodeName == 'INPUT') {
				(function () {
					var parent = labels[i];
					var elem = input;
					var checkbox = LSD.dom.first_child(parent);
					// Code
					fieldTimer = false;
					if (checkbox.checked == false) {
						LSD.animate.hide(elem);
					}
					elem.height = LSD.element.height(elem);
					LSD.events.add(elem, 'keyup', function () {
						if (fieldTimer) { clearTimeout(fieldTimer); }
						fieldTimer = setTimeout(function() { LSD.ajax.send(form[0]); }, 600);
					});
					LSD.events.add(checkbox, 'change', function () {
						if (checkbox.checked) {
							LSD.animate.grow_y(elem);
							setTimeout(function () { elem.focus(); }, 1200);
						} else {
							elem.value = '';
							LSD.animate.shrink_y(elem);
							LSD.ajax.send(form[0]);
						}
					});
				})();
			} else {
				LSD.events.add(LSD.dom.first_child(labels[i]), 'change', function () { LSD.ajax.send(form[0]); });
			}
			
			// Replace checkbox with image
			(function () {
				var checkbox = LSD.dom.first_child(labels[i]);
//				LSD.animate.hide(checkbox);
checkbox.style.cssText = 'left: -2000px; position: absolute;';
				var image = LSD.dom.create('img');
				if (checkbox.checked == true) {
					image.src = '../images/check_on.gif';
					checkbox.parentNode.title = 'Remove';
				} else {
					image.src = '../images/check_off.gif';
					checkbox.parentNode.title = 'Add';
				}
				LSD.dom.insert_before(image, checkbox);
				LSD.events.add(checkbox, 'click', function() {
					if (this.checked == true) {
						image.src = '../images/check_on.gif';
						this.parentNode.title = 'Remove';
					} else {
						image.src = '../images/check_off.gif';
						this.parentNode.title = 'Add';
					}
				});
			})();
		}
	}

		var scroller = LSD.dom.get('class', 'scroller', 'div');
		if (scroller) {
			for (var i = 0 ; i < scroller.length ; i++) {
				(function () {
					var cur = i;
					
					if (LSD.element.height(scroller[cur]) == scroller[cur].scrollHeight) {
						scroller[cur].style.overflow = 'visible';
						return;
					}
					
					var down = LSD.dom.create('img');
					down.alt = 'down';
					down.title = 'down';
					down.src = '../images/scroll_down_on.gif';
					down.className = 'buttonDown';
					LSD.events.add(down, 'mousedown', function() {
						scroller[cur].scroll_func(50);
						scroller[cur].timer = setInterval(function() { scroller[cur].scroll_func(50); }, 500);
					});
					LSD.events.add(down, 'mouseup', function() {
						clearInterval(scroller[cur].timer);
					});
	
					var up = LSD.dom.create('img');
					up.alt = 'up';
					up.title = 'up';
					up.src = '../images/scroll_up_off.gif';
					up.className = 'buttonUp';
					LSD.events.add(up, 'mousedown', function() {
						scroller[cur].scroll_func(-50);
						scroller[cur].timer = setInterval(function() { scroller[cur].scroll_func(-50); }, 500);
					});
					LSD.events.add(up, 'mouseup', function() {
						clearInterval(scroller[cur].timer);
					});
					LSD.dom.insert_after(up, scroller[0]);
					LSD.dom.insert_after(down, scroller[0]);
					
					scroller[cur].scroll_func = function(dir) {
						var top = scroller[cur].scrollTop;
						var time = ((dir < 0)?-(dir):dir);
						for (var t = time ; t > 0 ; t -= 2) {
							(function() {
								var pos = t;
								var move = parseInt(dir*(pos/time));
								setTimeout(function() { scroller[cur].scrollTop = parseInt(top+(move)); }, (pos+1)*(500/time))
							})();
						}
						// Code to change arrows
//						setTimeout(function() {
							if (top+dir <= 0) {
								up.src = '../images/scroll_up_off.gif';
							} else {
								up.src = '../images/scroll_up_on.gif';
							}
							// scrollHeight before offsetHeight for FF
							if (top+LSD.element.height(scroller[cur])+dir >= scroller[cur].scrollHeight) {
								down.src = '../images/scroll_down_off.gif';
							} else {
								down.src = '../images/scroll_down_on.gif';
							}
//						}, 550);
					};
					
					scroller[i].style.overflow = 'hidden';
				})();
			}
		}
});
