$.expr[':'].icontains = function(obj, index, meta, stack){

var elText = (obj.textContent || obj.innerText || jQuery(obj).text() || '').toLowerCase();
var valMatch = meta[3].toLowerCase();

if (elText.substr(0,valMatch.length) == valMatch) {
	return true;
}
else {
	return false;
}
};

this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.rel +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

this.replaceP = function(){	
	$(".replace").focus(function() {
		$(this).replaceWith('<input class="left-input replaced" type="password" name="password" />');
		$(".replaced").focus();
	});
};

this.manu = function(){
	var location = $("#location").attr('href');
	$("#manu-input").hover(
	function() {
		var position = $(this).position();
		var height = $(this).height();
		$("#manu").css({
			top: position.top + height + 14,
			left: position.left,
			display: 'block'
		});
		$("#manu li").css({ display: 'block' });
	});
	$("#outer-wrapper").click( function() {
		$("#manu li").css({ display: 'none' });
	});
	$("#manu li").click(function() {
		$("#manu-input").attr('value', $(this).text());
		$("#location").attr('href', location + $(this).attr('type'));
		$("#manu li").css({ display: 'none' });
		$("#manu-input").removeClass('init-txt').focus();
	});
	$("#manu-input").focus( function() {
		$("#manu-input.init-txt").val('').removeClass('init-txt');
		$(this).keyup(function(x) {
			$("#location").attr('href', location);
			$("#manu li").css({ display: 'none' });
			$("#manu li:icontains(" + $(this).val() + ")").css({ display: 'block' });
			if ($("#manu li:icontains(" + $(this).val() + ")").text() == $(this).val()) {
				$("#manu li:icontains(" + $(this).val() + ")").css({ display: 'none' });
				var value = $("#manu li:icontains(" + $(this).val() + ")").attr('type');
				$("#location").attr('href', location + value);
			}
		}).keyup();
	});
};

this.bookmark = function(){	
	$("a.bookmark").click(function() {
		bookmarkurl = 'www.supplies4bathrooms.co.uk';
		bookmarktitle = 'Norbreck bathroom design centre';
		if (document.all) {
		window.external.AddFavorite(bookmarkurl,bookmarktitle);
		}
		else if (window.sidebar) {
		        alert('This feature only works for Internet Explorer, use Control+D to bookmark This website');
		}
		else if (window.opera && window.print) {
		        alert('This feature only works for Internet Explorer, use Control+T to bookmark This website');
		}
		return false;
	});
};

// starting the script on page load
$(document).ready(function(){
	imagePreview();
	replaceP();
	bookmark();
	manu();
});
