// JavaScript Document

	$(document).ready(function(){
		jQuery('a[rel*=facebox]').facebox();
		/*$("#left-nav ul li a").click(function() {
			var myids = $(this).attr("rel");
			var status = $("#"+myids).css("display");
			if(status !== "none"){
				$("#"+myids).slideUp();
			} else {
				$("#"+myids).slideDown();
			}
			if(myids) return false;
		});*/
		
		$(".image-pane .small").click(function() {
			var imSrc = $(this).attr("src");																 
			$("#big-image").fadeOut("slow", function() {
				$("#big-image").html("<img src='"+imSrc+"' class='big' alt='big image' />");		
			});
			$("#big-image").fadeIn("slow");
		});
		$("input[@name='del_type']").click(function() {
			productPrice();
		});
		$("input[@name='qq_units']").change(function() {
			productPrice();
		});
		$("input[@name='qq_units']").keyup(function() {
			productPrice();
		});
		$("input[name='qq-get']").click(function() {
																						
			var mqty = $("input[name='qq_units']").val();
			var myThis = $("input[name='del_type']:checked");
			var myDel = $(myThis).attr("value");
			var myPost = $("input[name='qq_postcode']").val();
			var prod_id = $("input[name='product_id']").val();
			// alert(mqty+" ---- "+myThis+" ---- "+myDel+" ---- "+myPost+" ---- "+prod_id);
			//alert(myDel);
			$.get("data-get.php", { type: "quickQuote", qty: mqty, postcode: myPost, prod: prod_id, delType: myDel }, function(data) {
				$(".qq-details").html(data);
				$(".qq-price").html("&nbsp;");
				jQuery('a[rel*=facebox]').facebox();
			});
			return false;
		});
		$("input[@name='order_shipping_postcode']").keyup(function() {
			//alert("here");
			var postcode = $(this).val();
			$("#total-details").load("checkout.php #total-inner", { postaction: "updatePostcode", pcode: postcode });
		});
		$("form[name=frmSearch]").submit(function() {
			//alert("here");
			var mySearch = $("input[@name='search_txt']").val();
			//alert(mySearch);
			$.get("data-get.php", { type: "searchResults", Search: mySearch }, function(data) {
				$("#right-container").html(data);
			});
			return false;
		});
		ajaxPaging();
		$("ul#gallery").innerfade({ speed: 'slow', timeout: 10000, type: 'sequence' }); 
		
	});
		function innerJq() {
			$(".basket-func").click(function() {
				var myid = $(this).attr("rel");
				var type = $(this).attr("rev");
				aElements = new Array('basket'+myid, 'subtotal'+myid);
				var updateStr = '<img vspace="1" src="images/icon_wait.gif" alt="Working" width="14" height="14" align="texttop" />';
				for(i=0;i<aElements.length;i++) {
					$("#"+aElements[i]).html(updateStr);
				}
				$("#right-container").load("basket.php #innerBasket", { action: type, id: myid }, function() {
					$.get("data-get.php", { type: "basket" }, function(data) {
						$("#basket a").html(data);
					});
					innerJq();	
				});
				return false;
			});

		}
		function ajaxPaging() {
			$(".paging a").click(function() {
				//alert("here");
				var mySrc = $(this).attr("href");
				//alert(mySrc);
				if ($("#right-container-index").html() != null) {
					$("#right-container-index").load(mySrc+" #results", function() {
						ajaxPaging();												   
					});
				}	else {
					$("#right-container").load(mySrc+" #results", function() {
						ajaxPaging();												   
					});
				} 
				//$.get("data-get.php", { type: "searchResults", Search: mySearch }, function(data) {
				//	$("#right-container").html(data);
				//});
				return false;
			});
		}
		function productPrice() {
			if ($("input[@name='del_type']:checked").val()) {
				var myThis = $("input[@name='del_type']:checked");
				var myDel = $(myThis).attr("value");
				var qty = $("input[@name='qq_units']").val();
				//if (
				var total = $("#"+$(myThis).attr("value")).attr("rel")*qty;
				$(".qq-price").html("&pound;"+total.toFixed(2));
			
				$(".qq-details").html("");
				//$(".group").toggleClass("group_vert");
			} 
		}




