$(document).ready(function()
{
	// Kontaktformular Submit Function
	if ($('#send-mail-form').size() > 0)
	{
		var contacttimer;

		$('#send-mail-form').ajaxForm({

			// Ajax Loader Symbol anzeigen
	    	beforeSubmit: function()
			{
				$('#loader').show();
	        },

			// POST auswerten
	        success: function(data) {
				clearTimeout(contacttimer);
				contacttimer = setTimeout(function ()
				{

					// Ajax Loader Symbol ausblenden
					$('#loader').hide();

					// POST auswerten
					if(data != 'success')
					{
						jAlert(data, 'Hinweis', function()
						{
							var found = false;

							// Fehlendes Feld auswählen
							$('#send-mail-form input, #send-mail-form textarea').each(function()
							{
								if (!found)
								{
									if ($(this).attr('type') != 'radio' && $(this).val() == '')
									{
										$(this).focus();
										found = true;
									}
								}
							});
						});
					}
					else
					{
						jAlert('Wir werden uns so schnell wie möglich mit Ihnen in Verbindung setzen.', 'Vielen Dank für ihr Interesse!', function() {
							$('#send-mail-form input, #send-mail-form textarea').each(function() {
								if($(this).attr('type') != 'radio')
									$(this).val('');
								else
									$('time0').attr('checked', true);
							});
						});
					}
				}, 1000);
			}

	    });
	}

	// Button Hover Effect
	$('.button, .big-button').hover(function()
	{
		$(this).children('span').stop().animate({'opacity' : '1'}, 200);
		}, function(){$(this).children('span').stop().animate({'opacity' : '0'}, 200);
	});

	// Externe Links automatische in neuem Fenster öffnen
	$('a[href^=http]').click( function()
	{
		window.open(this.href);
		return false;
	});

	// Projekt-Slider
	if ($('.projekt-slider-items div').size() > 0)
	{
		$(".projekt-slider").scrollable({
			items: '.projekt-slider-items',
			size: 1,
			next: '.projekt-slider-next',
			prev: '.projekt-slider-prev',
			clickable: true,
			keyboard: false,
			circular: true
		});
	}
    
    if(navigator.userAgent.indexOf('MSIE 6.0') != -1)
    {
    	var src = $("img#background").attr('src');
    	$('body').css({
    		background: '#000 url(' + src + ') no-repeat top center'
    	});
    	
    	$('img#background').remove();
   	}
    
    // Background Image Resizen
    if($(window).width() > 2000)
        $("img#background").css({ 
        	width: $(window).width() 
		});
	else if($(window).height() > 1100)
	    $("img#background").css({
    		width: $(window).height() * 1.82,
			height: $(window).height()
    	});
	else
		$("img#background").css({ 
        	width: 2000 
		});
	    
	$(window).bind("resize", function() {
        var winWidth  = $(window).width();
        var winHeight = $(window).height();
		
		if(winWidth > 2000)
            $("img#background").css({ 
            	width: winWidth 
			});
		else if(winHeight > 1100)
		    $("img#background").css({
	    		width: winHeight * 1.82,
				height: winHeight
	    	});
 		else
 			$("img#background").css({ 
            	width: 2000 
			});
	});
});