(function ($) {
	$(document).ready(function() {
					   $('.mmhide').hide();
					});
				
	
	
	 if (window.innerWidth <= 768) {
		 $('.parent_filter').removeClass('expand');
	 }
	
	//$('.styled-select select').SumoSelect();
	
	/*$(window).load(function() { */
	  /*if ($('html').hasClass('desktop')) {
		  $('#stuck_container').TMStickUp({
		  })
	  }*/  
	  
	  wrapEl();
		dropDown();
		
	/*});*/
	
	
	
	function dropDown() 
	{
		
		elementClick = '#header_assets .current';
		elementSlide =  '.toogle_content';       
		activeClass = 'active';			 

		$(elementClick).on('click', function(e){
			e.stopPropagation();
			var subUl = $(this).next(elementSlide);
			if(subUl.is(':hidden'))
			{
				subUl.slideDown();
				$(this).addClass(activeClass);	
			}
			else
			{
				subUl.slideUp();
				$(this).removeClass(activeClass);
			}
			$(elementClick).not(this).next(elementSlide).slideUp();
			$(elementClick).not(this).removeClass(activeClass);
			e.preventDefault();
		});

		$(elementSlide).on('click', function(e){
			e.stopPropagation();
		});

		$(document).on('click', function(e){
			e.stopPropagation();
			if (e.which != 3)
			{
				var elementHide = $(elementClick).next(elementSlide);
				$(elementHide).slideUp();
				$(elementClick).removeClass('active');
			}
		});
	}
	
	
	
	$(document).ready(function(){

	/* roll over cart */
	var cart_block = new HoverWatcher('#header .cart_block');
	var shopping_cart = new HoverWatcher('#header .shopping_cart');
	var is_touch_enabled = false;

	if ('ontouchstart' in document.documentElement)
		is_touch_enabled = true;

		$(document).on('click', '#header .shopping_cart > a:first', function(e){
			e.preventDefault();
			e.stopPropagation();

			// Simulate hover when browser says device is touch based
			if (is_touch_enabled)
			{
				if ($(this).next('.cart_block:visible').length && !cart_block.isHoveringOver())
					$("#header .cart_block").stop(true, true).slideUp(450);
				else if (parseInt($('.ajax_cart_quantity').html()) > 0)
					$("#header .cart_block").stop(true, true).slideDown(450);

				return;
			}
			else
				window.location.href = $(this).attr('href');
		});

		$("#header .shopping_cart a:first").hover(
			function(){
				if (parseInt($('.ajax_cart_quantity').html()) > 0)
					$("#header .cart_block").stop(true, true).slideDown(450);
			},
			function(){
				setTimeout(function(){
					if (!shopping_cart.isHoveringOver() && !cart_block.isHoveringOver())
						$("#header .cart_block").stop(true, true).slideUp(450);				
				}, 200);
			}
		);

		$("#header .cart_block").hover(
			function(){
			},
			function(){
				setTimeout(function(){
					if (!shopping_cart.isHoveringOver())
						$("#header .cart_block").stop(true, true).slideUp(450);
				}, 200);
			}
		);
		$("#header .isStuck .shopping_cart a:first").hover(
			function(){
				if (parseInt($('.ajax_cart_quantity').html()) > 0)
					$("#header .isStuck .cart_block").stop(true, true).slideDown(450);
			},
			function(){
				setTimeout(function(){
					if (!shopping_cart.isHoveringOver() && !cart_block.isHoveringOver())
						$("#header .isStuck .cart_block").stop(true, true).slideUp(450);				
				}, 200);
			}
		);

		$("#header .isStuck .cart_block").hover(
			function(){
			},
			function(){
				setTimeout(function(){
					if (!shopping_cart.isHoveringOver())
						$("#header .isStuck .cart_block").stop(true, true).slideUp(450);
				}, 200);
			}
		);

		
	});


	function HoverWatcher(selector)
	{
		this.hovering = false;
		var self = this;

		this.isHoveringOver = function(){
			return self.hovering;
		}

		$(selector).hover(function(){
			self.hovering = true;
		}, function(){
			self.hovering = false;
		})
	}
	
	function wrapEl(){
		$( "table" ).each(function( index ) {
			if(!$(this).hasClass('responsive')){
				$(this).wrap('<div class="table_div"></div>');
				if($(this).width()>$(window).width()){
					$( "<div class='slide_icon generated_el'></div>" ).insertBefore( $(this).parent() );
					$( "<div class='spacer10 generated_el'></div>" ).insertBefore( $(this).parent() );
					$( "<div class='slide_icon generated_el'></div>" ).insertAfter( $(this).parent() );
					$( "<div class='spacer10 generated_el'></div>" ).insertAfter( $(this).parent() );
				}
			}
		});
	}
	
	function checkEl(){
		$('.generated_el').remove();
		$( "table" ).each(function( index ) {
			if(!$(this).hasClass('responsive')){
				$(this).unwrap();
			}
		});
		
		wrapEl();
	}
	
	$( window ).resize(function() {
		checkEl();
	});	
	
	
	
	
		/* EqualHeights
	 ========================================================*/
		var o = $('.equal');
		if (o.length > 0) {
			$(document).ready(function () {
				$('.equal').matchHeight();
			});
		}
		
		
		
	var o = $('#tabs');
		if (o.length > 0) {
			$(document).ready(function () {
				$( "#tabs" ).tabs(); 
			});
		}
		
		
		
	
	
	
})(jQuery);

