	// bind function called if a colour is selected before size has been chosen.
	function bind_needtoselectcolour(){
		$(".needtoselectcolour").click(function () { 
			alert("You must first select a size");
		});
	}

	// load (ajax) available colors into the div
	function getall_size_colours(catID, size){
		$("#colours_loading").removeClass("dispnone");
		$("#available_colours").addClass("dispnone");

		urlAvail = "ajax_available_size_colours.php?catid=" + catID + "&size=" + size;

		$("#available_colours").load( urlAvail , { na: 1 }, function(){
			bind_needtoselectcolour();
			bind_scroll_to_element_demo();
			$("#colours_loading").addClass("dispnone");
			$("#available_colours").removeClass("dispnone");
		});
	}

	function display_color_selector(v){
		if( v == "on" ){
			$("#colour_section_main").removeClass("offscreen");
			$("#colour_section_main").addClass("onscreen");
			$("#colour_section_holder").addClass("setcontainerheight");		

			// title bar in
			$("#titlebar").removeClass("titlebar_offscreen");
			$("#titlebar").addClass("titlebar_onscreen");
		}
			
		if( v == "off" ){
			$("#colour_section_main").addClass("offscreen");
			$("#colour_section_main").removeClass("onscreen");
			$("#colour_section_holder").removeClass("setcontainerheight");
			// title bar out
			$("#titlebar").removeClass("titlebar_onscreen");
			$("#titlebar").addClass("titlebar_offscreen");
			

		}
		
	}

$(document).ready(function() {

    $(".fancybox").fancybox();

	// jq_close_colour_selector
	$(".jq_close_colour_selector").click(  function(){
													
		display_color_selector("off")
		
		//$("#colour_section_main").removeClass("onscreen");
		//$("#colour_section_main").addClass("offscreen");
		//$("#colour_section_holder").removeClass("setcontainerheight");													

	});

	// expand the left navigation sales section
	$(".jq_sales_items").click(function () { 
		$("#leftCategories_sales").show("slow");
	});

	// change has been made to the drop box
	$("select#options").change(function(){
		if( $(this).val() ){
			getall_size_colours( category_id, $(this).val() );	
		} else {
			getallcolours(category_id);
		}
	})

	bind_needtoselectcolour();

//	$(".sizegroup").click( function(){	
//		$( "#jq_property_id" ).attr( "value", $(this).attr("property_id") );
//		$( "#jq_item_property_id" ).attr( "value", $(this).attr("item_property_id") );
//		$( "#jq_add_id" ).attr( "value", $(this).attr("itemid") );
//		}
//	);

	$("#add_to_cart").click( function (){ 
		// ensure size and colours have been set
		if( !$(".sizegroup:checked").val() ){
			
			alert("You must first select a size and colour");
		} else {
			// check qty is available
			selected_qty = parseInt( $("#quantityselect").val() );
			available_stock = parseInt( $(".sizegroup:checked").attr("qty") );

			if( selected_qty > available_stock ){
				alert("You will need to select a lower stock amount there are currently "+available_stock+" items in stock");
			} else {
				// amend the form that will be submimtted ( fill with the property id )

				this_property_id = $(".sizegroup:checked").attr("property_id")
	
				$("#jq_item_property_id").attr("name", "property_" + this_property_id)
				$("#jq_property_required").attr("name", "property_required_" + this_property_id)
				$("#jq_property_control").attr("name", "property_control_" + this_property_id)
				$("#jq_property_name").attr("name", "property_name_" + this_property_id)
	
				$("#jq_add_id").attr("value", $(".sizegroup:checked").attr("itemid") );
				$("#jq_property_id").attr("value", this_property_id );
				$("#jq_item_property_id").attr("value", $(".sizegroup:checked").attr("item_property_id") );

				$("#qty").attr("value", selected_qty );
				alert("Your product has been added to your basket");
				document.form_174_0.submit();
			}

		}
	});

	// - - - Gallery stuff --
	$(".gallery_image").click( function(){
		$("#bigproductimage").removeClass("dispnone");
		$("#bigproductimage").attr("src", "assets/images/gallery/"+$(this).attr("gallery_image") );

		super_image = $(this).attr("super_image");

		$("#bigproductimage_anchor").attr("href", super_image );

		if( super_image == "" ){
		  $("#bigproductimage_anchor").addClass("dispnone");
		} else {
		  $("#bigproductimage_anchor").removeClass("dispnone");
		}
		

		$("#bigproductimage").show();
//		$("#colour_section_main").removeClass("onscreen");
//		$("#colour_section_main").addClass("offscreen");
//		$("#colour_section_holder").removeClass("setcontainerheight");
	});

//#bigproductimage
//#colour_section_main
//#colour_section_holder

	$(".jq_gallery_colours").click( function(){		
		display_color_selector("on")
	});

});

