
$(document).ready(function(){
    var myStatus = false;
                
    $('.showHide').click(
        function() {
            if(!myStatus){
                //Open
                $('.menuDrop').slideToggle('slow', '-1px');
                $('#stage2').show();
                $('#stage1').hide();
                myStatus = true;
            }else{
                //close
                $('.menuDrop').slideToggle('slow', '-205px');
                $('#stage1').show();
                $('#stage2').hide();
                setTimeout(function() {myStatus = false;}, 600);
            }
            return false;
        }
    );
    
    $('.open').hover(
        function (){
            if(!myStatus){
                //Open
                $('.menuDrop').slideToggle('slow', '-1px');
                $('#stage2').show();
                $('#stage1').hide();
                setTimeout(function() {myStatus = true;}, 600);
            }
        }, function(){
            //do nothing
        }
    )
    
    
    $('#submit').click(function(){
        
     
        //Both email and phone number are blank
        if( ($('#email').attr('value') == 'email' || $('#email').attr('value') == '') &&
           ($('#telephone').attr('value') == 'telephone number' || $('#telephone').attr('value') == '') ){
            alert('Please enter an email address or telephone number so we may contact you.');
            return false;
        }
        
        $('#stage2 input').each( function(i){
        //Search for the name=value match
            if( $(this).attr('name') == $(this).attr('value').replace(' ', '_') ){
                $(this).attr({'value' : ''}); //Clear value if it's the default value
            }
        });
        if( $('#query').attr('name') == $('#query').attr('value')){
            $('#query').attr({'value' : ''});
        }
        
        
        
        //alert('submit form');
        $('#stage3').show();
        $('#stage2').hide();
        $('.menuDrop').slideToggle('slow', '-205px');

             
        //Grab data
        var dataString = 'name='+ $('#name').attr('value') +
                         '&email=' + $('#email').attr('value') +
                         '&company=' + $('#company').attr('value') +
                         '&telephone=' + $('#telephone').attr('value') +
                         '&query=' + $('#query').attr('value') +
                         '&page=' + document.title;
                         ;
        
        //Send data
        $.ajax({  
            type: "POST",  
            url: "../_dropdown/process.php",
            data: dataString,  
            success: function(html) {
                //alert(html); debug what's happening in an alert
                               
                
                setTimeout(function(){
                    //hide permanently
                    $('.menuDrop').slideToggle('slow', '-255px');
               }, 1500);
            }
        });  
        
        
       return false;
       
    });
    
    jQuery.fn.slideToggle = function(speed, heightX, easing, callback) {
        return this.animate( {marginTop: heightX} , speed, easing, callback);  
    };
    
    $(document).pngFix();
    
    $('div.stage').css({'z-index' : '1'});
    $('#stage2').hide();
    $('#stage3').hide();
    
    
    $('.input').focus(function(){
        if($(this).attr('value') == $(this).attr('name') ||
           $(this).attr('value').replace(' ', '_') == $(this).attr('name')
        ){
            $(this).attr({'value' : ''});
            $(this).css({'color' : '#333', 'text-align' : 'left'});
            //Grab the info and send it as a post to sMail.php
        }
    });
    
    $('.input').blur(function(){
        if( $(this).attr('value') == ''){
            var curValue =  $(this).attr('name').replace('_', ' ');
            $(this).attr({'value' : curValue}); //asign its own name
            $(this).css({'color' : '#AAA', 'text-align' : 'center'});
        }
        //otherwise leave field as is.
    });
    $('.textarea').attr({'value' : 'query'});
    
    $('.menuDrop').css({'display' : 'block'});
});