var way = 1000;

function scroll(direction) {
	if(!this.active) this.active = 0;
	if(direction == 'left') {
		way= 1000;
		if(this.active > 0) this.next = parseInt(this.active)-1;
		else this.next = max;
		$('#img'+next).css({'left':'-1000px'}) 
	}
	else {
		way = -1000;
		if(this.active < max) this.next = parseInt(this.active)+1;
		else this.next = 0;
		
	}
	$('#img'+active).animate({'left':way+'px'});
	$('#img'+next).animate({'left':'0px'},function() {
		$('#scroller div').each(function() { 
			if($(this).attr('id') !='img'+next) $(this).css({'left':'1000px'}) 
		})
	});
	active = next;
}

$(document).ready(function() {
	$('.scroll.links').click(function() {
		scroll('left');
		return false;
	});
	$('.scroll.rechts').click(function() {
		scroll('right');
		return false;
	});
});


function changeLang() {
	$('#content').load('/cgi-bin/adframe/snp/lang.snp',{'referrer':self.location.hash});
}

function hideAll(topic) {
	$('#menu ul li').each(function() { 
		if($(this).attr('id') != '_'+topic) {
			if( $(this).next("div").is(":visible") ) $(this).next("div").slideUp(100);
			$(this).removeClass('selected');
		}
	});
}

function navi(topic,article,query) {
	$.address.value($(this).attr('href')); 
	if(article == '' || !article || (topic == 'produkte' && !article.match(/jpg|png|gif/i))) page='index';
	else page='article';
				
	hideAll(topic);
	$("#_"+topic+" + div").slideDown(100); 
	$('#content').fadeOut(100,function () {
		if($(window).scrollTop() > 481) $(document).scrollTo('#contents',200);
		$('#loading').show();
		$('#content').load('/cgi-bin/adframe/'+topic+'/'+page+'.snp',{'short':article,'id':sessionId,'start':query},function() {
			$('#loading').hide();
			$('#content').fadeIn(100); 
			
		})
	});
	$('#_'+topic).addClass('selected');
	$.address.title('allride :: '+topic);
	var randomnumber=Math.floor(Math.random()*11);
	if(randomnumber < 3) scroll();
	return false;
}
			
$.address.change(function(event) {
	var uri=self.location.hash;
	var uriParts = uri.split('?');
	var hash = uriParts.shift();
	var query = uriParts.shift();
	hash = hash.replace(/(^#\!?\/?)/,'');
	var teile = hash.split('/');
	var section = teile.shift();
	var rest = teile.join('/');
	if(section=='') { section='blog';}
	navi(section,rest,query);
});
