/* Home.js */

var pos = 0;
var m = 0;
var k = 0;
var timer = 0;
var slideObj = new Object;
var slideObj2 = new Object;

function swapImage() {
		pos = 1+ (Math.floor(Math.random()*slideObj[m]));
		
		if(pos == slideObj2[m]) {
			if((pos + 1) > slideObj[m]) {
				pos--;
			}
			else {
				pos++;
			}
		}
		
		slideObj2[m] = pos;
		
		tmp = $('#teaser .el_'+m+' .img img:visible');
		
		$('#teaser .el_'+m+' .img .img_'+pos).fadeIn("slow");
		tmp.fadeOut("slow");
		
		m = 1+ (Math.floor(Math.random()*4));
		setTimeout("swapImage()", 5000);
	}

$(document).ready(function() {
	
	
	
	/*##################### Scrollbar ###############################################*/
	
	$('#pane').jScrollPane({showArrows: true});
	
	
	/*##################### Slide ##################################################*/
	
	$('#teaser .slide .item_2').parent().parent().addClass('el_1');
	$('#teaser .slide .item_3').parent().parent().addClass('el_2');
	$('#teaser .slide .item_4').parent().parent().addClass('el_3');
	$('#teaser .slide .item_5').parent().parent().addClass('el_4');
	
	$('#teaser .el_1 .more a').text('mehr dazu');
	$('#teaser .el_1 .more a').attr('href', '/index.php?id=02');
	$('#teaser .el_2 .more a').text('mehr dazu');
	$('#teaser .el_2 .more a').attr('href', '/index.php?id=03');
	$('#teaser .el_3 .more a').text('mehr dazu');
	$('#teaser .el_3 .more a').attr('href', '/index.php?id=04');
	$('#teaser .el_4 .more a').text('mehr dazu');
	$('#teaser .el_4 .more a').attr('href', '/index.php?id=05');
	
	$('#teaser .slide dt a').each(function(){
		$(this).text('');
	})
	
	k = 0;
	$('#teaser .el_1 .img img').each(function(){
		k++;
		$(this).addClass("img_"+k);
	})
	k = 0;
	$('#teaser .el_2 .img img').each(function(){
		k++;
		$(this).addClass("img_"+k);
	})
	k = 0;
	$('#teaser .el_3 .img img').each(function(){
		k++;
		$(this).addClass("img_"+k);
	})
	k = 0;
	$('#teaser .el_4 .img img').each(function(){
		k++;
		$(this).addClass("img_"+k);
	})
	
	
	/*##################### Set Anker ############################################*/
	$('.news-list-item h3 a').click(function(){
		href = $(this).attr('href');
		
		href = href + '#single';
		
		window.location.href = href;
		
		return false;
	});
	
	
	
	/*##################### Image Slide ############################################*/
	
	$('#teaser .slide .img').each(function(){
		m++;
		
		$(this).find('img:not(:first)').hide(0);
		
		slideObj[m] = Object;
		slideObj2[m] = Object;
		slideObj[m] = $(this).find('img').size();
		slideObj2[m] = 1;		
	});
	
	setTimeout("swapImage()", 5000);
});
