$(document).ready(function()
{
	$('.listen_container').each(function()
		{
			if($(this).find('input[name="nettokaltmiete"]').val() != '')
			{
				$(this).find('td').each(function()
				{
					if($(this).html() == '<strong>Kaltmiete</strong>')
					{
						$(this).parent().remove();
					}
				});
			}
		});
	
	$('.interessent tr td').each(function()
		{
			if ($.trim($(this).html()) == '')
				{
					$(this).parent('tr').remove();  
				}
		});
	
	$('.interessent tr td span.ausgefuellt').each(function()
		{
			if ($.trim($(this).html()) == '')
				{
					$(this).parent('td').parent('tr').remove();  
				}
		});
	
	$('#details_details').each(function()
		{
			if($(this).find('input[name="nettokaltmiete"]').val() != '')
			{
				$(this).find('td').each(function()
				{
					if($(this).html() == '<strong>Kaltmiete</strong>')
					{
						$(this).parent().remove();
					}
				});
			}
		});
	
	$('.maklerergebnis_right table tr td').each(function()
	{
		if ($.trim($(this).html()) == '')
		{
			$(this).parent('tr').remove();  
		}
	})
	
	$('h3.bemerkung').each(function()
	{
		if ($.trim($(this).html()) != '')
		{
			$(this).show();
			$(this).next('h3.standard_bemerkung').hide();
		}
	})


	$('#startseite ul:first').attr('id', 'nav');
	$('#startseite #nav li:last').addClass('none-border');
	$('.infobox').each(function()
	{
		$(this).find('ul:first').addClass('images');
		$(this).find('ul.images li:last').addClass('none-margin');
	});
	$('.infobox ul.laender').removeClass('images');
	
	$('.veranstaltung').each(function() {
		$(this).find('div:first').addClass('veranstaltung_div');
	});

	$('#standard_container ul:first').attr('id', 'nav_v');
	$('#standard_container div:eq(1)').addClass('topobjekt');

	$('.konditionen tr td:even').addClass('konditionen_links');
	$('.interessent tr:even').addClass('grey');
	
	$('.partner tr td:even').addClass('partner_links');
	$('.listen_details').each(function()
	{
		$(this).find('table tr:even').addClass('listen_zeile');
		$(this).find('table tr td:even').addClass('listen_detail_zelle');
	});
	
	$('#intern p input:last').addClass('button');
	$('#intern p:last').addClass('none-margin');
	$('#content-contact form .tablerow:last').addClass('none-margin');
	$('.jumpbox > a:eq(1)').addClass('previous_site');
	$('.jumpbox > a:eq(2)').addClass('next_site');
	
	$('.jumpbox_bottom > a:eq(1)').addClass('previous_site');
	$('.jumpbox_bottom > a:eq(2)').addClass('next_site');
	
	$('#gallery > div:eq(0)').addClass('div_why');
	$('#gallery div > div:eq(0)').addClass('big_pic');
	$('#gallery div > ul:eq(0)').addClass('thumbs');
	
	$('#details_details table:first').addClass('details_table_1');
	$('#details_details table:eq(1)').addClass('details_table_2');
	$('#details_details table').each(function() {
		$(this).find('tr:even').addClass('listen_zeile');
	});
	
	//
	
	$('#objektbeschreibung li:first').addClass('no-border-left');
	$('#objektbeschreibung li:last').addClass('no-border-right last_li');
	
	$('#website-search p:first').addClass('treffer');
	
	$('.maklerergebnis_left').each(function()
	{
		if (jQuery.trim($(this).html()) == '') 
			$(this).addClass('kein_makler');
	});
	//
	
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).show(); //Fade in the active ID content
		return false;
	});
	
	//
	
	$('.maklerergebnis').each(function()
	{
		$(this).find('input').each(function()
		{
			var this_url = $(this).val();

			if(this_url != '')
			{
				var this_name = $(this).attr('name');
				var this_class = $(this).attr('class');
				$(this).parent('form').parent('.maklerergebnis').find('.maklerergebnis_social_media').append('<a href="' + this_url + '" class="' + this_class + '" target="_blank">' + this_name + '</a>');
			}
		});
	});
	
	//
	
	$('input[type="text"]').each(function()
	{
		$(this).focus(function()
		{
			if($(this).val() == $(this).attr('defaultValue')) 
			{
				$(this).val(''); 
			}
		});   
		$(this).blur(function()
		{
			if($(this).val() == '') 
			{
				$(this).val($(this).attr('defaultValue'));
			}
		});  
	}); 
	
	//
	
	$('form').submit(function()
	{
		$('input[type="text"]').each(function()
		{
			if($(this).val() == $(this).attr('defaultValue'))
			{
				$(this).val('');
			}
		});
	});
	
	// Karte

	var url = document.URL;
	var bundesland = url.split('f[2480-18]=');
	bundesland = bundesland[1];

	if(bundesland != undefined)
	{
		var b_land = bundesland.replace('%FC','ue');
		$('.map-bundesland').addClass(b_land.toLowerCase());
		$('.standorte span').html(bundesland.replace('%FC','ü'));
	}
	
	$('.map-bundesland').each(function()
	{
		if($(this).attr('class') == 'map-bundesland niedersachsen')
		{
			$(this).append('<a href="standort.xhtml?f[2480-104]=Bremen" style="position: absolute; top: 114px; left: 172px;"><img src="images/karte/bremen.jpg" height="54" width="89" border="0" /></a>');	
		}
		if($(this).attr('class') == 'map-bundesland brandenbrug')
		{
			$(this).append('<a href="standort.xhtml?f[2480-104]=Berlin" style="position: absolute; left:369px; top: 198px;"><img src="images/karte/berlin.jpg" height="76" width="94" /></a>');	
		}
	});
	
	$('.map-bundesland ul li').each(function()
	{
		if($(this).find('img').attr('alt') == 'Dortmund')
		{
			$(this).find('a').attr('href','dortmund.xhtml');
		}
	});

	$('.map area').each(function()
	{
		$(this).mouseenter(function()
		{
			if($(this).attr('alt') != '')
			{
				var bundesland_map = $(this).attr('alt');
				$('.map img').attr('src','images/karte/amarc21-karte-' + bundesland_map + '.jpg');
			}
		}).mouseleave(function()
		{
			$('.map img').attr('src','images/karte/amarc21-karte.jpg');
		});
	});
	
		//
	
		var mylist = $('.map-bundesland ul');
		var listitems = mylist.children('li').get();
		listitems.sort(function(a, b)
		{
		   var compA = $(a).find('img').attr('alt').toUpperCase();
		   var compB = $(b).find('img').attr('alt').toUpperCase();
		   return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
		});
		$.each(listitems, function(idx, itm) { mylist.append(itm); });
		
		//
		
		$('.map-bundesland a:last').addClass('last');
		
		//
		
		$('.map-bundesland a').each(function()
		{
			var standort_text = $(this).find('img').attr('alt');
			var standort_link = $(this).attr('href');
			if($(this).hasClass('last'))
			{
				$('.standorte').append('<a href="' + standort_link + '">' + standort_text + '</a>');	
			}
			else
			{
				$('.standorte').append('<a href="' + standort_link + '">' + standort_text + '</a> - ');
			}
		});
		
		//
	
		$('.map-bundesland ul a').mouseenter(function()
		{
			var standort_text = $(this).find('img').attr('alt');
			$(this).before().append('<span>' + standort_text + '</span>');
			$(this).find('img').attr('src','images/karte/point-active.jpg');
			$('.standorte a:contains("' + standort_text + '")').css('text-decoration','underline').css('font-style','italic');
		}).mouseleave(function()
		{
			$(this).find('span').remove();
			$(this).find('img').attr('src','images/karte/point.jpg');
			$('.standorte a').removeAttr('style');
		});
		
		//
		
		$('.standorte a').mouseenter(function()
		{
			var standort_text = $(this).text();
			$('.map-bundesland ul a').each(function()
			{
				if($(this).find('img').attr('alt') == standort_text)
				{
					$(this).append('<span>' + standort_text + '</span>');
					$(this).find('img').attr('src','images/karte/point-active.jpg');		
				}
			});
		}).mouseleave(function()
		{
			var standort_text = $(this).text();
			$('.map-bundesland ul a').each(function()
			{
				if($(this).find('img').attr('alt') == standort_text)
				{
					$(this).find('span').remove();
					$(this).find('img').attr('src','images/karte/point.jpg');
				}
			});
		});
	
	//
	
	$('#immobiliensuche select[name="f[2480-225]"]').each(function()
	{
		$(this).find('option[value="DEU"]').attr('selected','selected');	   
	});
	
	$('#immobiliensuche').submit(function()
	{
		if($('#searchCity').val() != '')
		{
			$('#searchState').val('');
		}
	});
	
	// Footer
	
	$('.footer-standorte').each(function()
	{
		
		var mylist = $('.footer-standorte');
		var listitems = mylist.children('li').get();
		listitems.sort(function(a, b)
		{
		   var compA = $(a).find('a').text().toUpperCase();
		   var compB = $(b).find('a').text().toUpperCase();
		   return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
		});
		$.each(listitems, function(idx, itm) { mylist.append(itm); });
		
		for(y = 0; y <= 5; y++)
		{
			$(this).append('<ul id="liste-' + y + '"></ul>');

			for(x = 0; x <= 12; x++)
			{
				$(this).find('> li:first').appendTo('#liste-' + y);
			}

		}
	});

});

$(window).load(function() {
    $('#slider').nivoSlider({
        effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
        slices:1, // For slice animations
        boxCols: 0, // For box animations
        boxRows: 0, // For box animations
        animSpeed:2000, // Slide transition speed
        pauseTime:9000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:false, // Next & Prev navigation
        directionNavHide:false, // Only show on hover
        controlNav:false, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0.8, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
    });
});
