if(document.images){
	preloadImage = new Image();
	preloadImage.src = "/images/news_loading.gif";
	preloadImage = new Image();
	preloadImage.src = "/images/gallery_loading.gif";
	preloadImage = new Image();
	preloadImage.src = "/images/loading.gif";	
}

var ajaxSnippet = function(ajax_links, file){
	var div = $(ajax_links+'_div');
	var div_loading = $(ajax_links+'_loading');
	var url = '/inc/'+file;
	
	var snippets = $$("#"+ajax_links+" a");
	snippets.each(function(snippet, i) {
		snippet.addEvent("click", function(e) {
			new Event(e).stop();
			
			div_loading.addClass('loading');
			
			div.fade(0, 0);
			
			var myRequest = new Request({
				url: url,
				method: 'get',
				onComplete: function(response) {
					div.set({'html': response});
					
					external();
										
					div.fade(0, 1);
					div_loading.removeClass('loading');
				}
			}).send('ajax_id='+this.rel);
			
			var snippetsrevert = $$("#"+ajax_links+" a");
			snippetsrevert.each(function(snippetrevert, i) {
				snippetrevert.className='';
			});
			
			this.className='active';
	
		});
	});
};

var ajaxSnippetNews = function(ajax_links, file){
	var div;
	var currentlink;
	var url = '/inc/'+file;
	
	var snippets = $$("#"+ajax_links+" a");
	snippets.each(function(snippet, i) {
		snippet.addEvent("click", function(e) {
			new Event(e).stop();
			
			div = $(ajax_links+'_'+this.rel);
			
			currentlink=$(ajax_links+'_li_'+this.rel);
			currentlink.addClass('loading');
			
			div.fade(0, 0);
			
			var myRequest = new Request({
				url: url,
				method: 'get',
				onComplete: function(response) {
					div.set({'html': response});
					
					external();
										
					div.fade(0, 1);
					currentlink.removeClass('loading');
					
					this.scroll = new Fx.Scroll(window);
					this.scroll.toElement(currentlink);
				}
			}).send('ajax_id='+this.rel);
			
			var snippetsrevert = $$("#"+ajax_links+" a");
			snippetsrevert.each(function(snippetrevert, i) {
				snippetrevert.className='';
			});
			
			this.className='active';
	
		});
	});
};

function toggleQTY(showhide){
	if(showhide==0){
		$('qty_div').setStyle('display', 'none');
		$('amount_div').setStyle('display', 'block');
	}else{
		$('qty_div').setStyle('display', 'block');
		$('amount_div').setStyle('display', 'none');
	}
	
	new postFormEntry('entry_form', '/inc/payment_type.php');
}

var postForm = function(formid, url){
	$(formid).addEvent('submit', function(e) {
		e.stop();
		var form = $(formid).addClass('loading');
		
		if(!/safari\/4/i.test(navigator.userAgent)){
			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 postFormChange = function(formid, url){
	var form = $(formid).addClass('loading');
	
	form.set('send', {
		onComplete: function(response) { 
			form.removeClass('loading');
			form.set('html', response);
			
			if(formid=='orderform' && !/safari\/4/i.test(navigator.userAgent)){
				this.scroll = new Fx.Scroll(window);
				this.scroll.toElement($('step2anchor'));
			}
		}
	});

	form.send('/inc/'+url+'?step=1');
};

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.getAttribute('href') && (relAttribute=='external')){
			
			anchor.onclick = function() {
				website(this);
				return false;
			};
		}
	});
};

window.addEvent('domready', function(){
	new external();
});