jQuery(document).ready(function()
{


$('.main_work').hover(
  function () {
  $(this).addClass("hover");
  },
  function () {
    $(this).removeClass("hover");
  }
);  


// Ipad Slider
$('.portfolio_slide:first').addClass('active_slide');
var first_slide_show = $('.active_slide').html();
$('.portfolio_main_slide_container').html(first_slide_show).jScrollPane({scrollbarWidth:0, wheelSpeed:80});


$('.portfolio_slide_arrow_box').hover(
  function () {
    $(this).stop(true, true).addClass('hover_arrow'); 
  },
  function () {
   $(this).stop(true, true).removeClass('hover_arrow'); 
  }
);

$('.portfolio_tablet_display').hover(
  function () {
    $('.portfolio_slide_arrow_box').stop(true, true).fadeIn(400);  
  },
  function () {  
   $('.portfolio_slide_arrow_box').stop(true, true).fadeOut(400);    
  }
);

$('.portfolio_slide_arrow_box_right, .portfolio_tablet_display').live("click", function(){    
   $('.for_scroll').removeClass('for_scroll'); 
    var last_index = $('.portfolio_slide:last').index();
     if ( $('.active_slide').index() == last_index)   {
          $('.active_slide:last').removeClass('active_slide'); 
          $('.portfolio_slide:first').addClass('active_slide'); 
          $('.portfolio_slide').hide();  
       } 
   
      else {
         $('.active_slide').next('div').addClass('active_slide');
         $('.active_slide:first').removeClass('active_slide'); 
         $('.portfolio_slide').hide();    
      }
    
     var active_html = $('.active_slide').html(); 
     $('.portfolio_main_slide_container').html(active_html)
     $('.portfolio_main_slide_container').jScrollPaneRemove();
     $('.portfolio_main_slide_container').jScrollPane({scrollbarWidth:0, wheelSpeed:80});  
     return false; 
});


$('.portfolio_slide_arrow_box_left').live("click", function(){    
    var first_index = $('.portfolio_slide:first').index();
     if ( $('.active_slide').index() == first_index)   {
          $('.active_slide:last').removeClass('active_slide'); 
          $('.portfolio_slide:last').addClass('active_slide'); 
          $('.portfolio_slide').hide();  
       } 
   
      else {
         $('.active_slide').prev('div').addClass('active_slide');
         $('.active_slide:last').removeClass('active_slide'); 
         $('.portfolio_slide').hide();    
      }
    
     var active_html = $('.active_slide').html(); 
     $('.portfolio_main_slide_container').html(active_html)
     $('.portfolio_main_slide_container').jScrollPaneRemove();
     $('.portfolio_main_slide_container').jScrollPane({scrollbarWidth:0, wheelSpeed:80});  
     return false; 
});
// -----------

$('.work').hover(
  function () {
    $(this).stop(true, true).addClass('work_hover');  
  },
  function () {  
   $(this).stop(true, true).removeClass('work_hover');         
  }
);


/*Отправка формы*/             
jQuery('input[name="submit"],.form_submit,input[name="send"]').live("click", function(){      submit_form(); return false;});
jQuery('#filter_form_submit').live("click", function(){      filter_form_submit(); return false;}); 
jQuery('#filter_form_reset').live("click", function(){$("#filter_form").clearForm(); filter_form_submit(); window.location = window.location; return false;});  
/**/


//*Основная функция отправки формы*//
function submit_form(callback)
    {
                
    //setTimeout(function(){submit_form();},2000); 
    //Переписываем WYSIWYG в textarea поля для отправки
    if (jQuery("#form_edit textarea[name^='wysiwyg']").length )
        {
        jQuery("#form_edit textarea[name^='wysiwyg']").each(function () 
            {
            var wysiwyg_id=jQuery(this).next('input').attr('value');
            jQuery(this).attr('value',tinyMCE.get(wysiwyg_id).getContent());
            });
        };
    //           
                        
                          
    var options_form_dtable = {
      target:'.form_edit-result',  
      type:'POST',                      
      beforeSubmit:function() {                              
      $('#form_edit input[type="submit"]').attr('disabled','disabled');
      $('.form_edit-result').html('<div class="loader-small"></div>');                                                           
      },
      success: function() {                     
      if (jQuery('li.form_messages-error').length==0)
        {      
          if (jQuery('#form_edit').hasClass('new_comment-form')){
                  if (jQuery("#form_edit textarea[name^='wysiwyg']").length )
                    {
                    jQuery("#form_edit textarea[name^='wysiwyg']").each(function () 
                        {
                        var wysiwyg_id=jQuery(this).next('input').attr('value');
                        tinyMCE.get(wysiwyg_id).setContent('');
                        });
                    };
           };
        if ($('input[name="callback"]').length){eval($('input[name="callback"]').val());};
        if ($("#dialog").length && $('.dialog_dont_closed').length==false ){$("#dialog").dialog('close');};
        }
      else
        {
        $('#form_edit input[type="submit"]').removeAttr('disabled');
        };
        
      }
    };    
        jQuery('#form_edit').ajaxSubmit(options_form_dtable);   
    };
/**/
});
