jQuery.noConflict();
jQuery(document).ready(function($){


  // clear input when focus
  var clearInputs = $('input[type=text]');
  clearInputs.blur(function() {
  if($(this).attr('value') == '') {
      $(this).attr('value',$(this).attr('alt'));
    }
  });
  clearInputs.focus(function() {
    if($(this).attr('value') == $(this).attr('alt')) {
      $(this).removeAttr('value');
    }
  });


  // Hover category images
  $('ul.hpCategories li a').mouseover(
    function(){
      if($(this).attr("rel")) {
        idImg = "#" + $(this).attr("rev");
        $(idImg).attr("src", $(this).attr("rel"));
      }
  });


  // producers checkbox 
  $('input.producer').click(function() {
    if($(this).attr('id')!='producer-0') {
      $('#producer-0').removeAttr('checked');
    } else {
      $('input.producer').removeAttr('checked');
      $(this).attr('checked','checked');
    }
  });
  $('input.filter').click(function() {
    if($(this).attr('id')!='filter-0') {
      $('#filter-0').removeAttr('checked');
    } else {
      $('input.filter').removeAttr('checked');
      $(this).attr('checked','checked');
    }
  });



  // focus active input
  $("input.txt, textarea.txt").focus(function() {
    $(this).parent().addClass("focus")
  });
  $("input.txt, textarea.txt").blur(function() {
    $(this).parent().removeClass("focus")
  })



  // fadeoud success message
  $('.success').animate({opacity: 1.0}, 5000).animate({opacity: 0.0}, 500).slideUp('fast', function() {
    $(this).remove();
  });



  // hover admin buttons
  $(".edit.menu").css({visibility:'hidden'});
  $("#mainMenu li").hover(function(){
    $(this).find(".edit.menu").css({visibility:'visible'});
  },
  function(){
    $(this).find(".edit.menu").css({visibility:'hidden'});
  });



  // hover admin menu
  $('#adminMenu').hover(
    function(){
      $(this).find("menu").show();
      $(this).find("#holder").css({backgroundPosition:"left bottom"});
    },
    function(){
      $(this).find("menu").hide();
      $(this).find("#holder").css({backgroundPosition:"left top"});
    }
  );



  // show only active category
  /*
  $("#categories li > ul").hide();
  $("#categories li a.active").parent().find("ul").show();
  */


  // set equal height for product boxes
  function equalHeight(group) {
  	tallest = 0;
  	group.each(function() {
  		thisHeight = $(this).height();
  		if(thisHeight > tallest) {
  			tallest = thisHeight;
  		}
  	});
  	group.height(tallest);
  }
  equalHeight($(".products li"));
  equalHeight($("#boxes .box"));
  if($("#sidebar").height() > $("#content").height()) {
    $("#content").height($("#sidebar").height());
  }
  //equalHeight($("#content, #sidebar"));



  // super gallery jcarousel
  $('.superGallery ul').jcarousel();
  $('.superGallery li a.enlarge').click(function(e) {
    //$('.superGallery .img-large > img').css('padding-top',(($('.superGallery .img-large').height()-$(this).attr('rel'))/2));
    $('.superGallery .img-large > img').attr('src',$(this).attr('href'));
    $('.superGallery a.img-large').attr('href',$(this).parent('li').attr('rel'));
    e.preventDefault();
  })



  // faq admin
  $('a.openForm').click(function(e) {
    //$("#content").height = '1000px';
    $(this).slideUp("fast");
    $(this).next().slideDown("fast");
    e.preventDefault();
    $('a.closeForm').click(function(e) {
      $(this).parent().slideUp("fast");
      $(this).parent().prev().slideDown("fast");
      e.preventDefault();
    })

  })



  // replace admin buttons
  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('btnInvisibleActive','eye_invisible.gif','eye_visible.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]+')');
      }
    );
  }


  // replace select element
  $.fn.styledSelect = function(options) {
  	var prefs = {
      coverClass : 'select-replace-cover',
  		innerClass : 'select-replace',
  		adjustPosition : { top:0, left:0 },
  		selectOpacity : 0
  		}
  	if (options) $.extend(prefs,options);
  	return this.each( function() {
  		var selElm = $(this);
  		selElm.wrap('<span><'+'/span>');
  		selElm.after('<span><'+'/span>');
  		var selReplace = selElm.next();
  		var selCover = selElm.parent();
  		selElm.css({
  			'opacity':prefs.selectOpacity,
  			'visibility':'visible',
  			'position':'absolute',
  			'top':0,
  			'left':0,
  			'display':'inline',
  			'z-index':1
  			});
  		selCover.addClass(prefs.coverClass).css({
  			'display':'inline-block',
  			'position':'relative',
  			'top':prefs.adjustPosition.top,
  			'left':prefs.adjustPosition.left,
  			'z-index':0,
  			'vertical-align':'middle',
  			'text-align':'left'
  			});
  		selReplace.addClass(prefs.innerClass).css({
  			'display':'block',
  			'white-space':'nowrap'
  			});
  
  		selElm.bind('change',function() {
  			$(this).next().text(this.options[this.selectedIndex].text);
  			}).bind('resize',function() {
  			$(this).parent().width('150px');
  			});
  		selElm.trigger('change').trigger('resize');
  		});
  }

  // replace select element
  $('#sortBy').styledSelect({adjustPosition:{top:-2, left:0}});

});