if(document.images){
	preloadImage = new Image();
	preloadImage.src = "/images/loading_tat.gif";
	preloadImage = new Image();
	preloadImage.src = "/images/loading.gif";
	preloadImage = new Image();
	preloadImage.src = "/images/loading_gallery.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 tatGallery = function(gallery_id, file){
	var div;
	var url = '/inc/'+file;
	
	var snippets = $$("ul."+gallery_id+" a");
	snippets.each(function(snippet, i) {
		snippet.addEvent("click", function(e) {
			new Event(e).stop();
			
			div = $(gallery_id);
			div.fade(0, 0);
			
			var myRequest = new Request({
				url: url,
				method: 'get',
				onComplete: function(response) {
					div.set({'html': response});				
					div.fade(0, 1);
				}
			}).send('src='+this.href+'&alt='+this.title+'&gallery_id='+this.rel);
			
			var snippetsrevert = $$("ul."+gallery_id+" a");
			snippetsrevert.each(function(snippetrevert, i) {
				snippetrevert.className='';
			});
			
			this.className='active';
		});
	});
};

function website(url){
	popupWindow = window.open(url, '_blank','');
	popupWindow.focus();
}

var external = function(){
	var anchors = $$("a");
	anchors.each(function(anchor, i) {
		var relAttribute = String(anchor.getAttribute('rel'));
		if (anchor.id=='print'){
			anchor.onclick = function() {
				print();
				return false;
			};
		}else if (anchor.getAttribute('href') && (relAttribute=='external')){
			anchor.onclick = function() {
				website(this);
				return false;
			};
		}
	});
};

window.addEvent('domready', function(){
	new external();
});
