window.addEvent('domready', function() {
	loadSWFs();
	sharpLinks();
	externalLinks();
	interactiveForms();
	newsLinks();
	new Slideshow($('top-image'));
});

function loadSWFs() {
	$(document.body).getElements('*[id$=-swf]').each(function(e) {
		var id = e.id;
		var params = e.getAttribute('rel').split(',');
		
		var width = params[0];
		var height = params[1];
		var version = params[2];
		
		var opt = new Object();
		var options = params[3].split('|');
		options.each(function(o) {
			var option = o.split(':');
			opt[option[0]] = option[1];
		});

		swfobject.embedSWF('img/swf/'+ id.slice(0,-4) +'.swf', id, width, height, version, false, false, opt);
	});
}

function sharpLinks() {
	$(document.body).getElements('a[href^=#]').each(function(e) {
		e.addEvent('click', function(ev) {
			ev.stop();
			var id = e.href.slice(e.href.indexOf('#')+1);
			new Fx.Scroll(window).toElement(id);
			return false;
		});
	});
}


function externalLinks() {
	$(document.body).getElements('a[rel=ext]').each(function(e) {
		e.addEvent('click', function(ev) {
			ev.stop();
			window.open(e.href);
			return false;
		});
	});
}


function interactiveForms() {
	var input = $(document.body).getElements('input[rel=focus]');
	var selec = $(document.body).getElements('select[rel=focus]');
	var texta = $(document.body).getElements('textarea[rel=focus]');
	
	var elements = input.combine(selec);
	elements = elements.combine(texta);
	
	// alert(elements)
	
	elements.each(
		function(e) {
			var li = e.parentNode;
			e.onfocus = e.onblur = function() {
				li.className = li.className == '' ? 'focus' : ''; 
			}
		}
	);
}


function newsLinks() {
	$$('div[rel=news-link]').each(function(e) {
		e.style.cursor = 'pointer';
		e.onmouseover = function() {
			this.style.backgroundColor = '#3c5e90';
		}
		
		e.onmouseout = function() {
			this.style.backgroundColor = '';
		}
		
		e.onclick = function() {
			document.location.href = this.id.replace('-','.php?id=');
		}
	});
}
