/**
  *  JavaScript-Datei fuer Slideshow
  *  
  *  @author		Marius Mayer [SoftRage]
  *  @copyright	2010 by SoftRage
  *  @link			http://www.softrage.de/
  *
  */

$(document).ready(function() {
	$('.hlink').hide();		$('.sr').hide();
	
	// Aktuellen Tipp als "Ausweich"-Tipp speichern, falls keine Bildunterschrift angegeben wurde
	alt_tip = $('.tipp').html();

	// Slideshow initialisieren
    $('#slideshow').cycle({
		fx: 'fade',
	    timeout: 6000, 
	    next:   '#nextButton', 
		prev:   '#prevButton', 
		before:  onAfter
	});
	

	$("#slideshow").mousemove(function(event) {
		$('#control-div').show();
	});
	$("#slideshow").mouseout(function(){
		timeout = setTimeout(function(){
			$('#control-div').fadeOut(500);
		}, 500)
	});
	$("#control-div").mouseover(function(){
		clearTimeout(timeout);
	});


	$('#pauseButton').click(function() { 
	    $('#slideshow').cycle('pause'); 
	});

	$('#resumeButton').click(function() { 
	    $('#slideshow').cycle('resume'); 
	});

});

function clearTi(){
	clearTimeout(timeout);	
}

function onAfter(curr,next,opts) {				//var caption = 'Image ' + (opts.currSlide + 1) + ' of ' + opts.slideCount;
	// Erst ggf. sichtbares Infofeld ausblenden
	$('.info-field-top').hide();
	$('.info-field-middle').hide();
	$('.info-field-bottom').hide();
	
	// Dann je nachdem, ob Infos vorhanden sind, Text oder Standard-Spruch anzeigen
	if(this.alt.length > 1){
		if (this.alt.indexOf('|') > 0) {
			var title = this.alt.slice(0, this.alt.indexOf('|'));
			var text = this.alt.slice(this.alt.indexOf('|')+1, this.alt.length);
			$('.tipp').html(title.replace(/\[/g, "<").replace(/\]/g, ">") + "<br><div class=\"more-div\"><a href=\"javascript:void(0);\" class=\"more\" onclick=\"more('" + text + "');\">Mehr...</a></div>");
		}else{
			var title = this.alt;
			$('.tipp').html(title.replace(/\[/g, "<").replace(/\]/g, ">"));	
		}
	}else{
		$('.tipp').html(alt_tip);
	}
}

function more(text){
	$('#slideshow').cycle('pause');
	$('.info-field-top').show();
	$('.info-field-bottom').show();
	$('.info-field-middle .info').html(text.replace(/\[/g, "<").replace(/\]/g, ">"));
	$('.info-field-middle').slideDown(600);
	
	$('.tipp-field-middle a.more').click(function() { 
		$('.info-field-middle').hide('blind');
		$('.info-field-bottom').hide('blind');
		$('.info-field-top').hide('blind');
		//$('#nextButton').click();
		$('#slideshow').cycle('resume'); 
		$('.tipp-field-middle a.more').hide('blind');
	});
	$('.tipp-field-middle a.more').html('Weiter');
}


