 jQuery(document).ready(function($) {
	  
//show_homepage
		bannerwidth = jQuery(".bannerwrapper").eq(0).width()+"px";
		jQuery(".bannercontainer td").attr("width",bannerwidth);
		bannerheight = jQuery(".bannerwrapper").height();
		navitopoffset = (bannerheight/2-30);
		if(navitopoffset > 0) {
			jQuery("#prevbanner, #nextbanner").css("top",navitopoffset);
		}
		//jQuery(".bannercontainer td").height(jQuery(".bannerwrapper img").eq(0).height()+"px");
	    jQuery("#nextbanner").click(function() {
			bannernum = jQuery(".bannercontainer .bannercol").size()+1;
			//alert(bannernum);
			if(jQuery(".bannercontainer").attr("num") == undefined || jQuery(".bannercontainer").attr("num") == 1) {
				jQuery(".bannercontainer").attr("num",2)
			} else {
				jQuery(".bannercontainer").attr("num",parseInt(jQuery(".bannercontainer").attr("num"))+1);
				if(jQuery(".bannercontainer").attr("num") > bannernum) {
					jQuery(".bannercontainer").attr("num","1");
				}
			}
			numoffset = jQuery(".bannercontainer").attr("num")-1;
			numoffset2 = jQuery(".bannercontainer").attr("num");
			if (numoffset > bannernum) {
			
				jQuery(".bannercontainer").attr("num","1");
				numoffset = "0";
			}
			if(numoffset2 == bannernum && bannernum < 2) {
				jQuery(".bannercontainer").attr("num","1");
				numoffset = "0";
			}
			
			containerwidth = jQuery(".bannercontainer td .bannercol").eq(numoffset).width();

			
			//containerheight = jQuery(".bannercontainer img").eq(0).height();
			bannerwidth = containerwidth*numoffset;
			jQuery(".bannerwrapper").width(containerwidth);
			bannerwidth = "-"+bannerwidth;
			
			jQuery(".bannercontainer").animate({
				marginLeft: bannerwidth+"px"
			},500);
	  });
	  
	  jQuery("#prevbanner").click(function() {
			bannernum = jQuery(".bannercontainer .bannercol").size()+1;
			if(jQuery(".bannercontainer").attr("num") == undefined || jQuery(".bannercontainer").attr("num") == 1) {
				jQuery(".bannercontainer").attr("num",jQuery(".bannercontainer .bannercol").size());

			} else {
				jQuery(".bannercontainer").attr("num",parseInt(jQuery(".bannercontainer").attr("num"))-1);
				if(jQuery(".bannercontainer").attr("num") < 1) {
					jQuery(".bannercontainer").attr("num",bannernum);
				}
			}
			numoffset = jQuery(".bannercontainer").attr("num")-1;
			
			if(numoffset == bannernum) {
			
				jQuery(".bannercontainer").attr("num",1);
				numoffset = 0;
			}
			containerwidth = jQuery(".bannercontainer td .bannercol").eq(numoffset).width();

			
			//containerheight = jQuery(".bannercontainer img").eq(0).height();
			bannerwidth = containerwidth*numoffset;
			jQuery(".bannerwrapper").width(containerwidth);
			bannerwidth = "-"+bannerwidth;
			
			jQuery(".bannercontainer").animate({
				marginLeft: bannerwidth+"px"
			},500);
	  });
		

	  var thebutton;
		jQuery("a.vote").click(function() {
			if(jQuery(this).hasClass("confirmed") == true) {
				alert("Sie müssen 24 Stunden warten bis Sie eine weitere Empfehlung für diesen Händler abgeben können");
			} else {
				if(jQuery(this).hasClass("votebutton") == true) {
					thebutton = jQuery(this);
					topoffset = thebutton.offset().top - 4;
					leftoffset = thebutton.offset().left - 4;
					shopid = ".shopid"+thebutton.attr("shopid");
					thecontent = jQuery(shopid);
					jQuery(shopid+" span").each(function (index, domEle) {
						//alert(jQuery(domEle).text());
					});
					
					
					jQuery("#shopid").attr("value", thebutton.attr("shopid"));
					jQuery(".votelayer").css({"top": topoffset , "left": leftoffset , "position": "absolute"});
					jQuery(".votelayer").fadeIn(500);
					
				} else {
					thebutton = jQuery(this).prev();
					topoffset = thebutton.offset().top - 4;
					leftoffset = thebutton.offset().left - 4;
					jQuery("#shopid").attr("value", thebutton.attr("shopid"));
					jQuery(".votelayer").css({"top": topoffset , "left": leftoffset , "position": "absolute"});
					jQuery(".votelayer").fadeIn(500);
				}
			}
		});
		jQuery(".confirm_vote").click(function(button) {
			thebutton.addClass("votebutton_confirmed");
			thebutton.addClass("confirmed");
			thebutton.next().addClass("confirmed");
			jQuery(".votelayer").fadeOut(500);
		});
		jQuery(".cancel_vote").click(function(button) {
			jQuery(".votelayer").fadeOut(500);
		});
		
		
		
		
		jQuery("#slider").easySlider({
			prevText: "&nbsp;",
			nextText: "&nbsp;",
			speed: 		300,
			auto:		true,
			pause:		5000,
			numericId: "controls",
			numeric: true

		});
		$(".product_imgs li").hover(
		  function () {jQuery(".lupe").show();},
		  function () {jQuery(".lupe").hide();}
		);

		
		
		
		
		jQuery("#registerslider").easySlider({
			controlsShow:	true,
			nextControls:	true,
			vertical:		true,
			prevText: "&nbsp;",
			prevId:		"sliderprev",
			nextText: "&nbsp;",
			nextId:		"slidernext",
			controlsFade:		true,
			speed: 		300,
			auto:		false,
			pause:		5000,
			numericId: "controls",
			numeric: true,
			// My callback function :
			esCallback: function(nt,n)
			{
			n = parseInt(n);
			nt = parseInt(nt)+1;
			actpage = nt;
			var notvalid = 0;
				jQuery("#registerslider ul li:nth-child("+n+") .req").html("");
				jQuery("#registerslider ul li:nth-child("+n+") [req=\"true\"]").each(function(index){
					if(jQuery(this).val()=="") {
						jQuery(this).next("span").html("!");
						notvalid = 1;
					}
					if(jQuery(this).attr("name") == "postleitzahl") {
					
						if(isNaN(jQuery(this).val()) == true || jQuery(this).val().length < 5) {
							alert("Ungültige Postleitzahl");
							return notvalid;
						}
					}
				});
				if (notvalid == 1) {
					alert("Bitte alle Pflichtfelder ausfüllen");
					return notvalid;
				} else {
					//controlprogress = "#controls"+n;
					//jQuery(controlprogress).css("cssText", "background-color: #7FB500");
					modprogress = ".page"+n;
					jQuery(modprogress).addClass("green");
					jQuery(modprogress).removeClass("act");
					jQuery("#registerslider ul li:nth-child("+actpage+") input").attr("tabindex","-1");
					n = n+1;
					jQuery("#registerslider ul li:nth-child("+n+") input").attr("tabindex","1");
					modprogress = ".page"+n;
					topage = n;
					showpage = topage+1;
					tabheader = jQuery("#registerslider ul li:nth-child("+showpage+") h1").html();
					if (tabheader!=null) {
						jQuery("#controls"+showpage).show();
					}
					if(actpage < topage && jQuery(modprogress).hasClass("green") != true) {
						//controlprogress = "#controls"+n;
						//jQuery(controlprogress).css("cssText", "background-color: #AA0515 !important");
						jQuery(modprogress).addClass("act");
						jQuery(modprogress).removeClass("green");
					}else {
						
					}
				}
			}

		});
		jQuery(".registerform #controls li").hide();
			jQuery(".registerform #controls"+1+",#controls"+2).show();
		
		
		if(jQuery("#slider").length > 0 ) {
			if(jQuery("#slider ul li").children().hasClass("lightview") != true) {
				jQuery("#nextBtn a").hide();
				jQuery("#controls").hide();
			}
		}

//Fancybox
			function formatTitle(title, currentArray, currentIndex, currentOpts) {
				fancyIndex = currentIndex + 1;
				fancyLength = currentArray.length;
				if (fancyIndex == 1) {
					fancyTitleNav = '<a class="titlePrev titleTransparent">&nbsp;</a> <a class="titleNext" title="nächstes Bild" href="javascript:;" onclick="$.fancybox.next();">&nbsp;</a>';
				}
				if (fancyIndex == currentArray.length) {
					fancyTitleNav = '<a class="titlePrev" title="vorheriges Bild" href="javascript:;" onclick="$.fancybox.prev();">&nbsp;</a> <a class="titleNext titleTransparent">&nbsp;</a>';
				}
				if (fancyIndex != 1 && fancyIndex != currentArray.length) {
					fancyTitleNav = '<a class="titlePrev" title="vorheriges Bild" href="javascript:;" onclick="$.fancybox.prev();">&nbsp;</a> <a class="titleNext" title="nächstes Bild" href="javascript:;" onclick="$.fancybox.next();">&nbsp;</a>';
				}
				if (currentArray.length == 1) {
					fancyTitleNav = '<a class="titlePrev titleTransparent" title="vorheriges Bild">&nbsp;</a> <a class="titleNext titleTransparent" title="nächstes Bild">&nbsp;</a>';
				}
				return '<div class="fancy_title_wrap">' + (title && title.length ? title : '' ) + '</div><div style="clear: both;"></div><div class="fancy_img_cnt"><span style="display: block; float: left;">&nbsp;Bild ' + (currentIndex + 1) + ' von ' + currentArray.length + '&nbsp;</span>' + fancyTitleNav +'</div><div style="clear: both;"></div>';
			}
			function formatTitleBigClose(title, currentArray, currentIndex, currentOpts) {

				return '<div id="legend">&nbsp;</div><a class="closelarge" href="javascript:;" onclick="$.fancybox.close();">&nbsp;</a><div style="clear: both;"></div>';
			}
			
			/* This is basic - uses default settings */
			
			$("a.gmap").fancybox( {
				'showCloseButton'	: false,
				'titlePosition' 	: 'inside',
				'titleFormat'		: formatTitleBigClose,				
				'width'				: '90%',
				'height'			: '99%',
				'autoScale'     	: true,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'iframe',
				'showNavArrows'			: false,
				'padding'			: '1px',
				'overlayColor'		: '#000'

			});
			
			
			$("a[rel=group]").fancybox( {
				'showCloseButton'	: true,
				'titlePosition' 	: 'inside',
				'titleFormat'		: formatTitle,				
				'width'				: '90%',
				'height'			: '99%',
				'autoScale'     	: true,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'image',
				'padding'			: '1px',
				'overlayColor'		: '#000'

			});
			$("a.lightview").fancybox( {
				'showCloseButton'	: true,
				'titlePosition' 	: 'inside',
				'titleFormat'		: formatTitle,				
				'width'				: '90%',
				'height'			: '99%',
				'autoScale'     	: true,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'image',
				'padding'			: '1px',
				'overlayColor'		: '#000'

			});
			$("a.tipps").fancybox( {
				'modal'             :true,
				'overlayColor'		: '#000'
			});
			
		
		
	  });
	  function openpano(panoxml){
		panoheight = $("#map").height();
		if(panoheight == null) {
			panoheight = 600
		}
		popupheight = panoheight+82;
		panowidth = $("#map").width();
		if(panowidth == null) {
			panowidth = 1000
		}
		var a = Math.random();
		a = 10*a;
		a = Math.round(a);
		var fenster = (window.open("http://www.einkaufen-in-braunschweig.de/typo3_map/index.php?id=46&pano="+panoxml, a, "width="+panowidth+",height="+popupheight+",status=no,scrollbars=no,resizable=no,left=30,top=130"));
		window.self.blur();
		setTimeout("fenster.focus();",0);
	  }
