/**
 * 
 */

$(document).ready(function(){
    
    $('header').css( {
        backgroundPosition: "0px 0px"
    } );
	
    $('a#klientinnen').mouseover(function(){
        if($('header').css('background-position-x')==""){
            var pos = $('header').css('background-position').replace(/%/g,'px');
        }else{
            pos = $('header').css('background-position-x').replace(/%/g,'px');
        }
        if (pos != '0px 0px' && pos!="0px") {
            $('header').stop().stop().stop().stop().animate( {
                backgroundPosition: "0px 0px"
            }, {
                duration: 500
            })
            .animate( {
                backgroundPosition: "-20px 0px"
            }, {
                duration: 100
            })
            .animate( {
                backgroundPosition: "10px 0px"
            }, {
                duration: 100
            })
            .animate( {
                backgroundPosition: "0px 0px"
            }, {
                duration: 100
            });
        }
    });
	
    $('a#praxen').mouseover(function(){
        if($('header').css('background-position-x')==""){
            var pos = $('header').css('background-position').replace(/%/g,'px');
        }else{
            pos = $('header').css('background-position-x').replace(/%/g,'px');
        }
        if (pos != '960px 0px' && pos!="960px") {
            $('header').stop().stop().stop().stop().animate( {
                backgroundPosition: "960px 0px"
            }, {
                duration: 500
            } )
            .animate( {
                backgroundPosition: "940px 0px"
            }, {
                duration: 100
            } )
            .animate( {
                backgroundPosition: "970px 0px"
            }, {
                duration: 100
            } )
            .animate( {
                backgroundPosition: "960px 0px"
            }, {
                duration: 100
            } );
        }
    });
    
    if($('input[name=station]:checked').val()=="Mammobil" && $('#mammoLocationHider').css('display')=="none"){
        $.get('http://www.mammascreening-bonn-rhein-sieg-euskirchen.de/mammobiltermine',function(data){
            $('.contenttable').html($(data).find("#mammotermine").html());
            $('#mammoLocationHider').show();
        });
        
    }
    $('input[name=station]').click(function(){
        if($(this).val()=="Mammobil"){
            $.get('http://www.mammascreening-bonn-rhein-sieg-euskirchen.de/mammobiltermine',function(data){
                $('.contenttable').html($(data).find("#mammotermine").html());
                $('#mammoLocationHider').fadeIn(200);
            });
            
        }else{
            $('#mammoLocationHider').fadeOut(200);
        }
    })
    
    
    
    
    $('div.teaser').hover(function(){
        $(this).css('border-left','5px solid #A4005A').css('padding-left','10px');
    },function(){
        $(this).css('border-left','0px solid #A4005A').css('padding-left','0px');
    })
    $('div.imgborder').hover(function(){
        $(this).find('.imgfront').stop().animate({
            top:"85px"
        },{
            duration:500
        });
    },function(){
        $(this).find('.imgfront').stop().stop().stop().animate({
            top:"120px"
        },{
            duration:500
        });
    });
    $('div.imgborder_high').hover(function(){
        $(this).find('.imgfront_high').stop().animate({
            top:"70px"
        },{
            duration:500
        });
    },function(){
        $(this).find('.imgfront_high').stop().stop().stop().animate({
            top:"120px"
        },{
            duration:500
        });
    });
    $('div.imgborder_large').hover(function(){
        $(this).find('.imgfront_large').stop().animate({
            top:"205px"
        },{
            duration:500
        });
    },function(){
        $(this).find('.imgfront_large').stop().stop().stop().animate({
            top:"240px"
        },{
            duration:500
        });
    });
    $('a#aktuelles').mouseover(function(){
        if($('header').css('background-position-x')==""){
            var pos = $('header').css('background-position').replace(/%/g,'px');
        }else{
            pos = $('header').css('background-position-x').replace(/%/g,'px');
        }
        if (pos != '1920px 0px' && pos!="1920px") {
            $('header').stop().stop().stop().stop().animate( {
                backgroundPosition: "1920px 0px"
            }, {
                duration: 500
            } )
            .animate( {
                backgroundPosition: "1900px 0px"
            }, {
                duration: 100
            } )
            .animate( {
                backgroundPosition: "1930px 0px"
            }, {
                duration: 100
            } )
            .animate( {
                backgroundPosition: "1920px 0px"
            }, {
                duration: 100
            } );
        }
    });
    $('div#subfaq ul li a').click(function(e){
        e.preventDefault();
        if($(this).parent().children("ul").css('display')=="none"){
            $('ul li ul').slideUp(300);
            $('ul li').css('border-left','0px solid #a4005a').css('padding-left','0px');
            $('ul.children li div').slideUp(300);
            $(this).parent().css('border-left','5px solid #a4005a').css('padding-left','20px');
            $(this).parent().children("ul").slideDown(300);
        }else{
            $(this).parent().css('border-left','0px solid #a4005a').css('padding-left','0px');
            $(this).parent().children("ul").slideUp(300);
        }
    });
    
    $('ul.children li a').click(function(e){
        e.preventDefault();
        //var dieid=$(this).attr('href').split("=");
        var linkdata=$(this).attr('href').split("/");
        var dieid;
        if(linkdata!=""){
            $.post("getlinkbyajax.php",{
                link:linkdata[linkdata.length-1]
            },function(data){
                dieid=data.replace("\n","");

                $("li div.faqcontent").slideUp(300);
                if($("li.page-item-"+dieid+" div").hasClass("faqcontent")==true){
                    if($("li.page-item-"+dieid+" div.faqcontent").css('display')=="none"){

                        $("li.page-item-"+dieid+" div.faqcontent").slideDown(300);
                    }else{
                        $("li.page-item-"+dieid).css('border-left','0px solid #a4005a').css('padding-left','0px');
                        $("li.page-item-"+dieid+" div.faqcontent").slideUp(300);
                    }
                /*
            if($("li.page-item-"+dieid[1]+" div.faqcontent").css('display')=="none"){
                $("li.page-item-"+dieid[1]+" div.faqcontent").slideDown(300);
            }else{
                $("li.page-item-"+dieid[1]+" div.faqcontent").slideUp(300);
            }*/
                }else{

                    $.post("ajax.php",{
                        id:dieid
                    },function(data){
                        
                        $("li.page-item-"+dieid).append(data);

                        $("li.page-item-"+dieid+" div.faqcontent").slideDown(300);
                        $("li.page-item-"+dieid).addClass("open");
                    });
                }
        

            });
        }
        

        




    /*$("li div.faqcontent").slideUp(300);
        if($("li.page-item-"+dieid[1]+" div").hasClass("faqcontent")==true){
            if($("li.page-item-"+dieid[1]+" div.faqcontent").css('display')=="none"){
                
                $("li.page-item-"+dieid[1]+" div.faqcontent").slideDown(300);
            }else{
                $("li.page-item-"+dieid[1]).css('border-left','0px solid #a4005a').css('padding-left','0px');
                $("li.page-item-"+dieid[1]+" div.faqcontent").slideUp(300);
            }
        /*
            if($("li.page-item-"+dieid[1]+" div.faqcontent").css('display')=="none"){
                $("li.page-item-"+dieid[1]+" div.faqcontent").slideDown(300);
            }else{
                $("li.page-item-"+dieid[1]+" div.faqcontent").slideUp(300);
            }*/
    /* }else{
            
            $.post("ajax.php",{
                id:dieid[1],
                link:linkdata[linkdata.length-1]
            },function(data){
                $("li.page-item-"+dieid[1]).append(data);
                $("li.page-item-"+dieid[1]+" div.faqcontent").slideDown(300);
                $("li.page-item-"+dieid[1]).addClass("open");
            });
        }*/
    });
    
    var emptyfields=new Array();
    function seekemptyfields(){
        emptyfields=new Array();
        $('.hint').each(function(){
            
            var fieldid=$(this).attr("id");
            
            if($("input[name="+fieldid+"]").val()==""){
                
                $(this).hide();
                emptyfields.push(fieldid);
            }
            if($("textarea[name="+fieldid+"]").val()==""){
                $(this).hide();
                emptyfields.push(fieldid);
            }
        });
        
    }
    jQuery.expr[':'].focus = function( elem ) {
        return elem === document.activeElement && ( elem.type || elem.href );
    };
    var selectedInput;
    function showfirstfield(){
        var thisfield=emptyfields.reverse().pop();
        $('div#'+thisfield).show();
        $('div.arrow').stop().animate( {
            left:"0px"
        }, {
            duration: 100
        } ).animate( {
            left:"15px"
        }, {
            duration: 100
        } ).animate( {
            left:"0px"
        }, {
            duration: 100
        } ).animate( {
            left:"5px"
        }, {
            duration: 100
        } ).animate( {
            left:"0px"
        }, {
            duration: 70
        } ).animate( {
            left:"3px"
        }, {
            duration: 50
        } ).animate( {
            left:"0px"
        }, {
            duration: 30
        } );
        
    }
    seekemptyfields();
    showfirstfield();
    
    if($('input[name="termintyp[]"]').attr('checked')!=true){
        $('#termin,#termincontent').parent().hide();
    }
    $('input,textarea').click(function(){
        var thisid=$(this).attr("name");
        $('#incorrect-'+thisid).hide();
        if(thisid!=""){
            if($('#'+thisid).css("display")=="block"){
                $('#'+thisid).fadeOut(200);
            }
        }
    });
    $('.fault').click(function(){
        id=$(this).attr('id');
        $(this).hide();
        $('input[name='+id.substr(10,id.length-1)+']').focus();
    });

    $('input,textarea').focus(function(){
        var thisid=$(this).attr("name");
        selectedInput = thisid;
        $('#incorrect-'+thisid).hide();
        if(thisid!=""){
            if($('#'+thisid).css("display")=="block"){
                $('#'+thisid).hide();
            }
        }
    });
    $('input[name="termintyp[]"]').click(function(){
        if($(this).attr("checked")!=true){
            $('#termin,#termincontent').parent().fadeOut(200);
        }else{
            $('#termin,#termincontent').parent().fadeIn(200);
        }
    });
    $('.hint').click(function(){
        var thisid=$(this).attr("id");
        $('#incorrect-'+thisid).hide();
        if($('#'+thisid).css("display")=="block"){
            $('#'+thisid).fadeOut(200);
        }
        $('input[name='+thisid+']').focus();
    });
    $('.hint').focus(function(){
        var thisid=$(this).attr("id");
        if($('#'+thisid).css("display")=="block"){
            $('#'+thisid).fadeOut(200);
        }
        $('input[name='+thisid+']').focus();
    });
    $('input,textarea').blur(function(){
        var thisid=$(this).attr("name");
        if($(this).val()==""){
            $('#'+thisid).fadeIn(200);
        }
        seekemptyfields();
        showfirstfield();
    });
    $('div#wpcf7-f1-p89-o1 .wpcf7-form').submit(function(event) {
        event.preventDefault();
        //alert(emptyfields.length);
        //var self = this;
        seekemptyfields();
        sendisallowed=true;
        if(issent!=true && emptyfields.length==0){
            //Validation
            //eMail
            /*result=$('input[name=your-email]').val().search(/@/);
            result1=$('input[name=your-email]').val().search(/\./);
            if(result!=-1 && result1!=-1){
            }else{
                sendisallowed=false;
                $('#incorrect-your-email').show();
            }*/
            //Geburtsdatum
            result=$('input[name=date_of_birth]').val().split(".");
            if(
                result.length==3 &&
                result[0].length==2 &&
                result[1].length==2 &&
                result[2].length==4
                ){
                datum=new Date();

                mindestjahr=datum.getFullYear()-49;
                if(result[2]>=mindestjahr){

                    sendisallowed=false;
                    $('#incorrect-age').show();
                }
            }else{
                sendisallowed=false;
                $('#incorrect-date_of_birth').show();
            }
            if($('input[name=station]:checked').val()==undefined){
                $('#incorrect-station').show();
                sendisallowed=false;
            }
        }else{
            sendisallowed=false;
        }
        if(sendisallowed==true){
            var issent=true;
            this.submit();
        }
    });

    $('div#wpcf7-f3-p53-o1 .wpcf7-form,div#wpcf7-f2-p92-o1 .wpcf7-form').submit(function(event) {
        event.preventDefault();
        //var self = this;
        sendisallowed=true;
        seekemptyfields();
        
        if(issent!=true && emptyfields.length==0){
            
        }else{
            showfirstfield();
            sendisallowed=false;
        }
        if(sendisallowed==true){
            var issent=true;
            this.submit();
        }
    });
    
    $('div#wpcf7-f4-p60-o1 .wpcf7-form').submit(function(event){
        event.preventDefault();
        //var self = this;
        sendisallowed=true;
        seekemptyfields();

        if(issent!=true && emptyfields.length==0){

        }else{
            showfirstfield();
            sendisallowed=false;
        }
        if($('input[type=checkbox]:checked').length==0){
            sendisallowed=false;
        }
        if(sendisallowed==true){
            var issent=true;
            this.submit();
        }
    });
//$('.imgborder a').lightBox();
});

