/**
 * @author Alexander Marquardt
 * 
 * $(this).attr('style','border: 1px dotted red;');
 */

$().ready(function() {

    $('.profildiv').attr('style','display: none; height:1px; width: 1px; left: -100px;');

    // ausfahren des kontaktformulars
    $('#kontaktclick').click(function (){
	$('#contact').fadeIn('slow');
	return false;
    });

    $('#kontaktclose').click(function (){
	$('#contact').fadeOut('slow');
	return false;
    });

    $(".kundenliste").hover(function(){
	$(this).css('background-position', 'left -100px');
    }, function() {
	$(this).css('background-position', 'left top');
    });

    $(".partnerliste").hover(function(){
	$(this).css('background-position', 'left -100px');
    }, function() {
	$(this).css('background-position', 'left top');
    });


    $("#profilanfordern a, #agenturprofil2, img#agenturprofil3").click(function(){
	$("#fadebg").fadeIn('fast');
	$(".profildiv").attr('style','display: none; top: 200px; left: 50%; margin-left: -470px; width: 950px; height: 420px;');
	$(".profildiv").fadeIn('slow');

	return false;
    });

    $("#profilclose").click(function(){
	$("#fadebg").fadeOut('fast');
	$(".profildiv").fadeOut('slow');
    });

       $(".kundenliste").click(function(){
	var id = $(this).attr('ref');
	$.ajax({
	    type: "POST",
	    url: "contents/showdata",
	    data: {
		id: id
	    },
	    success: function(data){
		$("#fadebg").fadeIn('fast', showit);
		function showit() {
		    $("#kundencontent").html(data);
		    $("#kundenzoom").attr('style','position: fixed');
		    $("#kundenzoom").fadeIn('slow');
		}
	    }
	});
    });

    $("#kundenclose").click(function(){
	$("#fadebg").fadeOut('fast');
	$("#kundenzoom").fadeOut('slow');
    });

    $("#ProfileAddForm").submit(function() {
	var name = $("#ProfileName").val();
	var firma = $("#ProfileFirma").val();
	var address = $("#ProfileAddress").val();
	var city = $("#ProfileCity").val();
	var validation = 0;

	if(name == "") {
	    $("#ProfileName").focus();
	    $("#ProfileName").css({ backgroundColor: '#d1d1d1'})
	} else if (firma == "") {
	    $("#ProfileFirma").focus();
	    $("#ProfileFirma").css({ backgroundColor: '#eaeaea'})
	    $("#ProfileName").css({ backgroundColor: '#ffffff'})
	} else if (address == "") {
	    $("#ProfileAddress").focus();
	    $("#ProfileAddress").css({ backgroundColor: '#eaeaea'})
	    $("#ProfileFirma").css({ backgroundColor: '#ffffff'})
	} else if (city == "") {
	    $("#ProfileCity").focus();
	    $("#ProfileCity").css({ backgroundColor: '#eaeaea'})
	    $("#ProfileAddress").css({ backgroundColor: '#ffffff'})
	} else {
	    $("#ProfileCity").css({ backgroundColor: '#ffffff'})
	    validation = 1;
	}

	if(validation == 1) {
	    return true;
	} else if (validation == 0){
	    return false;
	}
    });

    $(".profilbutton").hover(
    function() {
	$(this).attr('src','img/absenden_hv.png');
    },
    function(){
	$(this).attr('src','img/absenden.png');
    });
});
