function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
$(function(){
	$('.navMain > li').hoverIntent({
		interval:	100,
		over:		topmenuOver,
		timeout:	100,
		out:		topmenuOut
	});
	$('#containerFilter, #containerView, #containerSort').hoverIntent({
		interval:	100,
		over:		topDropsOver,
		timeout:	100,
		out:		topDropsOut
	});
	$('#containerCart').hoverIntent({
		interval:	100,
		over:		cartDropOver,
		timeout:	500,
		out:		cartDropOut
	});
	$('#topSearchBox').focus(function() {
				if (this.value == 'Search for Products')
					this.value = '';
			}).blur(function() {
				if (this.value == '')
					this.value = 'Search for Products';
			}).autocomplete(top_server+'/autocomplete.php', {
//				resultsClass: 'searchDrop_results',
//				overClass: 'searchDrop_over',
				containerId: 'searchDrop',
				highlight: function(value, term) {
//					return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), '<span class="searchDrop_search-string">$1</span>');
					return '<a>'+jQuery(value).find('span:first').html(jQuery(value).find('span:first').html().replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), '<span class="searchDrop_search-string">$1</span>')).end().html()+'</a>';
//					alert(jQuery('<div>'+value+'</div>').find('span').length());
//					return $(value).find('span:first').html().replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), '<span class="searchDrop_search-string">$1</span>').html();
				},
				formatItem: function(row, i, max) {
					return '<a href="#"><span>'+row[0]+'</span><br /><span class="search-type">'+row[1]+'</span></a>';
				}
			}).result(function(event, data, formatted) {
				this.form.submit();
			});
	$('#topNewsletterBox')
		.focus(function() {
			if (this.value == 'Enter your email')
				this.value = '';
		})
		.blur(function() {
			if (this.value == '')
				this.value = 'Enter your email';
		});
});
function topmenuOver() {
//	$(this).children('div').slideDown('slow');
	$(this).addClass('active').children('div').show();
}
function topmenuOut() {
//	$(this).children('div').slideUp('fast');
	$(this).removeClass('active').children('div').hide();
}
function topDropsOver() {
	$(this)
		.children('a').each(function() {
			var $this = $(this);
			$this
				.removeClass($this.attr('classOut'))
				.addClass($this.attr('classOver'));
		})
		.end()
		.children('div')
//			.css('top', $(this).position().top)
			.slideDown(300);
}
function topDropsOut() {
//	$(this)
//		.children('div').slideUp('fast')
//		.children('div').hide();
	$(this)
		.children('a').each(function() {
			var $this = $(this);
			$this
				.addClass($this.attr('classOut'))
				.removeClass($this.attr('classOver'));
		})
		.end()
		.children('div').hide(10);
}

function cartDropOver() {
	$(this)
		.find('div.bagDrop')
			.css('top', $(this).position().top)
			.slideDown(300);
}
function cartDropOut() {
	$(this)
//		.find('div.bagDrop').slideUp('fast');
		.find('div.bagDrop').hide(10);
}

function cartShow(timeout, not_hide)
{
	if ('undefined' == typeof not_hide)
	{
		not_hide = false;
	}
	$('#containerCart').each(function() {
		var _this = this
		cartDropOver.apply(_this);
		if (!not_hide)
		{
			setTimeout( function(){ cartDropOut.apply(_this); } , timeout);
		}
	});
}
function cartUpdate(cnt, sum)
{
	$('#topCartText').html('Shopping Bag ('+cnt+') &pound;'+sum);
}
function cartRemove(products_id, sizes_id)
{
	xajax_ajaxRemoveFromCart('<xjxquery><q>products_id='+products_id+'&sizes_id='+sizes_id+'</q></xjxquery>');		
}
