if(document.images){
	preloadImage = new Image();
	preloadImage.src = "/images/loading.gif";
	preloadImage = new Image();
	preloadImage.src = "/images/news_loading.gif";
}

var postForm = function(formid, url){
	$(formid).addEvent('submit', function(e) {
		e.stop();
		var form = $(formid).addClass('loading');
		
		this.set('send', {
			onComplete: function(response) { 
				form.removeClass('loading');
				form.set('html', response);
			}
		});

		this.send('/inc/'+url);
	});
};

var postFormChange = function(formid, url){
	var form = $(formid).addClass('loading');
	
	form.set('send', {
		onComplete: function(response) { 
			form.removeClass('loading');
			form.set('html', response);
		}
	});

	form.send('/inc/'+url+'?change=1');
};

function website(url){
	popupWindow = window.open(url, '_blank','');
	popupWindow.focus();
}

function popup(url){
	popupWindow = window.open(url, '_blank', 'location=no,menubar=no,width=600,height=520,toolbar=no,scrollbars=yes,resizable=no');
	popupWindow.focus();
}
function popupclose(){
	window.close();
}

var external = function(){
	var anchors = $$("a");
	anchors.each(function(anchor, i) {
		var relAttribute = String(anchor.getAttribute('data-rel'));
		if (anchor.id=='print'){
			anchor.onclick = function() {
				print();
				return false;
			};
		}else if (anchor.getAttribute('href')){
			if(relAttribute=='external'){
				anchor.onclick = function() {
					website(this);
					return false;
				};
			}else if(relAttribute=='popup'){
				anchor.onclick = function() {
					popup(this);
					return false;
				};
			}
		}
	});
};
var current=0;
var fadeImages = function(imagelocal){
	var current=0;
	
	var timer = 4;
	
	var images = $$(imagelocal);
	
	var max=(images.length-1);
	
	if(max>0){
		images.each(function(image, i) {
			image.setStyle('opacity', (i==0 ? 1 : 0));
			image.set('id', 'fade'+i);
		});
		
		var refresh = (function() {
			current=(current==max ? -1 : current);
			current++;
			
			new photoChange(current);
		});
	
		periodical = refresh.periodical(timer * 1000, this);
	}
};
var photoChange = function(id){	
	$('fade'+current).setStyle('z-index', '10');
	$('fade'+current).fade(1, 0);
		
	current=id;
		
	$('fade'+current).setStyle('z-index', '20');
	$('fade'+current).fade(0, 1);
};
var slideup = function() {
	var list = $$('ul.event');
	list.each(function(element) {
	 
 
		var myFx = new Fx.Tween(element, {
			property: 'height',
			duration: 1000
		});
		var height = element.offsetHeight - 26;
		element.addEvent('mouseenter', function(){
			element.tween('height',height);
			//myFx.start(-500,height);
		});
	 
		element.addEvent('mouseleave', function(){
			element.tween('height',0);
			//myFx.start(height,0);
		});
		element.tween('height',0);
		//myFx.start(0,0);
	 
	});
}
var embedVideo = function(video){
    var flashvars = { };
    var params = { allowScriptAccess: "always", allowFullScreen: "true", movie: video};
    var atts = { };
 
	swfobject.embedSWF("" + video + "&enablejsapi=1&playerapiid=player1",  "video", 430, 274, "8", '/js/expressInstall.swf', flashvars, params, atts);
};
window.addEvent('domready', function(){
	new external();
	new fadeImages('div.fadelogos ul li');
	new fadeImages('p.fade img');
	new slideup();
});
