if(document.images){
	preloadImage = new Image();
	preloadImage.src = "/images/video_roll.jpg";
	preloadImage = new Image();
	preloadImage.src = "/images/loading.gif";
	preloadImage = new Image();
	preloadImage.src = "/images/gallery_closelabel.gif";
	preloadImage = new Image();
	preloadImage.src = "/images/gallery_loading.gif";
}

var postForm = function(formid, url){
	$(formid).addEvent('submit', function(e) {
		e.stop();
		var form = $(formid).addClass('loading');
		
		this.scroll = new Fx.Scroll(window);
		this.scroll.toElement(form);
		
		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 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});
					
					external();
					
					div.fade(0, 1);
				}
			}).send('gallery_id='+this.rel);
			
			var snippetsrevert = $$("ul.gallery a");
			snippetsrevert.each(function(snippetrevert, i) {
				snippetrevert.className='';
			});
			
			$('gallery_a_'+this.rel).className='active';
	
		});
	});
};

var fadeImages = function(max){
	var current=1;
	
	var timer = 7;
	var periodical; 
	 
	var refresh = (function() {
		$('area'+current).setStyle('z-index', '10');
		$('area'+current).fade(1, 0);		
		
		current=(current==max ? 0 : current);
		current++;
		
		$('area'+current).setStyle('z-index', '20');
		$('area'+current).fade(0, 1);
	});

	periodical = refresh.periodical(timer * 1000, this);
};

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();
});