/**
 * Purple7
 * (c) 2010 LoRd <Andreas Sattler>
 */

var item = 0;
var aktivswitch;
function switcher(ev, el){
	if(ev == 'click'){
		var newsrc = $(el).attr('rel'); 
		$('#control img').removeClass('active');
		$(el).find("img").addClass('active');
		showNewSwitch(newsrc, ev);
	}
	else if(ev == 'auto'){
		Children = $('#control a');
		numChildren = Children.length;
		if(item >= numChildren) item = 0;
		var newsrc = Children.eq(item).attr('rel');
		$('#control img').removeClass('active');
		Children.eq(item).find("img").addClass('active');
		showNewSwitch(newsrc, ev);
	}
}
function showNewSwitch(newsrc, ev){
	var s = newsrc.split(';');
	var imgsrc = jQuery.trim(s[0]);
	if(s.length > 1) url = s[1];
	else url = '#';
	if(s.lenth > 2) target = s[2];
	else target = '_self';
	$('#switch').attr('href', url);
	$('#switch').attr('target', target);
	$('#switchImg').attr('src',imgsrc);
	if (ev == 'auto') {
		item++; 
		aktivswitch = window.setTimeout('switcher(\'auto\')', 7000); 
	}
}
$(document).ready(function(){
	switcher('auto');
	$('#control > li > a').click(function(){ 
		aktivswitch = window.clearTimeout(aktivswitch); 
		switcher('click', $(this)); 
	});
});