var color = 'grey';
var state_default = '../gif/map/map_grey_0.gif';
var pics = new Array();

for (var i = 0; i <= 16; i++) {
	pics[i] = new Image();
	pics[i].src = '../gif/map/map_grey_'+i+'.gif';
}

function on(state_id, color) {
	if(!color) {
		color = 'grey';
	}
	if(!state_id || state_id == '0' || state_default == '../gif/map/map_blue_' + state_id + '.gif') {
		document.getElementById('image_map').src = state_default;
	}
	else {
		document.getElementById('image_map').src = '../gif/map/map_' + color + '_' + state_id + '.gif';
	}
}


function getBaseURL() {
    var url = location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));
    return baseURL + "/";
}

function openGMap(address) {
	
	new_window = window.open(getBaseURL() + 'maps/?address=' + encodeURI(address), 'Popup', 'width=700,height=500,status=no,scrollbars=no,resizable=no');
}

function openNW(url) {
	new_window = window.open(getBaseURL() + 'nw/' + encodeURI(url), 'Popup', 'width=750,height=650,status=no,scrollbars=yes,resizable=no');
}

$(document).ready(function(){
	var wert = $("input[name=search_term]").val();
	$catHead = $("div#catHead");
	$catHeadDefault = $("div#catHead").height();
	$catContext = $("span#catContext");
	
	$(document).click(function(e) {
		if(!$(e.target).hasClass('language_menue')) {
			$('#language_menue').removeClass('active');
			$('.language_menue').css({'display': 'none'});
		}
		if(!$(e.target).hasClass('overlay')) {
			$('#html5').removeClass('active');
			$('.simple_overlay').css({'display': 'none'});
		}
	});
	
	//effect for the Browser to disable the dotted lines around a link
	$("a, input[type=submit], button").focus(function(){
	  $(this).blur();
	});

	$('a.new-window').click(function(){
		window.open(this.href);
		return false;
	});
	$('a.new-window').live('click', function(){
		window.open(this.href);
		return false;
	});
	
	$("#footer a").css({color: "#666"}).hover(function() {
		$(this).stop().animate({ color: "#1C1C1C"}, 200);
	},function() {
		$(this).stop().animate({ color: "#666"}, 200);
	});
	
	$("ul.submenue li a:not(.select)").css({color: "#1C1C1C"}).hover(function() {
		$(this).stop().animate({ color: "#FFF"}, 200);
	},function() {
		$(this).stop().animate({ color: "#1C1C1C"}, 200);
	});
		
	$("ul.article li a").css({color: "#666"}).hover(function() {
		$(this).stop().animate({ color: "#1C1C1C"}, 200);
	},function() {
		$(this).stop().animate({ color: "#666"}, 200);
	});
	
	$('a.toplink').click(function() {
		$('html,body').animate({scrollTop : 0},'slow');
   	});
	
    $("a.readmore").click(function(e) {
		$(this).hide();
		$('a.readless').show();
		$($catHead).stop().animate({"height": $catContext.height()})
		return false;
	});
	
	 $("a.readless").click(function(e) {
		$(this).hide();
		$('a.readmore').show();
		$($catHead).stop().animate({"height": $catHeadDefault})
		return false;
	});
	
	$(".trigger_container").hide(); 
	
	$("a.trigger").click(function(){
		$('.trigger_container').slideToggle();
		return false;
	});
	
	$('#search').submit(function(e) {
		if($("input[name=search_term]").val().length < 3) {
			$('#search').find("em").css({'display': 'block'});
			return false;
		} else {
			$('#search').find("em").css({'display': 'none'});
		}
	});
	$('#showSubmenue').click(function(e) {
		if($(this).hasClass('active')) {
			$(this).removeClass('active');
		} else {
			$(this).addClass('active');
		}
 		$('.subMenue').slideToggle();
		return false;
	});
	
	
	$('#slidebottom, #togglebottom').click(function(e) {
		if($(this).hasClass('active')) {
			$(this).removeClass('active');
		} else {
			$(this).addClass('active');
		}
 		$('.togglebottom').slideToggle();
		return false;
	});
	
	$('#language_menue').click(function() {
		if($(this).hasClass('active')) {
			$(this).removeClass('active');
			$('.language_menue').css({'display': 'none'});
		} else {
			$(this).addClass('active');
			$('.language_menue').css({'display': 'block'});
		}
		
		return false;
	});
	
	$("input[name=search_term], input[name=search_locate], textarea[name=message], input[name=date_from], input[name=date_to]").each(function(e){
	var wert = $(this).val();
	$(this)
		.focusin(function(){
			if ($(this).val() == wert) {
				$(this).val("");
			}
		})
	});

	$('a.pdf, a.mail').bind('click', function(){
		alert('Sorry, aber diese Funktion wird zur Zeit überarbeitet. Bitte versuchen Sie es später noch einmal.\n Vielen Dank für Ihr Verständnis');
		return false;
	});
	
	$('a.print').click(function(){
		new_window = window.open(this.href, 'Popup', 'width=710,height=650,status=no,scrollbars=yes,resizable=no');
		return false;
	});
	
	$(".default").click(function(e) {          
		e.preventDefault();
		$(".lang").toggle();
		$(".default").toggleClass("active");
	});
	
	$(".lang").mouseup(function() {
		$(".icon_menu").removeClass('mouseover');
		return false;
	});
	
	$(document).mouseup(function(e) {
		if($(e.target).parent(".default").length==0) {
			$(".default").removeClass("active");
			$(".lang").hide();
		}
	});
	
	$(this).find("span.thumb").css({'opacity' : '0.5'});
	$(".pic, .pic_bigsize").hover(function() {
		$(this).find("span.thumb").stop().fadeTo('normal', 1.5 , function() {
		});
	} , function() {
		$(this).find("span.thumb").stop().fadeTo('normal', 0.5).show();
	});
			
	
	$("#toggle a").click(function (e) {
		e.preventDefault();
		$("#toggle a").toggle();
	});
	
	$('.table_submit').click(function(e){
		transmit();
		return false;
	});
	
	$('select[name=table_length]').change(function() {
	  $('#table_form, #form').submit();
	});
	
	$('#list tbody tr').click(function(event) {
		$('#list tbody tr').each(function (){
			$(this).removeClass('row_selected');
		});
		$(this).toggleClass('row_selected');
		$(event.target.parentNode).find("input[type=radio]").attr('checked', 'checked');
		$('input.table_submit').removeAttr('disabled');
	});
	
	$('#form table tbody tr').bind('dblclick', function () {
		transmit();
	});
	
	$('#list tbody tr td a.details').bind('dblclick', function () {
		return false;
	});
	
	$("#list tbody tr td input[type=radio]").each( function () {
		$(this).removeAttr('checked', 'checked');
	} );
	
	$("#list tbody tr td input[type=radio]").click( function (event) {
		$('#list tbody tr').each(function (){
			$(this).removeClass('row_selected');
		});
		$(event.target.parentNode.parentNode).toggleClass('row_selected');
		$('input.table_submit').removeAttr('disabled');
	});
	
	$('tr td a.details').live( 'click', function () {
		var Tr = this.parentNode;
		$(this).removeClass('open');
		$(this).addClass('close');
		$(Tr.parentNode).next('tr').show();
	});
			
	$('td a.close').live( 'click', function () {
		var Tr = this.parentNode;
		$(this).removeClass('close');
		$(this).addClass('open');
		$(Tr.parentNode).next('tr').hide();
	});

	$("select#participant").change(function(){
		if($(this).val() == '12+') {
			$('label#test').show();
		} else {
			$('input#participant_num').val('');
			$('label#test').hide();
		}
	});
	
	$('input#participant_num').focusout(function() {
		numRe = /^-?[0-9]*(\.[0-9]+)?$/;
		if(parseInt($(this).val()) < 13 || parseInt($(this).val()) > 25 || !numRe.exec($(this).val())) {
			$(this).val('');
			$(this).next('em').css({display: 'block'});
		} else {
			$(this).next('em').css({display: 'none'});
		}
	});
	
	$('input[type="checkbox"], input[type="radio"]').checkbox({cls:'jquery-safari-checkbox'});
	
	$("ul.vertical").tabs("div.panes > div");
	$("ul.horizontal").tabs("div.pane > div");
});


