/*
 * jQuery Baur Autoteaser Plugin $Revision: 85 $ - $Date: 2011-06-22 14:55:59 +0200 (Mi, 22 Jun 2011) $
 * @requires jQuery v1.3.2 or later
 * $Author: cs $
 * Copyright: BAUR Versand, 96222 Burgkunstadt
 * Doc: http://docs.jquery.com/Plugins/Authoring
 * minified version created with : http://compressorrater.thruhere.net/ Compressor: YUI Compressor, Options: preserveAllSemi, disableOpt
 */
(function(b) {
	var c= {
		teaserList:null,
		animationInterval:10,
		waitingTimeBeforeStart:3,
		mainContainerHeight:370,
		animationType:"fading",
		selectorAnimationGroupContainer:".animationGroupContainer",
		selectorAnimationGroup:".animationGroup",
		callFunctionAfterSuccess: function() {
		},
		debug:false,
		debugOuputMessagePrefix:"Baur Autoteaser : "
	};
	var a= {
		init: function(o) {
			var h=jQuery(this).eq(0);
			if(h.length>0) {
				var o=jQuery.extend({},c,o);
				if(o.debug) {
					a.debugOutput({
						error:h
					});
				}
				if(o.teaserList) {
					if(o.debug) {
						a.debugOutput({
							error:o.teaserList
						});
					}
					jQuery.each(o.teaserList, function(w,t) {
						if(t!="") {
							var z=t["imageurl"];
							var A=t["flashurl"];
							var y=t["linkurl"];
							var s=t["width"];
							var B=t["height"];
							var x=t["delay"];
							if((typeof(A)!="undefined")||(typeof(z)!="undefined"&&typeof(y)!="undefined")) {
								var v='<div class="teaser visibleNo">';
								if(typeof(A)!="undefined") {
									v+='<div class="slotFlashBackground" id="flashcontent_'+w+'"></div>';
								} else {
									if(typeof(z)!="undefined"&&typeof(y)!="undefined") {
										v+='<a class="slotImageBackground" href="'+y+'">';
										v+='<input type="hidden" name="imagepath" value="'+z+'">';
										v+="</a>";
									}
								}
								v+="</div>";
								jQuery(o.selectorAnimationGroup,h).append(v);
								var u=((typeof(A)!="undefined"&&typeof(s)!="undefined"&&typeof(B)!="undefined")&&(A!=""&&s!=""&&B!="")?true:false);
								if(u) {
									if(o.debug) {
										a.debugOutput({
											error:"init Flash Content"
										});
									}
									swfobject.addDomLoadEvent( function() {
										swfobject.createSWF({
											data:A,
											width:s,
											height:B
										}, {
											wmode:"transparent"
										},"flashcontent_"+w);
									});
								}
							}
						}
					});
				}
				if(o.mainContainerHeight) {
					if(o.debug) {
						a.debugOutput({
							error:"custom height: "+o.mainContainerHeight
						});
					}
					h.height(o.mainContainerHeight);
					jQuery(".teaser, .teaser .slotFlashBackground, .teaser .slotImageBackground",h).height(o.mainContainerHeight);
					jQuery(o.selectorAnimationGroupContainer+" .teaser:first",h).addClass("firstItem");
					jQuery(o.selectorAnimationGroupContainer+" .teaser:last",h).addClass("lastItem");
				}
				var p=jQuery(o.selectorAnimationGroup,h);
				var e=jQuery("div.teaser",h);
				var r=jQuery("div.teaser:first",h);
				if(o.animationType=="fading") {
					e.hide().removeClass("visibleNo");
					r.fadeIn("slow", function() {
						jQuery(this).addClass("active prepareAnimation");
					});
				} else {
					r.removeClass("visibleNo").addClass("active");
				}
				if(e.length>1) {
					var g="div.teaserAnimationNavigator span#teaserAnimationNavigatorDynamicMenue";
					var q="div.teaserAnimationNavigator span#teaserAnimationNavigatorAutomaticNavigation";
					
					var m = '';
					//m+='<a class="teaserAnimationNavigatorMenuePrev" href="javascript:void(0);"></a><a class="hiddenMenueForAutoNavigationPrev" href="javascript:void(0);"></a>';
					//m+='<a class="teaserAnimationNavigatorMenueNext" href="javascript:void(0);"></a><a class="hiddenMenueForAutoNavigationNext" href="javascript:void(0);"></a>';
					m+='<div class="teaserAnimationNavigator">';
					m+='<div class="teaserAnimationNavigatorContent">';
					m+='<span id="teaserAnimationNavigatorDynamicMenue">';
					m+='<a class="flashGroupPlayButton" href="javascript:void(0);"><span></span></a>';
					m+="</span>";
					m+='<span id="teaserAnimationNavigatorAutomaticNavigation"></span>';
					m+="</div>";
					m+="</div>";
					h.append(m);
					var n=0;
					
					jQuery('.teaserAnimationNavigator', h).append('<a class="flashGroupMenueItem teaserAnimationNavigatorMenuePrev" href="javascript:void(0);">&laquo;</a><a class="hiddenMenueForAutoNavigationPrev" href="javascript:void(0);"></a>');
					
					e.each( function(s) {
						n++;
						var t=jQuery(this);
						t.attr({
							"animationgroupindex":n
						});
						jQuery(".slotImageBackground",t).css({
							"background-image":"url("+jQuery(".slotImageBackground input[name='imagepath']",t).val()+")"
						});
						jQuery(g,h).append('<a class="flashGroupMenueItem" animationgroupindex="'+n+'" href="javascript:void(0);"><span>'+n+"</span></a>");
						jQuery(q,h).append('<a class="hiddenMenueForAutoNavigation" animationgroupindex="'+n+'" href="javascript:void(0);"></a>');
					});
					
					jQuery('.teaserAnimationNavigator', h).append('<a class="flashGroupMenueItem teaserAnimationNavigatorMenueNext" href="javascript:void(0);">&raquo;</a><a class="hiddenMenueForAutoNavigationNext" href="javascript:void(0);"></a>');
					
					function i(v) {
						if(typeof(v)=="undefined"||typeof(v)!="boolean") {
							var v=false;
						}
						var s=h.find(g+" a.flashGroupMenueItem.active, "+q+" a.active").attr("animationgroupindex");
						var t=h.find("div.teaserAnimationNavigator a.teaserAnimationNavigatorMenuePrev, div.teaserAnimationNavigator a.hiddenMenueForAutoNavigationPrev");
						var u=h.find("div.teaserAnimationNavigator a.teaserAnimationNavigatorMenueNext, div.teaserAnimationNavigator a.hiddenMenueForAutoNavigationNext");
						if(s>1) {
							t.addClass("active");
						} else {
							t.removeClass("active");
						}
						if(s==n) {
							u.removeClass("active");
						} else {
							u.addClass("active");
						}
						if(v) {
							d({
								animationInterval:o.animationInterval,
								clearCustomInterval:v
							});
						}
					}

					function k() {
						var t=jQuery(q+" a").length;
						var s=parseInt(jQuery(q+" a.active",h).attr("animationgroupindex"));
						if(s==t) {
							jQuery(q+" a:first",h).click();
						} else {
							jQuery("a.hiddenMenueForAutoNavigationNext",h).click();
						}
					}

					function d(s) {
						var s=jQuery.extend({
							playButton:jQuery(g+" a.flashGroupPlayButton",h),
							animationInterval:null,
							clearCustomInterval:false
						},s|| {});
						if(s.clearCustomInterval) {
							window.clearInterval(startAutoNavigation);
							s.playButton.removeClass("stop").addClass("start");
						} else {
							s.animationInterval=Math.abs(s.animationInterval*1000);
							if(s.animationInterval<1000) {
								s.animationInterval=Math.abs(s.animationInterval*5000);
							}
							if(s.playButton.hasClass("stop")) {
								window.clearInterval(startAutoNavigation);
								s.playButton.removeClass("stop").addClass("start");
							} else {
								if(s.playButton.hasClass("start")) {
									startAutoNavigation=window.setInterval(k,s.animationInterval);
									s.playButton.removeClass("start").addClass("stop");
								} else {
									startAutoNavigation=window.setInterval(k,s.animationInterval);
									s.playButton.addClass("stop");
								}
							}
						}
					}

					setTimeout( function() {
						d({
							animationInterval:o.animationInterval
						});
					},Math.abs(o.waitingTimeBeforeStart*1000));
					jQuery(g+" a.flashGroupPlayButton").click( function() {
						d({
							playButton:jQuery(this),
							animationInterval:o.animationInterval
						});
					});
					h.find(g+" a.flashGroupMenueItem:first, "+q+" a:first").addClass("active");
					h.find("a.teaserAnimationNavigatorMenueNext, a.hiddenMenueForAutoNavigationNext").addClass("active");
					h.find(g+" a.flashGroupMenueItem, "+q+" a").unbind("click").click( function() {
						h.find(g+" a.flashGroupMenueItem, "+q+" a").removeClass("active");
						jQuery(this).addClass("active");
						var t=(jQuery(this).attr("animationgroupindex")-1);
						var s=jQuery("div.teaser",p).get(t);
						if(o.animationType=="fading") {
							jQuery(s).fadeIn("slow", function() {
								jQuery(".teaser.prepareAnimation",p).fadeOut("slow", function() {
									jQuery(this).removeClass("active prepareAnimation");
									jQuery(s).addClass("active prepareAnimation");
								});
							});
						} else {
							jQuery("div.teaser",p).removeClass("active").addClass("visibleNo");
							jQuery(s).removeClass("visibleNo").addClass("active");
						}
						var u=h.find(g+" a.flashGroupMenueItem, "+q+" a").get(t);
						jQuery(u).addClass("active");
						l({
							clearInterval:jQuery(this).hasClass("flashGroupMenueItem")
						});
					});
					h.find("a.teaserAnimationNavigatorMenuePrev, a.hiddenMenueForAutoNavigationPrev").unbind("click").click( function() {
						if(j()=="first") {
							f({
								type:"jumptolast",
								getCurrentSelectedGroupTeaser:jQuery("div.teaser:last",p),
								getCurrentSelectedMenueDynamic:jQuery(g+" a.flashGroupMenueItem:last",h),
								getCurrentSelectedAutomaticNavigation:jQuery(q+" a:last",h),
								clearInterval:true,
								animationType:o.animationType
							});
						} else {
							f({
								type:"prev",
								getCurrentSelectedGroupTeaser:jQuery("div.teaser.active:not(':first')",p),
								getCurrentSelectedMenueDynamic:jQuery(g+" a.flashGroupMenueItem.active",h).not(jQuery(g+" a.flashGroupMenueItem:first",h)),
								getCurrentSelectedAutomaticNavigation:jQuery(q+" a.active",h).not(jQuery(q+" a:first",h)),
								clearInterval:jQuery(this).hasClass("teaserAnimationNavigatorMenuePrev"),
								animationType:o.animationType
							});
						}
					});
					h.find("a.teaserAnimationNavigatorMenueNext, a.hiddenMenueForAutoNavigationNext").unbind("click").click( function() {
						if(j()=="last") {
							f({
								type:"jumptofirst",
								getCurrentSelectedGroupTeaser:jQuery("div.teaser:first",p),
								getCurrentSelectedMenueDynamic:jQuery(g+" a.flashGroupMenueItem:first",h),
								getCurrentSelectedAutomaticNavigation:jQuery(q+" a:first",h),
								clearInterval:true,
								animationType:o.animationType
							});
						} else {
							f({
								type:"next",
								getCurrentSelectedGroupTeaser:jQuery("div.teaser.active:not(':last')",p),
								getCurrentSelectedMenueDynamic:jQuery(g+" a.flashGroupMenueItem.active",h).not(jQuery(g+" a.flashGroupMenueItem:last",h)),
								getCurrentSelectedAutomaticNavigation:jQuery(q+" a.active",h).not(jQuery(q+" a:last",h)),
								clearInterval:jQuery(this).hasClass("teaserAnimationNavigatorMenueNext"),
								animationType:o.animationType
							});
						}
					});
					function l(s) {
						var s=jQuery.extend({
							clearInterval:false
						},s|| {});
						i(s.clearInterval);
					}

					function j() {
						var t=jQuery("div.teaser.prepareAnimation",p).attr("animationgroupindex");
						var s="";
						if(t==n) {
							s="last";
						} else {
							if(t==1) {
								s="first";
							} else {
							}
						}
						return s;
					}

					function f(t) {
						var t=jQuery.extend({
							type:null,
							getCurrentSelectedGroupTeaser:null,
							getCurrentSelectedMenueDynamic:null,
							getCurrentSelectedAutomaticNavigation:null,
							clearInterval:null,
							animationType:null
						},t|| {});
						if(t.type&&t.getCurrentSelectedGroupTeaser&&t.getCurrentSelectedMenueDynamic&&t.getCurrentSelectedAutomaticNavigation) {
							if(t.animationType=="fading") {
								if(t.type=="next"||t.type=="prev") {
									t.getCurrentSelectedGroupTeaser.removeClass("active");
									t.getCurrentSelectedMenueDynamic.removeClass("active");
									t.getCurrentSelectedAutomaticNavigation.removeClass("active");
								} else {
									jQuery(g+" a.flashGroupMenueItem.active",h).removeClass("active");
									jQuery(q+" a.active",h).removeClass("active");
								}
								if(t.type=="next") {
									var v=t.getCurrentSelectedGroupTeaser.next("div.teaser");
									var u=t.getCurrentSelectedMenueDynamic.next("a");
									var s=t.getCurrentSelectedAutomaticNavigation.next("a");
									v.fadeIn("slow", function() {
										t.getCurrentSelectedGroupTeaser.fadeOut("slow", function() {
											jQuery(this).removeClass("active prepareAnimation");
											v.addClass("active prepareAnimation");
											u.addClass("active");
											s.addClass("active");
										});
									});
								} else {
									if(t.type=="prev") {
										var v=t.getCurrentSelectedGroupTeaser.prev("div.teaser");
										var u=t.getCurrentSelectedMenueDynamic.prev("a");
										var s=t.getCurrentSelectedAutomaticNavigation.prev("a");
										v.fadeIn("slow", function() {
											t.getCurrentSelectedGroupTeaser.fadeOut("slow", function() {
												jQuery(this).removeClass("active prepareAnimation");
												v.addClass("active prepareAnimation");
												u.addClass("active");
												s.addClass("active");
											});
										});
									} else {
										if(t.type=="jumptolast"||t.type=="jumptofirst") {
											var v=t.getCurrentSelectedGroupTeaser;
											var u=t.getCurrentSelectedMenueDynamic;
											var s=t.getCurrentSelectedAutomaticNavigation;
											jQuery("div.teaser.active.prepareAnimation").fadeOut("slow", function() {
												jQuery(this).removeClass("active prepareAnimation");
												v.fadeIn("slow", function() {
													jQuery(this).addClass("active prepareAnimation");
													u.addClass("active");
													s.addClass("active");
												});
											});
										} else {
										}
									}
								}
							} else {
								t.getCurrentSelectedGroupTeaser.removeClass("active").addClass("visibleNo");
								t.getCurrentSelectedMenueDynamic.removeClass("active");
								t.getCurrentSelectedAutomaticNavigation.removeClass("active");
								if(t.type=="next") {
									t.getCurrentSelectedGroupTeaser.next("div.teaser").removeClass("visibleNo").addClass("active");
									t.getCurrentSelectedMenueDynamic.next("a").addClass("active");
									t.getCurrentSelectedAutomaticNavigation.next("a").addClass("active");
								} else {
									t.getCurrentSelectedGroupTeaser.prev("div.teaser").removeClass("visibleNo").addClass("active");
									t.getCurrentSelectedMenueDynamic.prev("a").addClass("active");
									t.getCurrentSelectedAutomaticNavigation.prev("a").addClass("active");
								}
							}
							l({
								clearInterval:t.clearInterval
							});
						}
					}

				}
				o.callFunctionAfterSuccess();
			} else {
				if(o.debug) {
					a.debugOutput({
						error:"no animation container found!"
					});
				}
			}
		},
		debugOutput: function(e) {
			var e=jQuery.extend({
				error:null,
				debugOuputMessagePrefix:""
			},e|| {});
			e=jQuery.extend({},c,e);
			if(e.error&&(("console" in window)&&("firebug" in console))) {
				d();
			}
			function d() {
				var f=(typeof(e.error)=="object"?e.error:e.debugOuputMessagePrefix+e.error);
				console.log(f);
			}

		}
	};
	jQuery.fn.autoteaser= function(d) {
		if(a[d]) {
			return a[d].apply(this,Array.prototype.slice.call(arguments,1));
		} else {
			if(typeof d==="object"||!d) {
				return a.init.apply(this,arguments);
			} else {
				jQuery.error("Method "+d+" does not exist on jQuery.autoteaser");
			}
		}
	};
})(jQuery);
