var StationList;
$(document).ready(function(){
    $('div.introdiv:first').show();
    $(document).bind("click", function(e){
        if($(e.target).closest('#searchcont').length < 1)
            $('#searchcont').hide();
    });
   
    $('a.fancybox').fancybox({
        onComplete: function(link){
            $($(link).attr('href') + ' input:first').focus();
        }
    });
   
    $('#share_form form').validate({
        rules: {
            "share_email": {
                required:true,
                email : true
            }
        },
        messages: {
            "share_email" : "Please enter a valid e-mail address"
        },
        errorPlacement : function(err, elem){
            $(elem).qtip({
                position: {
                    my: "bottom right",
                    at: "top left"
                },
                show: {
                    event: 'focus'
                },
                hide: {
                    event: "blur"
                },
                content: {
                    text : $(err[0]).text()
                },
                style: {
                    classes : "ui-tooltip-red ui-tooltip-rounded"
                }
            });
        },
        submitHandler: function(){
            $.ajax({
                data: $('#share_form form').serialize(),
                type: 'post',
                cache: false,
                url : "/ajax/share",
                success: function(){
                    $('#share_email').val('');
                    $.fancybox.close();
                }
            });
        }
    });
});
