function preloadImages() {
  var d = document;
	if(d.images) {
		if(!d.p) d.p = new Array();
    var i,j = d.p.length,a=preloadImages.arguments;
    for(i=0; i<a.length; i++)
    if(a[i].indexOf("#") != 0) {
    	d.p[j] = new Image;
    	d.p[j++].src = a[i];
    }
   }
}

preloadImages(
	'images/nav-grafikdesign-o.gif',
	'images/nav-kontakt-o.gif',
	'images/nav-marketing-o.gif',
	'images/nav-profil-o.gif',
	'images/nav-referenzen-o.gif',
	'images/nav-webdesign-o.gif',
	'images/nav-werbemittel-o.gif',
	'images/home-ref-1-o.jpg',
	'images/home-ref-2-o.jpg',
	'images/home-ref-3-o.jpg',
	'images/home-ref-4-o.jpg',
	'images/home-ref-5-o.jpg',
	'images/home-ref-6-o.jpg',
	'images/ft-maps-o.png',
	'images/ft-top-o.gif',
	'images/form-tf-bg-o.png',
	'images/form-ta-bg-o.png',
	'images/form-option-sn.png',
	'images/form-send-o.png'
);

$(document).ready(function(){
	/* MouseOver Effekte */
	$('#nav-gra').mouseover(function(){$(this).attr({src:'images/nav-grafikdesign-o.gif'});});
	$('#nav-gra').mouseout(function(){$(this).attr({src:'images/nav-grafikdesign-n.gif'});});
	$('#nav-web').mouseover(function(){$(this).attr({src:'images/nav-webdesign-o.gif'});});
	$('#nav-web').mouseout(function(){$(this).attr({src:'images/nav-webdesign-n.gif'});});
	$('#nav-wer').mouseover(function(){$(this).attr({src:'images/nav-werbemittel-o.gif'});});
	$('#nav-wer').mouseout(function(){$(this).attr({src:'images/nav-werbemittel-n.gif'});});
	$('#nav-mar').mouseover(function(){$(this).attr({src:'images/nav-marketing-o.gif'});});
	$('#nav-mar').mouseout(function(){$(this).attr({src:'images/nav-marketing-n.gif'});});
	$('#nav-ref').mouseover(function(){$(this).attr({src:'images/nav-referenzen-o.gif'});});
	$('#nav-ref').mouseout(function(){$(this).attr({src:'images/nav-referenzen-n.gif'});});
	$('#nav-pro').mouseover(function(){$(this).attr({src:'images/nav-profil-o.gif'});});
	$('#nav-pro').mouseout(function(){$(this).attr({src:'images/nav-profil-n.gif'});});
	$('#nav-kon').mouseover(function(){$(this).attr({src:'images/nav-kontakt-o.gif'});});
	$('#nav-kon').mouseout(function(){$(this).attr({src:'images/nav-kontakt-n.gif'});});
	$('#home-ref-one').mouseover(function(){$(this).attr({src:'images/home-ref-1-o.jpg'});});
	$('#home-ref-one').mouseout(function(){$(this).attr({src:'images/home-ref-1-n.jpg'});});
	$('#home-ref-two').mouseover(function(){$(this).attr({src:'images/home-ref-2-o.jpg'});});
	$('#home-ref-two').mouseout(function(){$(this).attr({src:'images/home-ref-2-n.jpg'});});
	$('#home-ref-three').mouseover(function(){$(this).attr({src:'images/home-ref-3-o.jpg'});});
	$('#home-ref-three').mouseout(function(){$(this).attr({src:'images/home-ref-3-n.jpg'});});
	$('#home-ref-four').mouseover(function(){$(this).attr({src:'images/home-ref-4-o.jpg'});});
	$('#home-ref-four').mouseout(function(){$(this).attr({src:'images/home-ref-4-n.jpg'});});
	$('#home-ref-five').mouseover(function(){$(this).attr({src:'images/home-ref-5-o.jpg'});});
	$('#home-ref-five').mouseout(function(){$(this).attr({src:'images/home-ref-5-n.jpg'});});
	$('#home-ref-six').mouseover(function(){$(this).attr({src:'images/home-ref-6-o.jpg'});});
	$('#home-ref-six').mouseout(function(){$(this).attr({src:'images/home-ref-6-n.jpg'});});
	$('#img-ft-gm').mouseover(function(){$(this).attr({src:'images/ft-maps-o.png'});});
	$('#img-ft-gm').mouseout(function(){$(this).attr({src:'images/ft-maps-n.png'});});
	$('#img-ft-top').mouseover(function(){$(this).attr({src:'images/ft-top-o.gif'});});
	$('#img-ft-top').mouseout(function(){$(this).attr({src:'images/ft-top-n.gif'});});

	/* MouseOver Effekt Home */
	$('#slogo').mouseover(function(){
		$(this).animate({opacity: 0}, 400);
		$('#shome').animate({opacity: 1.0}, 400);
	});
	$('#slogo').mouseout(function(){
		$('#shome').animate({opacity: 0}, 400);
		$(this).animate({opacity: 1.0}, 400);
	});

	/* Sanftes scrollen zum Seitenbeginn */
	$('a[href*=#]').bind('click', function(event) {
		event.preventDefault();
		var linktarget = $(this).attr('href');
		$('html,body').animate({
			scrollTop: $(linktarget).offset().top
		}, 1000 , function (){location.hash = linktarget;});
	});

	/* Referenzen */
	$('#refzur').mouseover(function(){$(this).css('cursor', 'pointer');});
	$('#refvor').mouseover(function(){$(this).css('cursor', 'pointer');});
	document.ref1w = '700'; document.ref1h = '351'; document.ref1f = '.jpg';
	document.ref2w = '366'; document.ref2h = '314'; document.ref2f = '.png';
	document.ref3w = '700'; document.ref3h = '368'; document.ref3f = '.jpg';
	document.ref4w = '700'; document.ref4h = '472'; document.ref4f = '.jpg';
	document.ref5w = '700'; document.ref5h = '479'; document.ref5f = '.jpg';
	document.ref6w = '638'; document.ref6h = '441'; document.ref6f = '.jpg';
	document.ref7w = '519'; document.ref7h = '365'; document.ref7f = '.gif';
	document.ref8w = '593'; document.ref8h = '388'; document.ref8f = '.gif';
	document.ref9w = '630'; document.ref9h = '472'; document.ref9f = '.jpg';
	document.ref10w = '697'; document.ref10h = '486'; document.ref10f = '.jpg';
	document.lastref = 1;
	$('#refvor').bind('click', function(event) {
		var newref = document.lastref != 10 ? document.lastref+1 : 1;
		var refw = eval('document.ref'+newref+'w');
		var refh = eval('document.ref'+newref+'h');
		var reff = eval('document.ref'+newref+'f');
		var loader = '<img style="margin-top:140px" src="images/ajax-loader.gif" class="loader" alt="" />';
		$('#refpic').hide();
		$('#refpic').attr({src:'images/ref-'+newref+reff});
		$('#refpic').attr({width:refw});
		$('#refpic').attr({height:refh});
		$('.ref-pic').append(loader);
		$('#refpic').load(function() {
			$('#refpic').fadeIn('slow');
			$('.loader').hide();
		});
		document.lastref = newref;
	});
	$('#refzur').bind('click', function(event) {
		var newref = document.lastref != 1 ? document.lastref-1 : 10;
		var refw = eval('document.ref'+newref+'w');
		var refh = eval('document.ref'+newref+'h');
		var reff = eval('document.ref'+newref+'f');
		var loader = '<img style="margin-top:140px" src="images/ajax-loader.gif" class="loader" alt="" />';
		$('#refpic').hide();
		$('#refpic').attr({src:'images/ref-'+newref+reff});
		$('#refpic').attr({width:refw});
		$('#refpic').attr({height:refh});
		$('.ref-pic').append(loader);
		$('#refpic').load(function() {
			$('#refpic').fadeIn('slow');
			$('.loader').hide();
		});
		document.lastref = newref;
	});

	/* Kontaktformular */
	$('.textfield-tpl').each(function(){
		var content = $(this).val();
		$(this)
			.focusin(function(){
				if($(this).val() == content) $(this).val('');
			})
			.focusout(function(){
				if($.trim($(this).val()) == '') {
					$(this).val(content);
					if(!$(this).hasClass('textfield-tpl') ) {
        		$(this).addClass('textfield-tpl');
        		$(this).removeClass('textfield');
      		}
				}
				else {
					$(this).addClass('textfield');
					$(this).removeClass('textfield-tpl');
				}
			})
		;
	});
	$('#formkontakt').submit(function(){
		// Namenseingabe kontrollieren
		if($('input[name=name]').val() == 'Herr/Frau Vor- und Nachname') {
			$('input[name=name]').css('color', '#d01515');
			$('html,body').animate({
				scrollTop: $('#error').offset().top
			}, 1000 , function (){location.hash = '#error';});
		}
		else {
	  	var name = $('input[name=name]');
	  	var company = $('input[name=company]');
	  	var telnr = $('input[name=telnr]');
	  	var email = $('input[name=email]');
	  	var grafikdesign = $('input[name=grafikdesign]');
	  	var webdesign = $('input[name=webdesign]');
	  	var werbemittel = $('input[name=werbemittel]');
	  	var marketing = $('input[name=marketing]');
	  	var startup = $('input[name=startup]');
	  	var anderes = $('input[name=anderes]');
	  	var text = $('textarea[name=text]');
	
		  var data = 'name='+name.val()
		           + '&company='+(company.val() != 'Firmenbezeichnung (optional)' ? company.val() : '-')
		           + '&telnr='+(telnr.val() != 'Telefon- oder Mobilfunknummer (optional)' ? telnr.val() : '-')
		           + '&email='+(email.val() != 'E-Mail Adresse (optional)' ? email.val() : '-')
		           + '&grafikdesign='+(grafikdesign.attr('checked') ? grafikdesign.val() : '')
		           + '&webdesign='+(webdesign.attr('checked') ? webdesign.val() : '')
		           + '&werbemittel='+(werbemittel.attr('checked') ? werbemittel.val() : '')
		           + '&marketing='+(marketing.attr('checked') ? marketing.val() : '')
		           + '&startup='+(startup.attr('checked') ? startup.val() : '')
		           + '&anderes='+(anderes.attr('checked') ? anderes.val() : '')
			         + '&text='+encodeURIComponent(text.val());

		  $('input[name=send]').hide();
		  $('.loading-icon').show();

			$.ajax({
				url: 'contact.php',	
				type: 'POST',
				data: data,		
				success: function (reqCode) {			
					if(reqCode==1) {
						$('html,body').animate({
							scrollTop: $('#top').offset().top
							}, 1000 , function (){location.hash = '#top';});
		  			$('#formkontakt').hide();
						$('#success').show();
						var title = name.val().substring(0,4);
						if(title == 'frau' || title == 'Frau') successtitle = 'Sehr geehrte ';
						else if(title == 'herr' || title == 'Herr') successtitle = 'Sehr geehrter ';
						else successtitle = 'Sehr geehrte(r) Herr/Frau ';
						$('#successname').html(successtitle+name.val()+$('#successname').html());
					}
					else { 
						alert('Fehler beim Abschicken des Formulares.');
					}				
				}		
			});
		}
		return false;
	});

	$('input').checkBox();
});

/* Google Analytics */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18010633-1']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
