jQuery.noConflict();
(function ($) {

	var h = window.location.hostname;
	$.extend($.expr[':'], {
		external: function (o) {
			return o.hostname !== h && o.hostname !== '';
		}
	});
	$.fn.external = function () {
		return this.filter(':external');
	};

	$(function() {
			
		//image change hover
		$('.shop-links li a').each(function (i, e) {
			var image = $(e).find('img'),
			oldImage = image.attr('src'),
			newImage = oldImage.replace('.png', '-hover.png'),
			preLoadImage = new Image();
			
			preLoadImage.src = newImage;
			
			$(e).hover(function () {
				image.attr('src', newImage);
			}, function () {
				image.attr('src', oldImage);
			});
		});
		
		//Display Email Address
		
		$('#contact li:eq(1)').html('<span>email:</span> <a href="mailto:info@windowwallpaper.co.uk?subject=Website Enquiry">info@windowwallpaper.co.uk</a>');
		
		
		//external links
		$('a:external, a[rel="external"]').click(function (e) {
			window.open(this.href);
			e.preventDefault();
		});
		
	});
	
	$(window).load(function () {

		//Home page rollover
		var new_w = 299,
		new_h = 290;
		 
		$('.featured-categories li div').each(function (i, e) {

			var self = $(e),
			h = self.height(),
			w = self.width(),
			pos = self.position(),
			t = pos.top,
			l = pos.left,
			desc = $('.product-description', self),
			parent = self.parent();
		
			self.bind('mouseenter', function () {
				parent.css({
					zIndex: 1000
				});			
				self.stop().css({
					zIndex: 1000
				}).animate({
					height: new_h,
					left: 0 - (new_w - w) / 2,
					top: 0 - (new_h - h) / 2,
					width: new_w
				}, function () {
					self.height('auto');
					desc.show();
				});
			});
			
			self.bind('mouseleave', function () {
				
				parent.css({
					zIndex: 1
				});
				self.css({
					zIndex: 1
				}).animate({
					height: h,
					left: l,
					top: t,
					width: w
				}, function () {
					desc.hide();
				});
			});
		
		});

		//Compare image rollover
		$('#gallery img').each(function (i, el) {
			var self = $(el),
			w = self.width(),
			h = self.height(),
			p = self.css('position'),
			pos = self.position(),
			t = pos.top,
			l = pos.left,
			new_h = Math.floor(h*1.5),
			new_w = Math.floor(w*1.5);
			
			$(this).parent().height(h);
			
			self.hover(function () {
				var self = $(this);
				self.parents('li').css({
					position: 'relative',
					zIndex:100
				});
				self.css({
					left: l,
					position: 'absolute',
					top: t,
					zIndex: 500
				}).animate({
					height: new_h,
					left: 0 - (new_w - w) / 2,
					top: 0 - (new_h - h) / 2,
					width: new_w
				}, 'fast');
			}, function () {
				var self = $(this);
				self.parents('li').css({
					position: 'relative',
					zIndex:1
				});
				self.animate({
					height: h,
					left: l,
					top: t,
					width: w
				}, 'fast', function () {
					self.css({
						position: p,
						zIndex: 1
					})
				});
			});
		});
		
	});

}(jQuery));
