window.onmousemove=followCursor;
var posx = 0;
var posy = 0;
function followCursor(e){
	e = e || window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	} else 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	document.getElementById('click').style.left=(posx+10)+'px';
	document.getElementById('click').style.top=(posy-10)+'px';
}
var zoomOn = 0;
var xOffset =0;
var yOffset =0;
$(function(){
		$(document).ready(function(){
			$('input[title]').blur(function() {
			if($(this).val() == '') {
				$(this).addClass('hinting').val($(this).attr('title'));
				$(this).one('focus', function() {
					$(this).removeClass('hinting').val('');
				});
			}
		}).trigger('blur');
		/*$('.productdetails .image').mouseover(function(){
			$('.productdetails .details').hide();
			$('.largeImageContainer').show();
			//alert(xOffset+','+yOffset);
			$(this).css({'cursor':'all-scroll'});
			zoomOn=1;
		});
		$('.productdetails .image').mousemove(function(e){
			if (zoomOn==1){
				xOffset = (posx-435)/2.5;
				yOffset = (posy-295)/2.8;
				$('.largeImage').css({'margin-top':'-'+yOffset+'%','margin-left':'-'+xOffset+'%'});
			}
		});
		$('.productdetails .image').mouseleave(function(){
			if (zoomOn==1){
				$('.productdetails .details').show();
				$('.largeImageContainer').hide();
				//alert(xOffset+','+yOffset);
				$(this).css({'cursor':'pointer'});
				zoomOn=0;
			}
		});*/
		$('.productdetails .arrows div').hover(function(){
				$(this).stop().animate({ color: "#ff3300"}, 300);
			},function(){
				$(this).stop().animate({ color: "#e9e9e9"}, 300);
		});
		$('.productdetails .gallery .thumb img').click(function(){

			$('.productdetails .image img').attr('src', '/images/products/'+$(this).attr('rel'));
			$('.productdetails .image a').attr('href', '/images/products/large/'+$(this).attr('rel'));
			$('.fullImage a').attr('href','/images/products/large/'+$(this).parent().attr('rel'));

		});
		$('#colour').change(function(){
			if ($(this).val() != '') {
				var size = $('#size').val();
				var id = $('#pdid').val();
				var colour = $(this).val();
				$.ajax({
					type: "POST",
					url: "/include/cart/checkStock.php",
					data: "size="+size+"&id="+id+"&colour="+colour,
					success: function(msg){
						if (msg > 0) {
							$('#stock_id').val(msg);
							$('#btnAddToCart').val('ADD TO CART');
							$('#btnAddToCart').attr('disabled', '');
							
						} else {
							$('#btnAddToCart').val('OUT OF STOCK');
							$('#btnAddToCart').attr('disabled', 'true');
						}
					}
				});
			} else {
				$('.addToCartButton').val('SELECT SIZE & COLOUR');
			}
		});
		$('#size').change(function(){
			document.getElementById('colour').length=0;
			document.getElementById('colour').options[0] = new Option("Select colour",'');
			$('.addToCartButton').val('SELECT SIZE & COLOUR');
			var size = $(this).val();
			var id = $('#pdid').val();
			$.ajax({
				type: "POST",
				url: "/include/cart/getColours.php",
				data: "size="+size+"&id="+id,
				success: function(msg){
					document.getElementById('colour').length=0;
					document.getElementById('colour').options[0] = new Option("Select colour",'0');
					var stringArray = msg.split('#');
					for (var i=1; i < (stringArray.length); i++){
						idSeperate = stringArray[i-1].split('*');
						document.getElementById('colour').options[i] = new Option(idSeperate[0],idSeperate[0]);
						idSeperate = "";
					}
				}
			});
		});
		$('.addToCartButton').click(function(){
			if ($('#size').val()!='0' && $('#colour').val()!='0' ){
				$.ajax ({
					type:	"POST",
					url: 	'/include/cart/addToCart.php',
					data:	's='+$('#stock_id').val(),
					success: function (msg) {
						if (msg) {
							if ($('#itemAmount').html()=='No') {
								$('#itemAmount').html('1');
								$('#itemsTop').html('item');
								$('.shopBag').show();
							} else if ($('#itemAmount').html()=='1') {
								$('#itemAmount').html(parseInt($('#itemAmount').html())+1);
								$('#itemsTop').html('items');
							} else {
								$('#itemAmount').html(parseInt($('#itemAmount').html())+1);
							}
							if (msg == 2) {
								$('.addToCartButton').fadeOut('fast');
								$('#outOfStock').fadeIn('fast');
							}
						}
					}
				});
			} 
		});
		$('.productdetails .gallery .thumb img').hover(function(){
				$('#click').stop().show().animate({'opacity':'1'},100);
			}, function() {
				$('#click').stop().animate({'opacity':'0'},100,function(){
					$(this).hide();
				});
			}
		);
		$('.arrows div').click(function() {
			var id = $(this).attr('rel');
			var cat = $('#catid').val();
			window.location.href='/shop/'+cat+'/'+id;
		});
		$('#t1 td').hover(function(){
				$(this).find('#productdetails').stop().animate({ backgroundColor: "#e9e9e9"}, 300);
			} , function(){
				$(this).find('#productdetails').stop().animate({ backgroundColor: "#fff"}, 300);
		});
		var galPos = 0;
		$('.galuparrow').click(function(){	
			if (galPos<0) {
				galPos++;
				$('.galslider').animate({'marginTop':(galPos*86)+'px'});
			}
		});
		$('.galdownarrow').click(function(){
			if (galPos > 5-$('#gallerynum').val()){
				galPos--;
				$('.galslider').animate({'marginTop':(galPos*86)+'px'});
			}
		});
		
		$('#t1 td').click(function(){
			var id = $(this).attr('class');
			window.location.href=id;
		});
	});
});
			