$(document).ready(function(){

	$("#picture .control").fadeTo("slow",0.1);
	$("#picture .control").mouseenter(function() {
		$(this).fadeTo("fast",0.6);
	});
	$("#picture .control").mouseleave(function() {
		$(this).fadeTo("fast",0.2);
	});
	
	function strtolower(str) {
		return (str + '').toLowerCase();
	}
	
	function slideLeft() {
		//übermitteln der ID des aktuell angezeigten Artikels
		var id = $("#picture #featuredimg").attr("alt");
		var max = $("#picture #featuredimg").attr("longdesc");
		//verstecken des Buttons um mehrmaliges Klicken zu verhindern
		$("#picture .control").css({zIndex : "-999"});
					
			
		$.getJSON( "/inc/featured.php",{mode : "left", start_id : id, max_id : max},function(json) {
			//var photo = '<li><img class="right" src="/pic/' + json[0].art_headingphoto + '" alt="'+ json[0].art_id +'" longdesc="'+ max +'"/></li>';
			var photo = '<li><div id="featuredimg"class="right" style="background:url(/pic/' + json[0].art_id+ '/' + json[0].art_headingphoto + ') no-repeat 50% 50%" alt="'+ json[0].art_id +'" longdesc="'+ max +'"></div></li>';
						
			$("#picture ul").prepend(photo).load();
			$("#picture ul").css("left","-360px");
			$("#picture .left").css("left","-360px");
			$("#picture ul").animate({
					left: "0px",
				},1200, "swing", function() {
						$(this).children(":last").remove();
						//wieder einblenden des Buttons
						$("#picture .control").css({zIndex : "999"});
						
						$("#description .category").html(json[0].cat_text);
						$("#description .date").html(json[0][0]);
						$("#description h2").html(strtolower(json[0].art_title));
						$("#description p.text").html(strtolower(json[0].art_text));	
						$("#description p.text").append('<a href="/article/' + json[0].art_id + '/' + strtolower(json[0].art_title).replace(/\s/g,"-") + '/"> [weiterlesen...]</a>');	
						//Content durch Cufon ersetzen lassen
						Cufon.refresh();
						blinkingLinks();
				});	
		});
	}
	
	
	function slideRight() {
		//übermitteln der ID des aktuell angezeigten Artikels
		var id = $("#picture #featuredimg").attr("alt");
		var max = $("#picture #featuredimg").attr("longdesc");
		//verstecken des Buttons um mehrmaliges Klicken zu verhindern
		$("#picture .control").css({zIndex : "-999"});
					
			
		$.getJSON( "/inc/featured.php",{mode : "right", start_id : id, max_id : max},function(json) {
			//var photo = '<li><img class="right" src="/pic/' + json[0].art_headingphoto + '" alt="'+ json[0].art_id +'" longdesc="'+ max +'"/></li>';
			var photo = '<li><div id="featuredimg"class="right" style="background:url(/pic/' + json[0].art_id+ '/' + json[0].art_headingphoto + ') no-repeat 50% 50%" alt="'+ json[0].art_id +'" longdesc="'+ max +'"></div></li>';
			
			$("#picture ul").append(photo).load().animate({
					left: "-360px",
				},1200, "swing", function() {
						$(this).css({left: "0px"}).children(":first").remove();
						//wieder einblenden des Buttons
						$("#picture .control").css({zIndex : "999"});
						$("#picture .right").removeAttr("class");
						
						$("#description .category").html(json[0].cat_text);
						$("#description .date").html(json[0][0]);
						$("#description h2").html(strtolower(json[0].art_title));
						$("#description p.text").html(strtolower(json[0].art_text));	
						$("#description p.text").append('<a href="/article/' + json[0].art_id + '/' + strtolower(json[0].art_title).replace(/\s/g,"-") + '/"> [weiterlesen...]</a>');
						//Content durch Cufon ersetzen lassen
						Cufon.refresh();
						blinkingLinks();
					});
		});
	}
	
	
	$("#picture #right").click(function() {
		slideRight();
		window.clearInterval(autoslide);
		autoslide = window.setInterval(slideRight,30000);
	});
	
	
	$("#picture #left").click(function() {
		slideLeft();
		window.clearInterval(autoslide);
		autoslide = window.setInterval(slideRight,30000);
	});
	
	//regelmäßiges nach rechts scrollen - optional - evtl löschen!!!
	var autoslide = window.setInterval(slideRight,30000);
		
});	
