jQuery.noConflict();

jQuery(document).ready(function($){
$('input,textarea').focus(function(){
 $(this).parent('li').addClass('focus');
})
$('input,textarea').blur(function(){
 $(this).parent('li').removeClass('focus');
})

$('table.outofstock tr').hover(
  function () {$(this).addClass('darker');},
  function () {$(this).removeClass('darker');}
);
/*$('table.outofstock tr, table.outofstock tr input').click(function () {
  var checkboxObject = $(this).find('input[type=checkbox]');
  console.log('kolo');
  if (checkboxObject.is(':checked')) {
    $(this).removeClass('selected');
  } else {
    $(this).addClass('selected');
  }
});*/

$('table .select-all').click(function() {
  $('table input[type=checkbox]').attr('checked', 'checked');
  $('table tr').addClass('selected');
  return false;
})

$('table .deselect-all').click(function() {
  $('table input[type=checkbox]').removeAttr('checked');
  $('table tr').removeClass('selected');
  return false;
})

$('a.back').click(function(){
 history.back();
 return false;
})
/*---------------- EXPEDICE / STORNO * -----------------------------------------*/
 $('button[name="send-expedition"]').click(function(e){
  function insertPackageNumber(thisObject,e,insertedNumber){

   var promptValue=prompt('Zadejte prosím číslo balíku:');
   if(promptValue==null){
    e.preventDefault();
   }else if(promptValue==''){
    alert('Vyplňte prosím číslo balíku!');
    insertPackageNumber(thisObject,e,promptValue);
   }else{
    thisObject.parent('span').prev('input').val(promptValue);
   }

  }

  if(!$(this).hasClass('personal')){
   insertPackageNumber($(this),e,'');
  }

 })

 $('button[name="send-storno"]').click(function(e){
  var orderNumber=$(this).parents('tr').children('td:first').text();
  if(!orderNumber){
   var orderNumber=$('li.order-number strong').text();
  }
  if(!confirm("Opravdu chcete stornovat objednávku č.:\n\n"+orderNumber)){
   e.preventDefault();
  }
 })

/*---------------- DYNAMICKÉ VYHLEDÁVÁNÍ -------------*/
 function formatItem(row) {
    return row[0];
  }
 function formatResult(row) {
    return row[1];
  }

 $('#search input').autocomplete('/autocompleter/',{
  width:500,
  formatItem: formatItem,
  formatResult: formatResult
 });
 $('#search input').result(function(event,data,fromatted){
  window.location=data[2];
//  return false;
 })

/*---------------- OBRÁZKY V DETAILU PRODUKTU -------------*/
 $('#product #product-images a').click(function(){
  $('#product #product-images img.current').attr('src',$(this).attr('href'));
  return false;
  e.preventDefault();
 })

/*---------------- ZATRŽÍTKA VÝROBCŮ -------------*/
 $('input.producer').click(function(){
  if($(this).attr('id')!='producer-0'){
   $('#producer-0').removeAttr('checked');
  }else{
   $('input.producer').removeAttr('checked');
   $(this).attr('checked','checked');
  }
 })

/*---------------- OHEKOVÁNÍ BUTTONU EPUBLISHE * -------------*/
 var imagesUrl='/_common/epcommon_3_4/_gfx/';

 var editButtons=new Array(
  new Array('btnEditActive','page_white_edit.gif','page_edit.gif'),
  new Array('btnSortUpActive','arrow_up_green.gif','arrow_up_red.gif'),
  new Array('btnSortUpInactive','arrow_up_grey.gif','arrow_up_grey.gif'),
  new Array('btnSortDownActive','arrow_down_green.gif','arrow_down_red.gif'),
  new Array('btnSortDownInactive','arrow_down_grey.gif','arrow_down_grey.gif'),
  new Array('btnVisibleActive','eye_visible.gif','eye_invisible.gif'),
  new Array('btnDeleteActive','delete.gif','cross.gif'),
  new Array('btnAddActive','add.gif','add_blue.gif')
 );

 $('.btnIco').css({backgroundColor:'transparent',backgroundPosition:'center bottom',backgroundRepeat:'no-repeat',display:'block',height:'16px',textEecoration:'none',width:'20px',padding:'0px 0px',margin:'0px 0px',border:'none'});
 $('.ep_adminTools_button,.ep_adminTools_button_noActive').css({backgroundImage:'none',fontFamily:'"Verdana CE", Verdana, "Arial CE", Arial, "Lucida Grande CE", lucida, "Helvetica CE", sans-serif',padding:'0px 0px',margin:'0px 0px',fontSize:'11px',fontWeight:'normal',textTransform:'none',display:'inline',lineHeight:'1.4',float:'none',border:'none'});
 $('.ep_adminTools_button_noActive').css('background-color','#c58888');
 $('.dark_green').css('background-color','#00c500');


 $('.ep_adminTools_button').hover(
  function(){
   $(this).css('background-color','#f80');
  },
  function(){
   $(this).css('background-color','#c50000');
  }
 )

 for(i=0;i<editButtons.length;i++){
  $('.'+editButtons[i][0]).css('background-image','url('+imagesUrl+editButtons[i][1]+')');
  $('.'+editButtons[i][0]).attr('rel',i);
  $('.'+editButtons[i][0]).hover(
   function(){
    $(this).css('background-image','url('+imagesUrl+editButtons[$(this).attr('rel')][2]+')');
   },
   function(){
    $(this).css('background-image','url('+imagesUrl+editButtons[$(this).attr('rel')][1]+')');
   }
  );
 } 
 
 if(jQuery('#form-product-check')[0]) {
   jQuery('#form-product-check').submit(function() {        
     var arr = [];
     jQuery('.product-check:checked').each(function() {
       arr.push(jQuery(this).val());       
     });
     jQuery('#product-id').val(arr);     
   });
 } 
 
 if(jQuery('#popup').css('display')=='block') {
   jQuery('body').css('overflow', 'hidden');
 }
 jQuery('#popup a').click(function(e) {
   if(jQuery('#popup a').index(jQuery(this))==1) {
     e.preventDefault();
   }
   jQuery('#popup').hide();
   jQuery('#overlay').hide();
   jQuery('body').css('overflow', 'auto');
 }); 
});
