/*
 * jQuery replaceText - v1.1 - 11/21/2009
 * http://benalman.com/projects/jquery-replacetext-plugin/
 * 
 * Copyright (c) 2009 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */

(function($){$.fn.replaceText=function(b,a,c){return this.each(function(){var f=this.firstChild,g,e,d=[];if(f){do{if(f.nodeType===3){g=f.nodeValue;e=g.replace(b,a);if(e!==g){if(!c&&/</.test(e)){$(f).before(e);d.push(f)}else{f.nodeValue=e}}}}while(f=f.nextSibling)}d.length&&$(d).remove()})}})(jQuery);

$(window).load(function()
{	

	//

	$('#slider, #slider_tagomago, #slider_mallorca, #slider_interior').nivoSlider(
	{
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		slices:1,
		animSpeed:2500,
		pauseTime:8000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:false, //1,2,3...
		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:false, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.0, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
	
	//
	
	$('#slider_regionen').nivoSlider(
	{
		effect:'fold', //Specify sets like: 'fold,fade,sliceDown'
		slices:3,
		animSpeed:2500,
		pauseTime:8000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:false, //1,2,3...
		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:false, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.0, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
	
});

// Slidetoggle

$(function() 
{
	$('.toggler').click(function()
	{
		$(this).parents(".teamMemberRight").children('.toggleMe').slideToggle('fast');
		return false;
	});
});

$(document).ready(function()
{
	
	//
	
	$('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'));
			}
		});  
	}); 
	
	//
	
	$('.gewerbe .jumpbox span a:gt(1)').remove();
	
	$('.gewerbe .jumpbox span').replaceText( /\b|...||\b/gi, '' );
	
	
	
	//
	
	$('.quicksearch form, #detailsuche').submit(function()
	{
		$('input[type="text"]').each(function()
		{
			if($(this).val() == $(this).attr('defaultValue'))
			{
				$(this).val('');
			}
		});
	});

	//
	
	if ($.trim($('.google_maps, .freitexte').html()) == '')
	{
		$(this).css('display','none');
	}
	
	//
	
	if ($.trim($('.beschreibung_ausstattung table').html()) == '')
	{
		$('.beschreibung_ausstattung').css('display','none');
	}
	
	//
	
	/*
	
	if ($.trim($('.angebotspreis span span').html()) == '')
	{
		$('.preisprovision').css('display','none');
	}
	
	*/

	//
	
	$('.menu_hor_2 ul').attr('id', 'nav');
	
	//
	
	$('.languages ul li a:last, .menu_hor_1 ul li a:last, .languages ul li:last').addClass('no-border-right');
	$('.menu_hor_1 ul li a:first').addClass('no-border-left');
	$('.menu_hor_1 ul li a:last').addClass('no-padding-right');
	$('.languages ul li:eq(2)').remove();
	
	//
	
	if ($('.title ul li').size()>=3)
	{
		$('.title ul li:eq(0), .title ul li:eq(2)').addClass('displaynone');
	}
	
	//
	
	$('.kaufen_mieten_links ul li a:last').addClass('red');
	
	//
	
	$('.beschreibung_ausstattung table tr td span').text('');
	
	//
	
	$('#details .single_detail').each(function()
	{
		if ($.trim($(this).html()) == '')
		{
			$(this).remove();  
		}
	});
	
	//
	
	$('.right_detail table, #details table').each(function()
	{
		$(this).find('tr:even').addClass('list_tr_color');
	});
	
	//
	
	$('.region_bilder .regionen:last, #gallery div ul li:eq(3), #gallery div ul li:eq(7), .tagomago_galerie li:last, .interior_galerie li:nth-child(6n)').addClass('no-margin-right');

	//

	$('.jumpbox').each(function()
	{
		$(this).find('a:first').addClass('left');
		$(this).find('a:last').addClass('right');
	});
	
	//
	
	$('#integral_list > li:last').addClass('no-margin-right');
	$('.mini-logos tr td:last').addClass('no-padding-right');
	
	//
	
	$('.menu_hor_2 > ul > li > span a:last').addClass('no-border-right');
	$('.menu_hor_2 > ul > li > span a:first').addClass('no-border-left');
	
	//
	
	$('#footer > ul > li:last').addClass('no-margin-right');
	
	//
	
	$('div.tabs').each(function()
	{
		if ($.trim($(this).html()) == '')
		{
			var id = $(this).attr('id');
			$('a[href="#'+id+'"]').parent().remove();
			$(this).remove();
		}
	});
	
	//
	
	$('.sortierung input:last').hide();
	$('.sortierung select').change(function()
	{
		$(this).parent().submit();
	});

	//
	/*
	
	$('.listen_container').each(function()
	{
		if ($(this).find('.angebotspreis-hidden').val() != 'Kauf' && $(this).find('.angebotspreis-hidden').val() != 'Buy' && $(this).find('.angebotspreis-hidden').val() != 'Venta')
		{
			$(this).find('.provisionsfrei-hidden, .originalpreis').remove();	
		}	
	});
	
	*/
	
	//

	$('.listen_container').each(function()
	{
		if($(this).find('.preis-auf-webseite-hidden').val() == 'Ja')
		{
			$(this).find('.mietprovision').remove();
			$(this).find('.originalpreis').remove();
			$(this).find('.angebotspreis').remove();
			$(this).find('.preis_auf_anfrage-hidden').show();
		}	
		else if($(this).find('.preis-auf-webseite-hidden').val() == 'Yes')
		{
			$(this).find('.mietprovision').remove();
			$(this).find('.originalpreis').remove();
			$(this).find('.angebotspreis').remove();
			$(this).find('.preis_auf_anfrage-hidden').show();	
		}
		else if($(this).find('.preis-auf-webseite-hidden').val() == 'Sí')
		{
			$(this).find('.mietprovision').remove();
			$(this).find('.originalpreis').remove();
			$(this).find('.angebotspreis').remove();
			$(this).find('.preis_auf_anfrage-hidden').show();	
		}
	});
	
	//
	
	$('.listen_container').each(function()
	{
		if($.trim($(this).find('.angebotspreis').html()) == '')
		{
			$(this).find('.angebotspreis').remove();
			$(this).find('.provisionsfrei-hidden').remove();	
			$(this).find('.preis_auf_anfrage-hidden').show();
		}
	});

	//
	
	$('.footer_table td:eq(0)').addClass('first');
	$('.footer_table td:eq(1)').addClass('second');
	$('.footer_table td:eq(2)').addClass('third');
	
	//
	
	$('.quicksearch-insel').change(function()
	{
		if($(this).val() == 'ind_Schl__1978')
		{
			$('.quicksearch-insel-hidden').val('');
		}
		else
		{
			$('.quicksearch-insel-hidden').val('ind_Schl__1978');	
		}
	}).change();
	
	//
	
	$('#details').each(function()
	{
		if($(this).find('.preis-auf-webseite-hidden').val() == 'Ja')
		{
			$(this).find('.mietprovision').remove();
			$(this).find('.angebotspreis').remove();
			$(this).find('.originalpreis').remove();
			$(this).find('.preis_auf_anfrage-hidden-details').show();
		}
		else if($(this).find('.preis-auf-webseite-hidden').val() == 'Yes')
		{
			$(this).find('.mietprovision').remove();
			$(this).find('.angebotspreis').remove();
			$(this).find('.originalpreis').remove();
			$(this).find('.preis_auf_anfrage-hidden-details').show();
		}	
		else if($(this).find('.preis-auf-webseite-hidden').val() == 'Sí')
		{
			$(this).find('.mietprovision').remove();
			$(this).find('.angebotspreis').remove();
			$(this).find('.originalpreis').remove();
			$(this).find('.preis_auf_anfrage-hidden-details').show();
		}	
	});
	
	//
	
	$('#details').each(function()
		{
			$(this).find('.single_detail:even').addClass('detail_color');
		});
	
	//
	
	$('#nav:first > li').each(function()
	{
		if($(this).children('ul').size() > 0)
		{
			$(this).find('span a').each(function()
			{
				if($(this).attr('href') != 'kaufen.xhtml' && $(this).attr('href') != 'mieten.xhtml')
				{
					$(this).css('cursor','default');
					$(this).removeAttr('href');
				}
			});
		}
	});
	
	//
	
	$.fn.lt_ie_six = function()
	{
		$('.ie_six, .ie_six .ie_six_background').height($(document).height());
		$('.ie_six').show();
	}
	$('.ie_six_background').click(function()
	{
		$('.ie_six').fadeOut();	
	});

});
