var data = new Array()
$(function(){
    /*$(window).scroll(function() {
            $('#language').css('top',$(this).scrollTop() + "px");
        });*/
    
    $('.background').height($(document).height())
    
    $('.more').click(function(){
        $(this).hide();
        $('.thumbler').show();
        $('.background').height($(document).height())
        return false;
                
    })
    
    $('.contact').click(function(e){
        $('.overlay').height($(document).height())
        $('.overlay').show()
        
        
        $('.contactForm').css('left',e.pageX-57)
        $('.contactForm').css('top',e.pageY-$('.contactForm').height())
        $('.contactForm').show()
        
        return false;
        
    })
    
    $('.closeForm,.overlay').click(function(e){
        $('.overlay,.contactForm,.contactForm2').hide()
        
        return false;
        
    })
    
    $('.formField').focus(function(){
        if(!data[$(this).attr('name')])
            data[$(this).attr('name')] = $(this).val()
            
        if(data[$(this).attr('name')] == $(this).val()) 
            $(this).val('')        
    })
    
    $('.formField').blur(function(){
        if($(this).val() == '' && data[$(this).attr('name')])
            $(this).val(data[$(this).attr('name')]) 
        //$(this).val('')        
    })
    
    $('#contactForm').submit(function(){
        error = false
        $('input[name="phone"],input[name="email"],input[name="address"],input[name="phone"],input[name="email"],input[name="address"],textarea[name="question"],input[name="security"]').css('border','1px solid #ffffff')
        $('.error1,.error2,.error3,.error4').hide()
        
        if(($('input[name="name"]').val() == '' || $('input[name="name"]').val() == data['name'] || !data['name'] || !$('input[name="name"]').val()) && 
            ($('input[name="company"]').val() == '' || $('input[name="company"]').val() == data['company'] || !data['company'] || !$('input[name="company"]').val())
        ){
           $('input[name="name"],input[name="company"]').css('border','1px solid #ff1f1f')
           $('.error1').show()
           error = true;
        }
        
        if(($('input[name="phone"]').val() == '' || $('input[name="phone"]').val() == data['phone'] || !data['phone'] || !$('input[name="phone"]').val()) && 
            ($('input[name="email"]').val() == '' || $('input[name="email"]').val() == data['email'] || !data['email'] || !$('input[name="email"]').val())&& 
            ($('input[name="address"]').val() == '' || $('input[name="address"]').val() == data['address'] || !data['address'] || !$('input[name="address"]').val())
        ){
           $('input[name="phone"],input[name="email"],input[name="address"]').css('border','1px solid #ff1f1f')
           $('.error2').show()
           error = true;
        }
        
        if(($('textarea[name="question"]').val() == '' || $('textarea[name="question"]').val() == data['question'] || !data['question'] || !$('textarea[name="question"]').val())){
           $('textarea[name="question"]').css('border','1px solid #ff1f1f')
           $('.error3').show()
           error = true;
        }
        if(($('input[name="security"]').val() == '' || $('input[name="security"]').val().toLowerCase() != 'grafikarna')){
           $('input[name="security"]').css('border','1px solid #ff1f1f')
           $('.error4').show()
           error = true;
        }
        
        
        
        if(!error){
           $('.contactForm2').css('left',$('.contactForm').css('left'))
           $('.contactForm2').css('top',Number($('.contactForm').css('top').replace('px',''))+$('.contactForm').height()-212) 
           $('.contactForm2').show() 
           $('.contactForm').hide()
           setTimeout('hideForm()', 5000) 
           $.post("/ajax", $("#contactForm").serialize());
        }
        
        
        return false;
    })
    
    
        
})

function hideForm(){
    $('.overlay,.contactForm,.contactForm2').hide()    
}

