// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
//$(document).ready(function() {
//  setTimeout(hideFlashes, 25000);
//});
//
//var hideFlashes = function() {
//  $('p.notice, p.warning, p.error').fadeOut(1500);
//}

$j = jQuery.noConflict()

$j(document).ajaxStart(function(){
  jQuery("#progress").fadeIn(1000);
});

$j(document).ajaxStop(function(){
  jQuery("#progress").fadeOut(1000);
});
var options = {
  target:        '#jdialog',   // target element(s) to be updated with server response
  //beforeSubmit:  showRequest,  // pre-submit callback
  success:       showResponse,  // post-submit callback
  clearForm:     true
// other available options:
//url:       url         // override for form's 'action' attribute
//type:      type        // 'get' or 'post', override for form's 'method' attribute
//dataType:  null        // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true        // clear all form fields after successful submit
//resetForm: true        // reset the form after successful submit

// $.ajax options can be used here too, for example:
//timeout:   3000
};
function showResponse(){

}
$j(document).ready(function()
{
  
  // top sliding panel
  $j("#slide").mouseenter(function(){
     if (!$j("#panel").is(':animated')) {
        $j("#panel").slideDown("slow");
        //$j(this).toggleClass("active");
     }
  });
      
  $j("#slide").mouseleave(function(){
      if (!$j("#panel").is(':animated')) {
        $j("#panel").slideUp("slow");
		    //$j(this).toggleClass("active");
      }
    });
  // bind to the form's submit event
  $j('#jdialog').dialog({
    //bgiframe: true,
    autoOpen: false,
    modal: true,
    buttons: {
      'Продолжить': function() {
          
        $j('#form_dialog').ajaxSubmit(options); //submit();
        loadDialog();
        var dformsnumber = $j('#form_dialog').length;
        if (dformsnumber==0)
        {
          $j(this).dialog('close');
        }
          
      },
      'Отмена': function() {
        loadDialog();
        $j(this).dialog('close');
          
      }
    },
    close: function() {
      loadDialog();
      $j('#form_dialog').html('');
    //jQuery(this).dialog('close');
        
    },
    width: 550
  });
  loadDialog();
});
  

function loadDialog(){
  $j('#contact_form').click(function(){
    $j('#jdialog').dialog("open").load('/contact_form/index').dialog("open");
  });
}
