$(document).ready(function(){
	function addMega(){
		$(this).addClass("hovering");
	}
	function removeMega(){
		$(this).removeClass("hovering");
		$("#search-quickresults li").remove();
	}
	var megaConfig = {
		interval: 50,
		sensitivity: 4,
		over: addMega,
		timeout: 200,
		out: removeMega
	};
	if (($.browser.msie && $.browser.version>="8.0") || !$.browser.msie) {
		$("li.mega").hoverIntent(megaConfig);
		$("li.megasub").hoverIntent(megaConfig);
		$('.search-bar').hoverIntent(megaConfig);
	}
	$('#searchformtop').submit(function(){
		if($('#search-text').val() == 'Search for keywords or product code') return false;
	});
});
function load_items(start, number) {
	if ( start === undefined ) {start = 1;}
	if ( number === undefined ) {number = 3;}
	$.ajax({url:"assets/items/featured.xml", success:function(xml){
		var count = 1
		$("#itemlist div, #itemlist p, #itemlist h2").remove();
		if((start-number) > 0) {$("#itemlist").append('<p id="list-arrow-up" onclick="load_items(' + (start - number) + ', ' + number  + ')"></p>');} else {$("#itemlist").append('<h2>Featured Items</h2>')}
		$(xml).find('item').each(function(){
			count = count + 1;
			if (count <= (number + start) && count > start) 
			{
				$("#itemlist").append('<div><div class="image"><a href="' + $(this).find('url').text() + '"><img src="' + $(this).find('imgurl').text() + '" alt="' + $(this).find('name').text() + '" /></a></div><a href="' + $(this).find('url').text() + '"><h4>' + $(this).find('name').text() + '</h4></a><br />Our Price <span class="green bold">&pound;' + $(this).find('price').text() + '</span><br />RRP: <s>&pound;' + $(this).find('rrp').text() + '</s><br />You save <span class="blue bold">' + $(this).find('save').text() + '%</span><br /><a href="' + $(this).find('url').text() + '">View Product Page</a></div>');
			}
		});
		if((start+number) <= count-1) {$("#itemlist").append('<p id="list-arrow-down" onclick="load_items(' + (start + number) + ', ' + number  + ')"></p>');}
	}});
}
function ajax_search() {
	$.ajax({url:"assets/words.txt", success:function(txt){
		$("#search-quickresults li").remove();
		var count = 1;
		var words = txt.split('|');
		for(var i in words)
		{
			if (words[i].toLowerCase().indexOf($('input:text[name=s]').val().toLowerCase()) >= 0 && count <= 5) {
				$("#search-quickresults ul").append('<li><a href="javascript:void" onclick="$(\'input#search-text\').val($(this).html())">' + words[i] + '</a></li>');
				count = count + 1;
			}
		}
	}});
}
