$(document).ready(function(){
	inittabs();
	/*initQty();*/
	initMap();
});

$(window).load(function(){
	shiftRights();
	shiftLefts();
});

function inittabs() {
	var _tabset = $('.tabset');
		
	_tabset.each(function(){
		var _tabsetEl = $(this).find('a');
		hideTabs();
		_tabsetEl.each(function(){
			if ($(this).hasClass('active'))
			$($(this).attr('href')).show();

			$(this).click(function(){
				if (!$(this).hasClass('active')) {
					hideTabs();
					_tabsetEl.removeClass('active');
					$(this).addClass('active');
					$($(this).attr('href')).show();
				}
				return false;
			});
		});
		
		function hideTabs() {
			_tabsetEl.each(function(){
				$($(this).attr('href')).hide();
			});
		}
	});
}

function initQty() {
	var _qty = $('.qty-box');
	
	_qty.each(function(){
		var _input = $(this).find('input.text');
		var _button = $(this).find('.area');
		var _value = parseInt($(this).attr('value'));
		if (_value)
			_button.show();
		else _button.hide();

		_input.keyup(function(){
			_value = parseInt($(this).attr('value'));
			if (_value)
				_button.show();
			else _button.hide();
		});
	});
}

function initMap(){
	var _list = $('.map-list');
	var _popup = '';
	var t;	
	
	_list.each(function(){
		var _item = $(this).find('>li');
		_popup = _item.find('.tooltip');
		_item.each(function(){
			$(this).mouseover(function(){
			
				// check for any timeouts and remove
				var t = $(document).data('timeout');
				clearTimeout(t);
				
				_item.removeClass('active');
				$(this).addClass('active');
				
				_item.css('z-index', 99);
				$(this).css('z-index', 100);
				//return false;
			});
			$(this).mouseout(function() {
				$(document).mousedown();						  
			});
		});
		$(document).bind('mousedown', function(e){
			if(_popup && _popup.is(':visible')){
				e = e || event;
				var t = e.target || e.srcElement;
				t = $(t);
				if(t.parents('li').length == 0){
					_item.removeClass('active');
				}
			}
		});
	});


	$(document).ready(function() {
		$(".side-nav li").mouseover(function() {						 
			// check for any timeouts and remove
			var t = $(document).data('timeout');
			clearTimeout(t);								 
											 
			// get the id we want to popup
			var id = $(this).attr('id');
			var id_split = id.split('-');
			
			// mark active popup and init mouseover
			$("#cat-popup-"+id_split[2]).mouseover();			
		});
		
		$(".side-nav li").mouseout(function() {			
			var t = setTimeout("$(document).mousedown();", 3000);	
			$(document).data('timeout', t);
		});
		
		$(".sub-list").mouseover(function() {						 
			// check for any timeouts and remove
			var t = $(document).data('timeout');
			clearTimeout(t);								 
											 
			// get the id we want to popup
			var id = $(this).attr('id');
			
			// mark active popup and init mouseover
			$(document).mousedown();
			$("#cat-popup-"+id).mouseover();			
		});
		
		$(".sub-list").mouseout(function() {
			var t = setTimeout("$(document).mousedown();", 3000);	
			$(document).data('timeout', t);
		});
   });	
}

function shiftRights()
{
	var rights = $('.invright');
	var arrow;
	
	rights.each(function(){
		$(this).css('top', -($(this).height()/2)+7);
		arrow = $(this).find('.leftpoint');
		arrow.css('top', $(this).height()+1);
	});
}

function shiftLefts()
{
	var lefts = $('.invleft');
	var arrow;
	
	lefts.each(function(){
		$(this).css('top', -($(this).height()/2)+7);
		arrow = $(this).find('.rightpoint');
		arrow.css('top', $(this).height()+1);
	});
}

