$(function() {
  // there's the gallery and the trash
  var $recipe_items = $( ".on-the-go,.on-the-table" );

  // let the gallery items be draggable
  $( ".recipe", $recipe_items ).draggable({
    cancel: "a.ui-icon", // clicking an icon won't initiate dragging
    revert: "invalid", // when not dropped, the item will revert back to its initial position
    helper: "clone",
    cursor: "move",
    helper: function( event ) {
      var append_c=$('.recipeHeader',$(this)).html();
      var class_name='drwp_for_other';
      if($(this).hasClass('recipeHeader_for_simple')){
        class_name='drwp_for_simple';
      }else if($(this).hasClass('recipeHeader_for_table')){
        class_name='drwp_for_table';
      }

      return $('<div class="dr_item '+class_name+' have_corner">'+append_c+'</di>');
    }
  });


  // $( "#ks_monday .ks_day_inner,#ks_tuesday .ks_day_inner,  #ks_wednesday .ks_day_inner, #ks_thursday .ks_day_inner, #ks_friday .ks_day_inner, #ks_saturday .ks_day_inner, #ks_sunday .ks_day_inner " ).droppable({
  $( "#ks_monday ,#ks_tuesday,  #ks_wednesday , #ks_thursday, #ks_friday , #ks_saturday, #ks_sunday " ).droppable({
    greedy: true,
    activeClass: "ui-state-hover",
    hoverClass: "ui-state-active",
    drop: function( event, ui ) {
      $(this).html('');
      add_item(ui.draggable,$(this));
    },

    over :function( event, ui){
            //$(this).html('Drag here');
          },

    out: function (event,ui){
           // $(this).html('');
         }

  });

  function add_item($item,$target){
    var append_c=$('.recipeHeader',$item).html();
    var class_name='drwp_for_other';
    var input_day=$target.attr('id').split('_',2)[1];
    var input_id=$('.recipeHeader',$item).attr('id').split('-',2)[1];

    $('#input_'+input_day).val(input_id);
    if($item.hasClass('recipeHeader_for_simple')){
      class_name='drwp_for_simple';
    }else if($item.hasClass('recipeHeader_for_table')){
      class_name='drwp_for_table';
    }

    var when_click =$target.append('<div class="dr_item '+class_name+'">'+append_c+'<div class="remove"><p>Remove</p></div></di>');
    //----remove
    $('.dr_item .remove',when_click).click(function(){
      // alert('ok');
      $(this).parents('.dr_item').fadeOut(400,function(){
        $(this).parents('.dr_item').remove();
      });
    });

  }


  $('.a_submit_bt').click(function(){


    $('#ks_calendar_form').submit();
    return false;
  });


  $('.a_submit_bt_fr').click(function(){


    $('#ks_calendar_form').submit();
    return false;
  });

  /*
     $('#ks_calendar_form').submit(function(){
     var data = $(this).serialize();

     $.ajax({
     type: "POST",
     url: root_url+"/"+userLocale+"/print",
     data: data+"&ajax=1",
     success: function(msg){
  // alert(msg);
  window.open (root_url+"/"+userLocale+"/print","mywindow");
  }
  });

  // alert(data);

  return false;
  });

*/

  //-----------------

  $('.star_planding,.star_planding_fr').click(function(){
    $('.ks_quick_view, .a_boy').fadeOut(300,function() {
      $('.ks_main_c').fadeIn(200);
    });

    window.location.hash='star_planding';

    return false;
  });

  $('.one_in_all').val('');

  var whash=window.location.hash.toLowerCase().replace('#','');

  if(whash=='star_planding'){
    $('.ks_quick_view,.a_boy').fadeOut(300,function(){
      $('.ks_main_c').fadeIn(200);
    });
  }

});

