jQuery(document).ready(function() {
  
	//set position floating div
	jQuery('#floatdiv').css({"left":jQuery('#wrapper').offset().left+jQuery('#wrapper').width()+10});
	
	jQuery(window).resize(function() {
 	 	jQuery('#floatdiv').css({"left":jQuery('#wrapper').offset().left+jQuery('#wrapper').width()+10});
	});

	//accordion menu setting
	jQuery('#accordion').accordion({
			header: '.head_accord',
			autoheight: false,
			active:false,
			alwaysOpen: false
	});
  
  jQuery('.tools a.share').mouseover(function () {
     jQuery('.sharediv').show();
  });

  jQuery('.sharediv').mouseleave(function () {
      jQuery(this).hide();
  });
  
  if (jQuery(".tabsection").length > 0)
  {
    jQuery(".tabsection").hide();
    jQuery("#tabsection1").show();
  }
  
  if (jQuery(".contentInner hr").length > 0)
  {
    jQuery(".contentInner hr").hide();
  }
	
	//share buttons window transparent
	jQuery('#social-icons a').mouseover(function() {
		jQuery(this).css({"z-index":1200});
		jQuery(this).find("span").css({"display":"block"});
		jQuery('#lightbox_background').animate({"opacity": "show"}, 10);
	}).mouseout(function() {
		jQuery(this).css({"z-index":1});
		jQuery(this).find("span").css({"display":"none"});
		jQuery('#lightbox_background').css({"display":"none"});
	});
  
	//tab switch
	//share buttons window transparent
	jQuery('.tabber li').mouseover(function() {
			if(!jQuery(this).hasClass('active')) {
				jQuery(this).addClass('hover');
			}
			
	}).mouseout(function() {
			if(!jQuery(this).hasClass('active')) {
				jQuery(this).removeClass('hover');
			}
	});
	
	jQuery('.tabber li').click(function() {
    
			jQuery(this).parents(".tabber").find("li.active").removeClass("active");
			jQuery(this).removeClass('hover');
			jQuery(this).addClass('active');
			
			var currentTab = jQuery(this).attr('tab');
			jQuery(".tabsection").hide();
			
			jQuery('#'+currentTab).show();
			
			jQuery('#'+currentTab).find('#'+currentTab+'_container').mCustomScrollbar("vertical",900,"easeOutCirc",1.05,"auto","yes","no",0);;

	});


  if (jQuery("#tabsection1_container").length > 0)
  {
    jQuery("#tabsection1_container").mCustomScrollbar("vertical",900,"easeOutCirc",1.05,"auto","yes","no",0);
  }
  if (jQuery("#mcs5_container").length > 0)
  { 
    jQuery("#mcs5_container").mCustomScrollbar("horizontal",500,"easeOutCirc",1,"fixed","yes","yes",20);
  }

  if (jQuery("#slider").length > 0)
  { 
    jQuery("#slider").nivoSlider({
        effect:"fade"
    });
  }

  jQuery('a[rel*=facebox]').facebox({
    loadingImage : '/facebox/loading.gif',
    closeImage   : '/facebox/closelabel.png'
  });
  
  
  // search blah blah
  var ajaxHandler = null;
  var timerId = null;
  jQuery("#visualsearch_inputitem").bind("focus", function(){
      jQuery(this).val('');
  });
  jQuery("#visualsearch_inputitem").bind("keyup", function(){
    if (jQuery(this).val().length >= 3){
      var keyword = jQuery(this).val();
      if (timerId != null) window.clearTimeout(timerId);
      timerId = window.setTimeout(function(){
        if (jQuery(this).data('searching') == true){
          ajaxHandler.abort();
        }
        ajaxHandler = jQuery.ajax({
          beforeSend: function(){
            jQuery("#visualsearch_inputitem").data('searching', true);
            
            jQuery("#search_button").removeClass();
            jQuery("#search_button").addClass("s_searching");
          },
          url: '/mn/page/search',
          type: 'POST',
          data: {keyword : keyword},
          complete: function(){
            jQuery("#visualsearch_inputitem").data('searching', false);
          },
          success: function(data){
            jQuery('#visualsearch_result').html(data);
            transparency_enable();
            
            jQuery("#search_button").removeClass();
            jQuery("#search_button").addClass("s_normal");
          }
        });
      }, 1000);
    }
  });
  
  jQuery("tr:last").addClass('last-row');

});

function transparency_enable() {
  document.getElementById('visualsearch_transparency').style.display='block';
}

function transparency_disable() {
  document.getElementById('visualsearch_transparency').style.display='none';
}

function findquick_none () {
  document.getElementById("visualsearch_inputitem").value = "Хайлт";
  transparency_disable();
  jQuery('#visualsearch_result').html('');
}

function printPopup(url) {
  window.open(url, "www.xacbank.mn, Right bank", 
  "status = 1, height = 700, width = 770, resizable = 0, scrollbars=1" )
}

function compProducts(language) {
  var fields = jQuery('#my-list input:checked');
  
  if(language == 'mn') {
    msg = 'Та 1-с олон бүтээгдэхүүн харьцуулна уу';
  } else {
    msg = 'Please. you must check two and more products';
  }
  
  if(fields.length <= 1) {
    alert(msg);
    return false;
  }
  
  document.forms['compare_form'].submit();
}
