$(document).ready(function() {

	bName = navigator.appName;
	bVer = parseInt(navigator.appVersion);
	dom = (document.getElementById)? true:false;
	ns4 = (document.layers)? true:false;
	ns5 = (bName == "Netscape" && bVer > 4)? true:false;

	if (dom) { show = "visible"; hide = "hidden"; }
	if (ns4) { show = "show"; hide = "hide"; }

	topicWidths = new Array(33,38,44,28,67,32,32,42,30,41);
	contentWidth = 780;
	menuHspace = 14;
	topicOffset = Math.floor(menuHspace/2);

	myWidth = document.body.clientWidth;
	mainXpos = Math.floor(myWidth/2-contentWidth/2)-12;
	if (mainXpos < 0) mainXpos = 0;

	$('#main').css('left',mainXpos+'px');
	$('#main').css('width',contentWidth+'px');
	$('#hider').css('left',mainXpos+'px');

	positioner();

	$('#hider').hover(function() {
		displayMenu('none',hide);
	})
	$('a#note').before('<div class="note"></div>');
	$('div#topics div a').focus(function() {$(this).blur()})
	$('div#autoren ul.alphabet li a').click(function() {
		var href = $(this).attr('href');
		$('html,body').animate({scrollTop: $('[name='+href.substr(href.length-1)+']').offset().top},'slow');
	})
	$('a#urbanpland-popup').click(function() {
		urbanpland=window.open($(this).attr('href'),'urban','width=480,height=360,scrollbars=0');urbanpland.focus();return false;
	})
	if ($('div.ebook_haendler').length == 1) {
		$('div.ebook_haendler p').hide();
		$('div.ebook_haendler a').before('&raquo; ');
		$('div.ebook_haendler').hover(function() {
			$('div.ebook_haendler p').fadeToggle(300);
		})
	}
	if ($('div.ebook_cover_k').length > 0) {
		$('div.ebook_cover_k p').hide();
		$('div.ebook_cover_k a').prepend('&raquo; ');
		$('div.ebook_cover_k a').attr('target','_blank');
		$('div.ebook_cover_k').click(function() {
			$(this).children('p').fadeToggle(300);
		})
	}
	if ($('a.book2look_img').length == 1) {
		var txt_b2l = $('h1:first').html().search(/kalender/i) == -1 ? 'Blick ins Buch' : 'Innenansicht';
		$('a.book2look_img').before('<a href="'+$('a.book2look_img').attr('href')+'" class="linkbox book2look shadow">'+txt_b2l+' &raquo;</a>')
		$('a.book2look, a.book2look_img').live('click',function() {
			window.open($(this).attr('href'),'book2look','width=1002,height=752,scrollbars=0');
			return false;
		})
	}
	$('form').submit(function() {
		var foc = false;
		$(':input',this).each(function() {
			if ($(this).is(':visible') && $(this).attr('alt') == 'pflicht') {
				var err = false;
				if ($(this).val() == false) { err = true }
				if ($(this).attr('id') == 'geburtsdatum_d') {
					if ($('input#geburtsdatum_d').val().match(/^\d+$/) == null || $('input#geburtsdatum_m').val().match(/^\d+$/) == null || $('input#geburtsdatum_y').val().match(/^\d+$/) == null) {
					}
				}
				var txt = $('#txt_'+$(this).attr('id'));
				if (err == true) { if (foc == false) { this.focus(); foc = true } txt.addClass('error'); $(this).addClass('error'); }
				else { txt.removeClass('error'); $(this).removeClass('error'); }
			}
		})
		return foc == false ? true : false;
	});
	$('form#adresse input').blur(function() {
		var txt = $('#txt_'+$(this).attr('id'));
		if ($(this).val() == '') {
			if ($(this).attr('alt') == 'pflicht') {
				$(this).addClass('error');
				txt.addClass('error');
			}
		}
		else {
			$(this).removeClass('error');
			txt.removeClass('error');
		}
	});
	if (window.location.href.indexOf('multimedia') != -1) {
		var i=0;
		$('a.audio').each(function() {
			i++;
			$(this).after('<div id="audio'+i+'"></div><br>'+$(this).html().replace(/ <span>\(.*?\)<\/span>/,'')+'');
			AudioPlayer.embed('audio'+i, {soundFile: $(this).attr('href')});
			$(this).remove();
		});
		/*$('a.audio').click(function() {
			i++;
			$(this).after('<div id="audio'+i+'"></div><br>'+$(this).html().replace(/ <span>\(.*?\)<\/span>/,'')+'');
			AudioPlayer.embed('audio'+i, {soundFile: $(this).attr('href')});
			$(this).remove();
			return false;
		});
		var myAudio = document.createElement('audio'); // http://html5doctor.com/native-audio-in-the-browser/
		var canPlayMp3 = !!myAudio.canPlayType && '' != myAudio.canPlayType('audio/mpeg');
		if (myAudio.canPlayType && canPlayMp3) {
			$('a.audio').click(function() {
				$(this).before('<audio src="'+$(this).attr('href')+'" controls preload="0" autobuffer></audio><br>');
				return false;
			});
		}*/
	}
})


window.onload = init;
window.onresize = positioner;

var loaded = 0;

var galerie_kalender_sel = 1;
function galerie_kalender(i,anzahl,pfad) {
	if (document.images) {
		galerie_kalender_sel+=i;
		if (galerie_kalender_sel<1) galerie_kalender_sel=1;
		if (galerie_kalender_sel>anzahl) galerie_kalender_sel=anzahl;
		imgL=galerie_kalender_sel>1?"backwards":"transp";
		imgR=galerie_kalender_sel>anzahl-1?"transp":"forward";
		document.images.bw.src="/img/div/"+imgL+".gif";
		document.images.fw.src="/img/div/"+imgR+".gif";
		document.images.gal.src=pfad+galerie_kalender_sel+".jpg";
	}
}

function init() {
	loaded = 1;

	jsReady = true; // nonverblaster
}

 
function getRef(divID) {
	if (dom) return document.getElementById(divID).style
	if (ns4) return document[divID]
}
function gid(id) {
	return document.getElementById(id);
}

function win(url,name,features) {
	name=window.open(url,name,features)
}

function widthGetter() {
	if (dom && !ns5) myWidth = document.body.clientWidth;
	if (ns4 || ns5)  myWidth = self.innerWidth;
	mainXpos = Math.floor(myWidth/2-contentWidth/2)-12;
	if (mainXpos < 0) mainXpos = 0;
	return mainXpos;
}

function positioner() {
	if (ns4) { window.location.href=window.location.href; }
	else {
		widthGetter();
		$('#main').css('left',mainXpos);


		var c=0;
		$('div#topics img').each(function() {
			var width = parseInt($(this).css('width').replace('px',''));
			topicXpos = mainXpos+topicOffset;
			dropDownXpos = mainXpos-15;
			$('#menu'+c).css('left',dropDownXpos+'px');
			$('#topic'+c).css('left',topicXpos+'px');
			$('#topic'+c).css('width',width+'px');
		
			mainXpos += width+menuHspace;
		
			c++;
		})

	}
}

function displayMenu(which,cond) {
	$('div#menu_main div').hide();
	if (which != "none") {
		$("div#menu"+which).show();
	}
}

function popup() {
	prag=window.open("/content/popup/index.html","Prag","width=180,height=250,scrollbars=0");
	prag.focus();
}

function tranq(f,u) {
	var m = new Array("&#105;","&#116;","&#111;","&#109;","&#97;","&#108;");
	document.write("<a href="+m[3]+m[4]+m[0]+m[5]+m[1]+m[2]+"&#58;"+u+"&#64;"+f+" class=\"maroon\">"+u+"&#64;"+f+"</a>");
}



// nonverblaster
var jsReady = false;
var flashMovie = "";

function isReady(){
	return(jsReady)
}

function getFlashMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}
function sendToNonverBlaster(value) {
	getFlashMovie(flashMovie).sendToActionScript(value);
}

function registerForJavaScriptCommunication(_flashMovie){
	flashMovie = _flashMovie;
}
