this.nav = function() {
	$("#nav a").css("display","none");
	$("#nav a").css("background-position","0 -69px");
	$("#nav li").css("cursor","pointer");
 	$("#nav li").hover(
      function(){
        $("a",this).fadeIn("fast");
      }, 
      function(){
        $("a",this).fadeOut("fast");
      }
    );	
};
this.slideshow = function(obj) {	
		//var obj = $("#templates");
		var zaehler = 0;
		var s = $(".seiten", obj).length;
		//alert(s);
		//var w = obj.width(); 
		var w = 1024;
		var winoWidth = document.body.clientWidth;  //window.innerWidth versteht IE nicht
		var x = (winoWidth/2)-(w/2);
		var ts = s-3;
		var t = 0;
		var z = (s*w);
		//alert(z);
		$("ul", obj).css("width", z);
		$(obj).parent().append("<span class=\"prev\"><a href=\"javascript:void(0);\">Previous</a></span> <span class=\"next\"><a href=\"javascript:void(0);\">Next</a></span>");
		
		$(".prev a", obj.parent()).hide();
		$(".next a", obj.parent()).click(function(){
			animate("next");
			if (t>=ts) $(this).fadeOut();
			$(".prev a", obj.parent()).fadeIn();
		});
		$(".prev a", obj.parent()).click(function(){		
			animate("prev");
			if (t<=0) $(this).fadeOut();
			$(".next a", obj.parent()).fadeIn();
		});	
		this.animate = function(dir){
			if(dir == "next"){
				t = (t>=ts) ? ts : t+1;
				//alert(t);
			}else if(dir=="haferbrei"){
				t = 1;
				t = (t>=ts) ? ts : t+2;
			}else if(dir=="kuerbis"){
				t = 1;
				t = (t>=ts) ? ts : t+4;
			}
			else if(dir=="maisbrot"){
				t = 1;
				t = (t>=ts) ? ts : t+5;
			}
			else if(dir=="chili"){
				t = 1;
				t = (t>=ts) ? ts : t+6;
			}
			else if(dir=="kassler"){
				t = 1;
				t = (t>=ts) ? ts : t+7;
			}
			else if(dir=="muffins"){
				t = 1;
				t = (t>=ts) ? ts : t+8;
			}
			else if(dir=="dessert"){
				t = 1;
				t = (t>=ts) ? ts : t+9;
			}
			else {
				t = (t<=0) ? 0 : t-1;
			};
			//var winoWidth = document.body.clientWidth; window.innerWidth versteht IE nicht
			var x = (winoWidth/2)-(w/2);
			p = (t*w*-1);
			tmp = p;
			//alert(p + "=(" +p+ "+" +x+ "+)-"+w);
			p= (p+x)-w;
			//alert("x: "+x);
			//alert("tmp: "+tmp);
			if(zaehler==0){ 	//damit es nicht auf position2 anfängt
				p=p+w;
				//setTimeout('move_up()', 5);
				$("ul",obj).animate( { marginLeft: p }, 900, 'easeInOutCubic');
			} //damit es nicht auf position2 anfängt
			else{
				//setTimeout('move_up()', 5);
				$("ul",obj).animate( { marginLeft: p }, 900, 'easeInOutCubic');
			};
			//$("ul",obj).animate( { marginLeft: p }, 900, 'easeInOutExpo');	
			//alert(zaehler);		
		};
		animate("next");
		
			if(zaehler==0){		//damit es nicht auf position2 anfängt
			$(".prev a", obj.parent()).fadeOut();
			t = (t<=0) ? 0 : t-1;
			};
			if(zaehler!=0){		//damit es nicht auf position2 anfängt
				//$(".prev a", obj.parent()).fadeIn();
				t = (t>=ts) ? ts : t+1;
			};
		zaehler++;				//damit es nicht auf position2 anfängt
};
//prvw

this.pngfix = function() {
	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	var ie8 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 8.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6 || ie8)) {		
		$("*").each(function(){
			var bgIMG = $(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				$(this).css('background-image', 'none');
				$(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			};
		});
	};		
};

this.init = function() {
	//pngfix();
	//nav();	
	$("#templates").each(function(){	
		slideshow($(this));	
	});		
	//preview();
};

$(document).ready(function(){	
	init();
});
