// jQuery Menu
// Initialization, you can leave this here or move this somewhere else
$(function(){
	$('ul.jd_menu').jdMenu({	onShow: loadMenu
								//onHideCheck: onHideCheckMenu,
								//onHide: onHideMenu, 
								//onClick: onClickMenu, 
								//onAnimate: onAnimate
								});
	$('ul.jd_menu_vertical').jdMenu({onShow: loadMenu, onHide: unloadMenu, offset: 1, onAnimate: onAnimate});
});

function onAnimate(show) {
	//$(this).fadeIn('slow').show();
	if (show) {
		$(this)
			.css('visibility', 'hidden').show()
				.css('width', $(this).innerWidth())
			.hide().css('visibility', 'visible')
		.fadeIn('normal');
	} else {
		$(this).fadeOut('fast');
	}
}

var MENU_COUNTER = 1;
function loadMenu() {
	if (this.id == 'dynamicMenu') {
		$('> ul > li', this).remove();

		var ul = $('<ul></ul>');
		var t = MENU_COUNTER + 10;
		for (; MENU_COUNTER < t; MENU_COUNTER++) {
			$('> ul', this).append('<li>Item ' + MENU_COUNTER + '</li>');
		}
	}
}

function unloadMenu() {
	if (MENU_COUNTER >= 30) {
		MENU_COUNTER = 1;
	}
}

// We're passed a UL
function onHideCheckMenu() {
	return !$(this).parent().is('.LOCKED');
}

// We're passed a LI
function onClickMenu() {
	$(this).toggleClass('LOCKED');
	return true;
}



$(document).ready(function() {
	$("#primNavBox li.firstLevel").bind("mouseover", function(){
		$(this).addClass('hover');
	});
	$("#primNavBox li.firstLevel").bind("mouseout", function(){
		$(this).removeClass('hover');
	});
	
	//Etagenpläne
	$("ul.tabs").tabs("div.panes > div");

/*
	$(".overlaybutton").overlay({ 
		expose: { 
			color: '#616161', 
			opacity: 0.7, 
			closeSpeed: 1000
		} 
	});
*/
	$(".overlaybutton").overlay();
	$(".overlayimageStadtzentrum").overlay();
	
	$(".tx-ttaddress-pi1 div.vcard-mieter:even").css('margin', '0 20px 20px 0');
	$(".tx-ttaddress-pi1 div.vcard-mieter:odd").css('margin', '0 0 20px 0');
	
	//Bildgalerie
	var imgGallery = $("#triggers a").size(); 
	if (imgGallery) {
		$("#triggers a").overlay({ 
			target: '#gallery', 
		}).gallery({
			speed: 800,
			template: '<strong>${title}</strong> <span>Bild ${index} von ${total}</span>'
		});
	}

	/* Logo Tickerleiste*/
	$("#viewer").removeClass("js-disabled");
	$("<div>").attr("id", "container").css({ position:"absolute"}).width($(".wrapper").length * 81).height(50).appendTo("div#viewer");
	$(".wrapper").each(function() {
		$(this).appendTo("div#container");
	});
	var duration = $(".wrapper").length * 2000;
	var speed = (parseInt($("div#container").width()) + parseInt($("div#viewer").width())) / duration;
	var direction = "rtl";
	var animator = function(el, time, dir) {
	 
			el.removeClass("ltr").addClass("rtl");

			el.animate({ left:"-" + el.width() + "px" }, time, "linear", function() {

				$(this).css({ left:$("div#imageScroller").width(), right:"" });

				animator($(this), duration, "rtl");
				
				($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;			
								
			});
	}
	animator($("div#container"), duration, direction);		
	
	
});
