/*
Slideshow als Werbungswidget
von Andreas Kasper
(c) 2008 by Andreas Kasper
E-Mail:djassi@web.de
*/
    $.fn.slideshow = function(options) {
		var defaults = {
			identifier: "slide_holder",
			transition_duration: 10000
		}
		var opts = $.extend(defaults, options);
		this.hide();
		this.after('<div id="'+opts.identifier+'"><span class="current_slide" style="display:none;">0</span><div class="curpic1"></div><div class="curpic2"></div><div class="nextpic1"></div><div class="nextpic2"></div><div class="clickpart"></div><div class="carousel_controls"><div class="caption"></div><div class="btn_prev"/><div class="btn_next"/></div></div>');
		opts.num_slides = this.find("li").length;
		opts.elemain = this;
		$("#"+opts.identifier+" .clickpart").click(function(e) {
			a = $("#"+opts.identifier+" .current_slide").text();
			url = opts.elemain.find("li:eq("+a+") a").attr("href");
			if (url > "") document.location.href = url;
		});
		$("#"+opts.identifier+" .btn_next").click(function() {
			a = $("#"+opts.identifier+" .current_slide").text();
			gotoslide(parseInt(a)+1, "fast");
		});
		$("#"+opts.identifier+" .btn_prev").click(function() {
			a = $("#"+opts.identifier+" .current_slide").text();
			gotoslide(parseInt(a)-1, "fast");
		});
		gotoslide = function(nr, speed) {
			clearTimeout(opts.m_timer);
			if (nr < 0) {nr = opts.num_slides-1;}
			if (nr >= opts.num_slides) {nr = 0;}			
			imgurl = opts.elemain.find("li:eq("+nr+") img").attr("src");
			imgopt = opts.elemain.find("li:eq("+nr+") img").attr("rel");
			imgtitle = opts.elemain.find("li:eq("+nr+") h1").text();
			$("#"+opts.identifier+" .current_slide").text(nr);
			$("#"+opts.identifier+" .nextpic2").css("background-image", "url("+imgurl+")");
			if (imgopt == "oversize") {
				a=opts.elemain.find("li:eq("+nr+") img").attr("rel2");
				a2=a*1+300;
				$("#"+opts.identifier+" .nextpic2").css("top", "-"+a+"px");
				$("#"+opts.identifier+" .nextpic2").css("height", a2+"px");
				} else {
				$("#"+opts.identifier+" .nextpic2").css("top", "0px");
				$("#"+opts.identifier+" .nextpic2").css("height", "300px");
				}
			$("#"+opts.identifier+" .clickpart").css("display","none");
			$("#"+opts.identifier+" .nextpic2").fadeIn(speed, function() {
				$("#"+opts.identifier+" .curpic2").css("top", $("#"+opts.identifier+" .nextpic2").css("top"));
				$("#"+opts.identifier+" .curpic2").css("height", $("#"+opts.identifier+" .nextpic2").css("height"));
				$("#"+opts.identifier+" .curpic2").css("background-image", "url("+imgurl+")");
				$("#"+opts.identifier+" .curpic2").css("display","inline");
				$("#"+opts.identifier+" .caption").text(imgtitle);
				$("#"+opts.identifier+" .clickpart").css("display","inline");
				$("#"+opts.identifier+" .nextpic2").css("display","none");
				nr2=nr+1;
				opts.m_timer = setTimeout("gotoslide("+nr2+");", opts.transition_duration);
			});
		}
		
		gotoslide(0, 3000);
	}	

