
	$j = jQuery.noConflict();
	
	jQuery.logThis = function( text )
	{
		if( (window['console'] !== undefined) )
		{
			console.log( text );
		}
	}

	$j(document).ready(function()
	{
		//$j('a.lightbox').lightBox();
		$j("input.wp-input").focus(
	    	function()
	    	{
		   		//$j("span#innertext_" + $j(this).attr("name")).css("text-indent", "-9999px");
		   		$j("span#innertext_" + $j(this).attr("name")).css("color", "#fff7f7");
	    	}
	    );
	    	
	    	
		$j("select.sel-size-and-price").change(
			function()
			{
				/*alert("The selected option is " + $j("option:selected", this).val());
				return;
				
				alert("Index of selected option is: " + optind);
				return false;
				alert("Option Index: " + $j(this).attr("selectedIndex"));
				return false;
				*/
				var optind = $j("option:selected", this).index();
				//var optind = $j(this).attr("selectedIndex");
				$j.logThis( "optind: " + optind );
				$j.logThis( "optind (2nd): " + $j("option:selected", this).index() );
				
				var formelem = $j(this).parents("form");
				var pid = formelem.attr("id").split("_"); // get the pid of this particular product 
				$j.logThis( "formelem ID: " + formelem.attr("id") );
				$j.logThis( "pid: " + pid[1] );
				
				/*alert("Price: " + $j("input[name=option_amount" + optind + "]", formelem).val());
				return false;*/
				$j.logThis( "Price: " + $j("input[name=option_amount" + optind + "]", formelem).val() );
				
				$j("span#price_" + pid[1]).text("$" + formelem.find("input[name=option_amount" + optind + "]").val());
			}
		);
		
		$j("input.consultant-code").focus(
			function()
			{
				if ($j(this).val() == "Consultant code")
				{
					$j(this).val("");
				}
			}
		);
		
		$j("input.img_btn").click(
			function()
			{
				// index of the main colour dropdown option on the clicked product
				//alert("Index: " + $j(this).parents("form").find("select.select-main-colour option:selected").index());
				
				//alert("Form object ID: " + $j(this).parents("form").attr("id"));
				var formelem = $j(this).parents("form");
				var pid = formelem.attr("id").split("_"); // get the pid of this particular product 
				/*alert("The pid is: " + pid[1]);
				return false;*/
				// get the indexes of all the dropdowns
				var dd_colour1 	= $j(this).parents("form").find("select.sel-main-colour").attr("selectedIndex");
				var dd_colour2 	= $j(this).parents("form").find("select.sel-secondary-colour").attr("selectedIndex");
				var dd_size		= $j(this).parents("form").find("select.sel-size-and-price").attr("selectedIndex");
				var dd_quantity = $j(this).parents("form").find("select.sel-quantity").attr("selectedIndex");
				var dd_shipping = $j(this).parents("form").find("select.sel-shipping").attr("selectedIndex");
				
				//var dd_colour1 	= $j(this).parents("form").find(".sel-main-colour").("option:selected").index();
				var dd_colour1 	= $j(this).parents("form").find("select.sel-main-colour option:selected").index();
				var dd_colour2 	= $j(this).parents("form").find("select.sel-secondary-colour option:selected").index();
				var dd_size		= $j(this).parents("form").find("select.sel-size-and-price option:selected").index();
				var dd_quantity = $j(this).parents("form").find("select.sel-quantity option:selected").index();
				var dd_shipping = $j(this).parents("form").find("select.sel-shipping option:selected").index();
				$j.logThis( "dd_colour1: " + dd_colour1 );
				$j.logThis( "dd_colour2: " + dd_colour2 );
				$j.logThis( "dd_size: " + dd_size );
				$j.logThis( "dd_quantity: " + dd_quantity );
				$j.logThis( "dd_shipping: " + dd_shipping );
				//return false;
				
				//alert("Colour 1: " + dd_colour1 + ", colour 2: " + dd_colour2 + ", size: " + dd_size + ", quantity: " + dd_quantity);
				//return false;
				
				
				// make sure all dropdowns have been chosen or return false;
				if (((dd_colour1 == 0) || (dd_colour2 == 0) || (dd_size == 0) || (dd_quantity == 0) || (dd_shipping == 0)) || (((dd_colour1 == 0) || (dd_size == 0) || (dd_quantity == 0) || (dd_shipping == 0)) && (dd_colour2 == -1)))
				//if (dd_colour1 == 0)
				{
					alert("Please choose an option from each of the drop-down menus (colour(s), size, quantity, shipping) and try again.");
					return false;
				}
				else
				{
					if ($j(this).parents("form").find("input.consultant-code").val() == "Consultant code")
					{
						$j(this).parents("form").find("input.consultant-code").val("")
					}
					return true;
				}
				
				return false;
			}
		);
		
		/* SHOWCASE */
		var in_progress = false;
		
		$j(function() 
		{
			function slideForward(frameID)
			{
				//var options = {};  																// most effect types need no options passed by default
		    	var $active = $j('div#frame_' + frameID + ' img.active');						// get the active image (pre-set to start)
		
		    	if ( $active.length == 0 ) $active = $j('div#frame_' + frameID + ' img:last');	// 
		    	
		    	//alert("active image ID: " + $active.attr("id"));
				//return false;	
		
		    	var $next = $active.next().length ? $active.next() : $j('div#frame_' + frameID + ' img:first');	// set next: if there is no next, set next to first
		
		    	$active.addClass('last-active');												// make the active one the last active
		
			    $next.hide()			 														// set next to opacity 0
		        	.addClass('active')															// make it active (still invisible though)
		        	.fadeIn(500,function()
		        	{
			        	$active.removeClass('active last-active');								// callback: remove classes from the previous active image
			        	in_progress = false;
	        		});
			}
			
			function slideBackward(frameID)
			{
				//var options = {};  																// most effect types need no options passed by default
		    	var $active = $j('div#frame_' + frameID + ' img.active');						// get the active image (pre-set to start)
		
		    	if ( $active.length == 0 ) $active = $j('div#frame_' + frameID + ' img:first');	// something to do with short cycles?
		
		    	var $prev = $active.prev().length ? $active.prev() : $j('div#frame_' + frameID + ' img:last');	// set prev: if there is no prev, set prev to last
		
		    	$active.addClass('last-active');												// make the active one the last active
		
			    $prev.hide()			 														// set next to opacity 0
		        	.addClass('active')															// make it active (still invisible though)
		        	.fadeIn(500,function()
		        	{
			        	$active.removeClass('active last-active');								// callback: remove classes from the previous active image
			        	in_progress = false;
	        		});
			}
			
			$j("a.arrow-right").live('click', function() {
				if ((in_progress == false) && ($j(this).attr("class") == "arrow-right"))
				{	
					in_progress = true;
					slideForward($j(this).parent().attr("id"));
				}
				return false;
				
			});
			
			$j("a.arrow-left").live('click', function() {
				if ((in_progress == false) && ($j(this).attr("class") == "arrow-left"))
				{	
					in_progress = true;
					slideBackward($j(this).parent().attr("id"));
				}
				return false;
			});
			
			$j("a.btn-tab").click(function() {
				var topFrame = $j(this).attr("rel");
				//alert("top frame will now be: " + topFrame);
				//return false;
				
				// id of frame
				tabid = $j(this).parent("div.itab").attr("id");
				//alert("Tab ID: " + tabid);
				
				if (tabid == "living") { $j("div#tabs").css("background-position", "0 0") }
				else if (tabid == "bedroom") { $j("div#tabs").css("background-position", "0 -46px") }
				else if (tabid == "dining") { $j("div#tabs").css("background-position", "0 -92px") }
				else if (tabid == "bath") { $j("div#tabs").css("background-position", "0 -138px") }
				
				$j(".frame").each(function()
				{
					if ($j(this).attr("id") != topFrame)
					{
						$j("div#" + $j(this).attr("id")).hide();
					}
					else
					{
						$j("div#" + $j(this).attr("id")).show();
					}
				});
				
				// update the tabs
				$j("div.itab").each(function()
				{
					if ($j(this).attr("id") == tabid)
					{
						jQuery("a.arrow-left-disabled", this).attr("class", "arrow-left");
						jQuery("a.arrow-right-disabled", this).attr("class", "arrow-right");
					}
					else
					{
						jQuery("a.arrow-left", this).attr("class", "arrow-left-disabled");
						jQuery("a.arrow-right", this).attr("class", "arrow-right-disabled");
					}
				});
				
				return false;
			});

		});
	});
