$(document).ready(function(){
	
	$('#Gallery').GalleryFader({
	    ImageViewerClass: '.mainImage',
		ImageViewerWidth: 734,
		ImageViewerHeight: 327,
	    ImageListClass: '.images',
	    FadeTimer: '5s'
	});
	
	
	
	//$('#imageflow').imageflow();
	/*$("#imageflow .images").carousel({
	    animateByMouse: true,
	    pausable: false,
	    radius: 350,
	    distance: 0.5,
	    direction: 'left',
	    animate: 0.005,
	    tilt: 35
	});*/
	$("#imageflow").CloudCarousel(		
		{			
			xPos: (786/2),
			yPos: 32,
			xRadius: 175,
			yRadius: -30,
			bringToFront: true,
			buttonLeft: $("#right-but"),
			buttonRight: $("#left-but"),
			altBox: $("#alt-text"),
			titleBox: $("#title-text"),
			autoRotate: 'left',
			autoRotateDelay: 5000,
			mouseWheel: true,
			minScale: 0.5
		}
	);
	$("#imageflow-large").CloudCarousel(		
		{			
			xPos: (989/2),
			yPos: 32,
			xRadius: 300,
			yRadius: -30,
			bringToFront: true,
			buttonLeft: $("#right-but"),
			buttonRight: $("#left-but"),
			altBox: $("#alt-text"),
			titleBox: $("#title-text"),
			autoRotate: 'left',
			autoRotateDelay: 5000,
			mouseWheel: true,
			minScale: 0.5
		}
	);
	/*
	$('#pagetext').ezColumns({
		columns: 2
	});
	*/
	$("#gMap").gMap({		
		latitude: 53.22946790187269,
		longitude: -0.471038818359375,
		markers: [{ latitude: 53.22127052071421,  
                    longitude: -0.4274100065231323,
                    html: "<h2>Grundy Agricultural</h2><p>Five Mill Lane<br />Washingborough<br />Linconshire<br />LN4 1AF</p>"
		}],
        zoom: 11
	});
	
	$('#infoTabs').tabs();
	$('#feedbackTabs').tabs();
	$('.jqzoom').jqzoom({
		zoomWidth: 440,
		zoomHeight: 400,
		xOffset: 32,
        yOffset: -20,
		showEffect:'fadein',
		hideEffect:'fadeout',
		fadeoutSpeed: 'slow'
	});
	$('#AddToBasket .item').ajaxform({
		updateObject: "#cartValue",
		updateLocation: "/cart/miniCart.php",
		updateData: {},
		updateFunction: function() {
			$('#your-basket').click();
		}
	});
	
	var priceGrid = $('#AddToBasket .item').find('input[name="price_grid"]');
	var size = $('#AddToBasket .item').find('select[name="size"]');
	var colour = $('#AddToBasket .item').find('select[name="colour"]');
	var price_grid = $('#AddToBasket .item').find('.price_grid');
	var amount = $('#AddToBasket .item').find('input[name="amount"]');
	var submit = $('#AddToBasket .item').find('input[name="submit"]');
	
	if (priceGrid.val() == 1) {
		updatePrice();
	}
	
	size.change(function(){
		updatePrice();
	});
	colour.change(function(){
		updatePrice();
	});
	
	function updatePrice() {
		$.ajax({
			url: '/price_grid.php',
			dataType: 'json',
			data: { 'size_id':size.val(), 'colour_id':colour.val() },
			type: 'post',
			beforeSend: function(){
				price_grid.html('updating...');
			},
			success: function(data){
//				$.each(data, function(key, val){
					if ((data.status) == "Available") {
						price_grid.html("<span class='strikeout'>Was &pound;" + data.rrp + "</span><br><span class='red'>Now &pound;" +data.price+"</span>");
						amount.val(data.price);
						submit.show();
					} else {
						price_grid.html("<span class='red'>Out of Stock</span>");
						amount.val('');
						submit.hide();
					}
//				}) 
				
			}
		});		
	}
	
	
	
	
	
	//$('#feedbackForm').css({'height':'0px', 'display':'none'})
	$('#feedbackForm').parent().append('<button id="WriteReview">Write a review</button>');
	$('#WriteReview').click(function(){
		$(this).remove();
		//$('#feedbackForm').animate({'height':'190px', 'display':'block'}, 1000);
		$('#feedbackForm').css({'display':'block'})//'height':'190px', 
	})
	
	
	$('#feedbackForm').ajaxform({
		updateObject: "#feedback .feedback-middle",
		updateLocation: "/feedback.php",
		updateData: { 'productID': $('#feedback form').attr('rel') },
		updateFunction: function() { $('.stars').stars(); }
	});
	$('#question form').ajaxform({
		updateObject: "#question .feedback-middle",
		updateLocation: "/question.php",
		updateFunction: function() { $('#question form').html('Form sent') }
	});

	
	
	$('.stars').stars();
	$('#header').basket();
	
	
	
	$('#twitter').getTwitter({
		userName: 'GEquestrian',
		numTweets: 3,
		loaderText: "Loading tweets...",
		slideIn: true,
		showHeading: true,
		headingText: "Latest Tweets",
		showProfileLink: true
	})	
	
//	swapImages()
})

function swapImages() {
	$('#moreImages img').click(function(){
	    // objects
	    var thumb = $(this);
	    var main = $('#Product .product-shadow-middle img.main');
	    var link = $('#Product .product-shadow-middle a');
	    
	    // object info
	    var thumbalt = thumb.attr('alt');
	    var thumbrel = thumb.attr('rel');
	    var thumbimg = thumb.attr('src');
	    var mainalt = main.attr('alt');
	    var mainimg = main.attr('src');
	    
	    // swap the variables around
	    thumb.attr('alt', mainimg);
	    thumb.attr('src', mainalt);
	    thumb.attr('rel', link.attr('href'));
	    
	    main.attr('alt', thumbimg);
	    main.attr('src', thumbalt);
	    
	    link.attr('href', thumbrel);
	});
}

function contactForm() {
	
}
