/** softscroll in newsletter  */
if(document.location.href.search(/Newsletter/) != -1)
{
	$(document).ready(function() { 
		$('a[href^="#"]').click(function() {
			var theName = decodeURI(this.href.split('#')[1]);
			inhaltRechts.scrollTo( $($('a[name='+theName+']')[0].parentNode),{duration:1500} ); /*offset: {left: 0, top: FFhack } ,easing:'easout'*/
			return false;
		});
	});
}

var bildRechtsHtml;
var inhaltRechtsHtml;

var inhaltRechts;
var bildRechts;
var popUpQuery;
var load;
/** Ajax initialisieren */
$(document).ready(function() {
	bildRechtsHtml = $('#bildRechts').html();
	inhaltRechtsHtml = $('#inhaltRechts').html();
	$('a.Ajax').click( LadeAjax );
	
	inhaltRechts = $('#inhaltRechts');
	bildRechts = $('#bildRechts');
	popUpQuery = $('#lLayer');
	load = $('#lLoad');
});

/**
 * Laden der Ajax PopUps
 */
function LadeAjax() 
{
	//var tempArr = this.href.split('/agentur/');
	//var pfad = tempArr[tempArr.length-1];
	var siteaccess = this.href.replace(location.protocol+'//'+location.hostname, '');
	var pfad = siteaccess.replace(/^\/[^\/]+/, '');
	siteaccess = siteaccess.replace(pfad, '');
	load[0].style.display = 'block';
	
	$.ajax({
		type: "GET",
		url: siteaccess+"/arsajax/overview/?pfad="+pfad,
		success: function(message) {
			var arr = message.split('||||||||||||||||');
			if(arr.length > 1)
			{
				inhaltRechts[0].style.backgroundColor = '#ffffff';
				var load_img = new Image();
				load_img.src = arr[1];
				popUpQuery.fadeTo(0, 0);
				bildRechts.fadeTo(500, 0);				
				inhaltRechts.fadeTo(500, 0, function() {
					load[0].style.display = 'none';
					var htmlInhalt = arr[0];
					var bildSrc = arr[1];
					var popUpContainer = popUpQuery[0];
					popUpContainer.innerHTML = htmlInhalt;
					popUpContainer.style.backgroundImage = 'url('+bildSrc+')';
					popUpContainer.style.zIndex = 1000;
					inhaltRechts[0].style.zIndex = 1;
					popUpQuery.fadeTo(500, 1);
					
					$('#lLayer a.Ajax').click( AjaxInAjax ); //mehrfaches ajax aktivieren
				});
			}
		}
	});
	
	return false;
}

function AjaxInAjax()
{
	//debugger;
	//var tempArr = this.href.split('/agentur/');
	//var pfad = tempArr[tempArr.length-1];
	var siteaccess = this.href.replace(location.protocol+'//'+location.hostname, '');
	var pfad = siteaccess.replace(/^\/[^\/]+/, '');
	siteaccess = siteaccess.replace(pfad, '');
	load[0].style.display = 'block';
	
	$.ajax({
		type: "GET",
		url: siteaccess+"/arsajax/overview/?pfad="+pfad,
		success: function(message) {
			var arr = message.split('||||||||||||||||');
			if(arr.length > 1)
			{
				var popUpContainer = popUpQuery[0];
				inhaltRechts[0].style.backgroundColor = '#ffffff';
				var load_img = new Image();
				load_img.src = arr[1];
				$(popUpContainer).fadeTo(0, 0);
				//bildRechts.fadeTo(500, 0);				
				inhaltRechts.fadeTo(500, 0, function() {
					load[0].style.display = 'none';
					var htmlInhalt = arr[0];
					var bildSrc = arr[1];
					
					popUpContainer.innerHTML = htmlInhalt;
					popUpContainer.style.backgroundImage = 'url('+bildSrc+')';
					//popUpContainer.style.zIndex = 1000;
					//inhaltRechts[0].style.zIndex = 1;
					popUpQuery.fadeTo(500, 1);
				});
				
				$('#lLayer a.Ajax').click( AjaxInAjax );
			}
		}
	});
	return false;
}

/** Ajax PopUp ausblenden*/
function Schliessen()
{
	if($.browser.msie)
		inhaltRechts[0].style.backgroundColor = '#ffffff';
	popUpQuery.fadeTo(500, 0, function() {	
		popUpQuery[0].style.zIndex = 1;
		inhaltRechts[0].style.zIndex = 1000;
		inhaltRechts.fadeTo(500, 1);
		bildRechts.fadeTo(500, 1, function() {
			//alert('x');
			//inhaltRechts[0].style.backgroundColor = 'transparent';
		});
	});

	return false;
}

/** Kontaktformular prüfen */
function chkFormular()
{
	var err = new Array();
	var firstElement= new Array();
 	if(document.kontakt.firma.value == "")  
 	{
		err.push("Bitte Ihre Firma eingeben!");
		firstElement.push(document.kontakt.firma);
  	}
 	if(document.kontakt.vorname.value == "")  
 	{
   		err.push("Bitte Ihren Vornamen eingeben!");
   		firstElement.push(document.kontakt.vorname);
  	}  
 	if(document.kontakt.nachname.value == "")  
 	{
   		err.push("Bitte Ihren Nachnamen eingeben!");
   		firstElement.push(document.kontakt.nachname);
  	}
	if(document.kontakt.strasse.value == "") 
	{
   		err.push("Bitte Ihre Straße eingeben!");
   		firstElement.push(document.kontakt.strasse);
	}
	if(document.kontakt.plzort.value == "") 
	{
		err.push("Bitte Ihren Wohnort eingeben!");
		firstElement.push(document.kontakt.plzort);
	}
	if(document.kontakt.telefon.value == "") 
	{
		err.push("Bitte Ihre Telefonnummer eingeben!");
		firstElement.push(document.kontakt.telefon);
	}
	if(document.kontakt.email.value == "") 
	{
		err.push("Bitte Ihre eMail-Adresse eingeben!");
		firstElement.push(document.kontakt.email);
	}
	else
	{
	  	var treffer = document.kontakt.email.value.search(/^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
	    ///\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/);
	  	///^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
  		if (treffer == -1) 
  		{
			err.push("Bitte prüfen Sie Ihre eMail-Adresse.");
			firstElement.push(document.kontakt.email);
  		} 
	}
	if(document.kontakt.anfrage.value == "") 
	{
		err.push("Bitte Ihre Anfrage eingeben!");
		firstElement.push(document.kontakt.anfrage);
  	}
  	
  	if(err.length > 0)
  	{
  		alert('Bitte prüfen Sie folgende Felder:\n'+err.join('\n'));
  		firstElement[0].focus();
  		return false;
  	}
  	return true;
}

var container;
/** Auflösung anpassen */
$(document).ready(function() { 
	container = $('#container');
	var originalWidth = container[0].style.width;
	window.onresize = function () {
		if($(document).width() < 1024)
		{
			container[0].style.width = '960px';
		}
		else
		{
			container[0].style.width =originalWidth;
		}
	};
	window.onresize();
});