/*//////////////////////////

	client:   SOURCING CITY
	version:  v3.1.4
	author:   tom greenhill
	agency:	  akikodesign.com

/////////////////////////*/

// NO FIREBUG WORKAROUND
// if(!console) {var console={log:function(msg){/*$("#log p").html($("#log p").html()+'<hr class="logsep" />'+ msg)*/},error:function(msg){/*alert(msg);*/}}};

var visible = false, 
	containerActive = false,
	active = 0,
	BEGAN_LOADING = (new Date()).getTime(),
	SITE_LOCATION,
	ACTIVE_PANEL,
	BASKETS,
	$markupInput;

var checkVisible = function() {
	if(visible) {
		return false;
	} else {
		$("#navigation li").removeClass("active");
		$(".dropdown:visible").hide();
	}
}

var hideContainer = function() {

	if(!containerActive)
	{
		$activeContainer.find("li.current").removeClass("current");
		$activeContainer.css({ top: "-9999em", left: "-9999em" });
	}
}

var setupSelectBox = function() {
	// console.log( "FUNCTION CALLED: setting up each dropdown - setupSelectBox" );
	$input = $(this);
	
	var id = $input.attr("id");
	if(!$("body").hasClass("home"))
	{
		var containerId = id.substring( id.lastIndexOf("_") + 1 ) +'_container';
		var text = $("div#"+ containerId +" li:first").text();
		
		if( $input.val() == "" )
		{
			$input.attr('value', text)
		}
		$input
		.attr('default', text)
		.attr('containerid', containerId)
	}
		
	$input
	.bind('blur', function() {
		if(!$(this).hasClass("disabled"))
		{
			containerActive = false;
			setTimeout(hideContainer, 250);
		}
	})
	.bind('click', function() {
		if(typeof($activeContainer) != "undefined")
		{
			hideContainer();
		}
		
		$activeInput = $(this);
		
		if($activeInput.hasClass("disabled"))
		{
			$activeInput.blur();
			return false;
		} else {
			var parentpos = $activeInput.offsetParent().position();
			var pos = $activeInput.position();
			var height = $activeInput.outerHeight();
			var containerId = $activeInput.attr("containerid");
			
			pos.top += (parentpos.top + height) + ($.browser.safari ? 62 : 0);
			pos.left += (parentpos.left - 4);
			$activeInput.panel = $activeInput.parents("[class*='panel-']").attr("id");			
			$activeContainer = $("#"+ containerId);
			
			$activeContainer.bind("focus", function() {
				containerActive = true;
			}).hoverIntent({
				sensitivity: 5, 	// integer = sensitivity threshold (must be 1 or higher)
				interval: 500,  	// integer = milliseconds of polling interval
				over: function() {	// callback (required)
					// console.log("mouse over");
					$("#log p").html($("#log p").html() +"mouse over<br />");
					containerActive = true;
				},  	
				timeout: 500,   		// integer = milliseconds delay before onMouseOut function call
				out: function() {   	// callback (required)
					// console.log("mouse out");
					$("#log p").html($("#log p").html() +"mouse out<br />");
					containerActive = false;
					hideContainer();
				}
			});
			
			if( $activeContainer.attr("width") != "set" )
			{
				var width = $activeContainer.find('ul').outerWidth();
				$activeContainer.width(width + 40);
				$activeContainer.find('.bottom').width(width + 6);
				$activeContainer.find('ul').width(width + 25);
				$activeContainer.attr("width", "set");
			}

			$activeContainer.css({ top: pos.top, left: pos.left }).find("li:first").focus();
			//dropdownItem();
			containerActive = true;
		}
	})
	.bind('keydown', function(e) {
		e.preventDefault();
		var kc = e.keyCode;
		var char = String.fromCharCode(kc);
		switch(kc)
		{
			case 13: // return
				if(typeof($activeContainer) != "undefined" && $("li.current", $activeContainer).length > 0)
				{
					$("li.current", $activeContainer).trigger("click");
				} else {
					$(this).trigger('click');
				}
				break;
			case 38: // up
				e.preventDefault();
				moveSelect(-1);
				break;
			case 40: // down
				e.preventDefault();
				moveSelect(1);
				break;
			case 27: //escape
			  	containerActive = false;
				hideContainer();
			  	break;
		}
		// console.log("key code: "+ kc);
		// console.log("character: "+ char);
		if( ( kc >= 65 && kc <= 90 ) || ( kc >= 97 && kc <= 122 ) || ( kc >= 48 && kc <= 57 ) )
		{
			$("li", $activeContainer).each(function() {
				var nodes = this.childNodes;
				var length = nodes.length;
				for(i = 0; i < length; i++)
				{
					var t = nodes[i].data;
					if(t.charAt(0) == char)
					{
						$("ul", $activeContainer).scrollTop(this.offsetTop);
						// console.log($(this));
						// console.log("position (top): "+ this.offsetTop);
						return false;
					}
					
				}
			});
		}
	});
}

var moveSelect = function(step) {
	var lis = $("li", $activeContainer);
	if (!lis || lis.length == 0) return false;
	active += step;
	//loop through list
	if (active < 0) {
		active = lis.size();
	} else if (active > lis.size()) {
		active = 0;
	}
	scrollLi(lis, active);
	lis.removeClass("current");

	$(lis[active]).addClass("current");
}

var scrollLi = function(list, active) {
	var el = $(list[active]).get(0);
	var list = $activeContainer.find("ul").get(0);
	
	if (el.offsetTop + el.offsetHeight > list.scrollTop + list.clientHeight) {
		
		list.scrollTop = el.offsetTop + el.offsetHeight - list.clientHeight; 
		
	} else if(el.offsetTop < list.scrollTop) {
		
		list.scrollTop = el.offsetTop;
	}
}

var sv = function( elem, id ) {
	var $this = $(elem);
	var text = (id == 0) ? $activeInput.attr("default") : $this.addClass("selected").text();
	var submitid = $this.attr("submitid");
	
	$this.siblings(".selected").removeClass("selected");
	
	$activeInput
	.val(text)
	.attr("title", text);
	
	if( submitid )
	{
		$("#"+ submitid ).trigger("click");
	}
	
	if($("body").hasClass("home"))
	{			
		$activeInput
		.attr("guid", id);
		
		$("#"+ $activeInput.panel +" .search input").focus();
		
		var aid = $activeInput.attr("id");
		if( aid == "ctl00_CPH1_DDPriceRanges" 
		 || aid == "ctl00_CPH1_DDColours"
		 || aid == "ctl00_CPH1_DDBrands"
		 || aid == "ctl00_CPH1_DDShapes" 
		 || aid == "ctl00_CPH1_DDExpressTime"  
		 || aid == "ctl00_CPH1_DDExpressPriceRange" )
		{
			$activeInput.next().val(id);
		}
		
		var masterInput = $.inArray($activeInput.attr("id"), ddInputs.master) == -1 ? false : true;
		$activeInput.attr("master", masterInput);
					
		disableInputs();
	} else {
		$activeInput
		.next()
		.val(id);
		if($activeInput.hasClass("paging"))
		{
			$activeInput.siblings("input:submit").trigger("click");
		}
	}
	containerActive = false;
	hideContainer();
}

var bindSelectBox = function() {
	$activeInput = $(this);
	$activeInput.panel = $activeInput.parents("[class*='panel-']").attr("id");
	var id = $activeInput.attr("id")
	$activeInput.defaultText = id.substring(id.lastIndexOf("_")+1);
	
	if($("body").hasClass("home"))
	{
		if($activeInput.val() != "") {
			var masterInput = $.inArray($activeInput.attr("id"), ddInputs.master) == -1 ? false : true;
			$activeInput.attr("master", masterInput);
			disableInputs();
		} else {
			$("#"+ $activeInput.panel).find(".disabled").removeClass("disabled");
		}
	}
}

var checkDisabled = function() {
	if($(this).hasClass("disabled"))
	{
		return false;
	}
}

var disableInputs = function(panel)
{
	var id = $activeInput.attr("id");
	var panel = $activeInput.panel || panel;
	
	if( typeof eval("ddInputs."+ panel +".disable") != "undefined" )
	{
		var toDisable = eval("ddInputs."+ panel +".disable."+ id) || false;
		
		if(toDisable)
		{
			toDisable.addClass("disabled")
			toDisable.each(function() {
				var $this = $(this);
				if($this.hasClass("selectbox"))
				{
					$this.addClass("disabled");
					var defaultText = $this.attr("default");
					$this.val(defaultText).attr("title", defaultText);
				} else {
					$this.parent().addClass("disabled");
					$this.val("").attr("title", "").prev().removeClass("hide");
				}
			});
		}
	}
}

var setValues = function( $this, container, $container, e ) {
	var $masterInputs = $("input:text[master='true']", $container);
	var $optionalInputs = $("input:text[master='false']", $container);
	
	if($masterInputs.length > 0)
	{
		var types = values = "";
		$masterInputs.each(function() {
			var $this = $(this);
			var thisType = ( !$this.attr("default") ) ? $this.attr("id").split("CPH1_")[1] : $this.attr("default");
			
			types = (types != "") ? types +"|"+ thisType : thisType;
			values = (values != "") ? values +"|"+ $this.attr("guid") : $this.attr("guid");
			
		});
		if($optionalInputs.length > 0)
		{
			$optionalInputs.each(function() {
			var $this = $(this);
				values = (values == "") ? $this.val() : values +"|"+ $this.val();
			});
		}
		
		if(container == "suppliersearch")
		{
			$("#ctl00_CPH1_txtSSType").val(types);
			$("#ctl00_CPH1_txtSSValue").val(values);
			
		} else {
			eval("ddInputs."+ container +".type.val(\""+ types +"\")");
			eval("ddInputs."+ container +".value.val(\""+ values +"\")");
		}	
		
		return true;
	} else {
		if(container == "productsearch")
		{
			smlTooltip.call("<p>Please ensure you have selected at least one filter to search against.</p>", $this.attr("id"));
			
		} else {
			
			smlTooltip.call( "<p>Please ensure you have selected at least one filter to search against!</p>", $this.attr("id") );
		}
		
		e.preventDefault();
		return false;
	}
}

var bindPaging = function() {
	$(".pages a:not([disabled])").click(function() {
		window.location.hash = "top";
		cursor("wait");
	});
}

var cursor = function(type) {
	$("body").css("cursor", type );

	// this function can be modified to overlay image for loading...	
	if( type == "wait" ) {
		// if we're loading something
		
	} else if( type == "default" ) {
		// if we're returning to normal state i.e. removing whatever was loaded above.
		
	}
}

// function for wait cursor
function setHourglass() {
	$("body").css("cursor", "wait");
}

// search results tumbler
var embedTumbler = function() {
	//console.log( "FUNCTION CALLED: embed SWF tumbler - embedTumbler" );
	
	var prodCount = $("input[id$='txtProdCount']").val();
	var itCount = $("input[id$='txtITCount']").val();
	var supCount = $("input[id$='txtSUPCount']").val();
	var swf = "includes/flash/tumbler3.swf";
	var width = "490";
	
	tumblerParams = {
		wmode: "transparent",
		menu: false
	};
	tumblerAttributes = {
		id: "tumbler",
		name: "tumbler"
	};
	tumblerFlashvars = {
		searchCount: prodCount,
		typesCount: itCount,
		supplierCount: supCount
	};
	if( $("#tumbler").hasClass("groups") )
	{
		swf = "includes/flash/tumbler_groups.swf";
		width = "470";
	}
	if ($("#tumbler").hasClass("itgroups")) {
		swf = "includes/flash/tumbler_item_types.swf";
		width = "470";
	}
	$("#textProdCount").text(prodCount);
	$("#textITCount").text(itCount);
	$("#textSUPCount").text(supCount);
	
	if( $("#tumbler").length > 0 )
	{
		swfobject.embedSWF(swf, "tumbler", width, "25", "9.0.0", "expressInstall.swf", tumblerFlashvars, tumblerParams, tumblerAttributes);
	}
	
	$("label.select-all").click(function() {
		$(".listing input[type='checkbox']").attr("checked", $(this).children("input").attr("checked"));
	});
	$("img.clear-all").click(function() {
		$(".listing input[type='checkbox']").attr("checked", false);
		$(this).siblings("label.select-all").find("input[type='checkbox']").attr("checked", false);
	});
	
	$("label:has(input)").bind("click", checkDisabled);
	$("label:has(input) input").bind("blur", bindSelectBox);		
	$("input.selectbox").each(setupSelectBox);

	var currentItem = $('ul#tumblr :first-child');
	fadeSequence(currentItem);
	
	function fadeSequence(thisItem) {
	thisItem.fadeIn('slow');
	
	if (thisItem.is(':last-child')) {
		clearTimeout(t);
		} else {
			var t = setTimeout(function(){fadeSequence(thisItem.next());},500);     
		}
	};
}

// sets dropdown default values on owner input
var setDefaultText = function() {
	// console.log( "FUNCTION CALLED: setting default text - setDefaultText" );
	$("input[default]").each(function() {
		var $this = $(this);
		$this.val( $this.attr("default") );
	});
	$(".selectbox-wrapper li").removeClass("selected");
}

// set initial values, fetched from hidden inputs
var setInitValues = function() {
	// console.log( "FUNCTION CALLED: setting initial values - setInitValues" );
	$(".selectbox-wrapper").each(function() {
		var $this = $(this);
		var id = this.id;
		var $lis = $this.find("li[selected]");
		
		if( $lis.length > 0 )
		{
			$lis.each(function() {
				var $li  = $(this).addClass("selected");
				var text = $li.text();
				var val  = id.indexOf("Currency") != -1 ? text.split(" ")[0] : text;
				$("input[containerid='"+ id +"']").attr("set", "true").val( text ).next().val( val );
			});
		}
	});
}

// function fired when page updated with update panel to bind functions again! if only we could use live()
var bindResults = function() {
	// console.log( "FUNCTION CALLED: bind results - bindResults" );
	$(".page-actions label:has(input)").bind("click", checkDisabled);
	$(".page-actions label:has(input) input").bind("blur", bindSelectBox);		
	$(".page-actions input.selectbox").each(setupSelectBox);
	
	bindPaging();
	bindDD();
	// bindSelectAll();
	cursor("default");
	
	$("#ctl00_CPH1_btnReset").click(function() {
		$("#ctl00_CPH1_DDSortPage, #ctl00_CPH1_DDFilterPage").val("All");
	});
	
	$("#ctl00_CPH1_btnGetSupplier").click(function(e) {
		
		var checkboxes = $(".get-supplier :checkbox:checked");
		if( checkboxes.length == 0 )
		{
			e.preventDefault();
			smlTooltip.call("<p>Please select at least one supplier.</p>", "ctl00_CPH1_btnGetSupplier");
		}
	});
	
	lgTooltip.init("a.supplier-info");
	lgTooltip.init("a.print");
	smlTooltip.init("a.supplier-websites");

}

// functionalised for .net update panels 
var label = function(e) {
	
	if($(e).get(0).tagName.toLowerCase() == "textarea")
	{
		$input = $(e);
		$span = $input.prev();
		
	} else if($(e).get(0).tagName.toLowerCase() == "span") {
		
		$span = $(e);
		$input = $span.next();
		$input.focus();
	}
	
	if($span.parent().hasClass("disabled"))
	{
		$input.blur();
		return false;
	}
	$span.addClass("hide");

	$input.bind("blur", function() {
		var $this = $(this);
		if($this.val() == "")
		{
			$this.prev().removeClass("hide");
		}
		$this.unbind("blur");
	});
}

// close large tooltip
var closeTooltip = function() {
	if($.browser.msie) {
		$("#tooltip-lg").hide();
		lgTooltip.visible = false;
		lgTooltip.index = false;
		$("#tooltip-lg .content").empty();
		$("#tooltip-lg").remove();
	} else {
		$("#tooltip-lg").fadeOut(500, function() {				
			lgTooltip.visible = false;
			lgTooltip.index = false;
			$("#tooltip-lg .content").empty();
			$("#tooltip-lg").remove();
		});
	}
}

// eshot baskets page for applying markup rate
var applyMarkup = function(elem) {
	var $this = $(elem);
	var $radios = $("#markup :radio:checked")
	
	if($radios.length < 1) {
		
		smlTooltip.call("<p>You must select a markup percentage first!</p>", "apply-markup");
		
	} else {
		var val = $radios.eq(0).prev().val();
		$markupInput.val(val).prev().addClass("hide");
		$markupInput = null;
		closeTooltip();
	}
}
var returnCenter = function(height) {
	return ((($(window).height() - height) / 2 ) + 100) + $(window).scrollTop()
}

/*#################################### DOM READY */
$(function() {
	
	ie6 = ($.browser.msie && parseInt($.browser.version) <= 6) ? true : false;
	swfobject.embedSWF("/includes/flash/newheader.swf", "flash", "836", "138", "8.0.0","expressInstall.swf", {}, {});
	
	$("#ctl00_CPH1_btnGetSupplier").click(function(e) {
		
		var checkboxes = $(".get-supplier :checkbox:checked");
		if( checkboxes.length == 0 )
		{
			e.preventDefault();
			smlTooltip.call("<p>Please select minimum one supplier.</p>", "ctl00_CPH1_btnGetSupplier");
		}
	});
	
	// fix datepicker calendar paths if page is in sub folder (additional can be added using same syntax)
	if( $("body").hasClass("supplier-area") || $("body").hasClass("customer-area") )
	{
		$.dpImages = {
			IMG_PREV_YEAR		:	'<img src="../images/btn/calendar-prev-year.gif" alt="'+ $.dpText.TEXT_PREV_YEAR +'" />',
			IMG_PREV_MONTH		:	'<img src="../images/btn/calendar-prev-month.gif" alt="'+ $.dpText.TEXT_PREV_MONTH +'" />',
			IMG_NEXT_YEAR		:	'<img src="../images/btn/calendar-next-year.gif" alt="'+ $.dpText.TEXT_NEXT_YEAR +'" />',
			IMG_NEXT_MONTH		:	'<img src="../images/btn/calendar-next-month.gif" alt="'+ $.dpText.TEXT_NEXT_MONTH +'" />'
		};
	}
	
	// auto expanding textareas
	$("textarea.expanding").autogrow({
		maxHeight: 300,
		minHeight: 50,
		lineHeight: 12
	});
	
	if( ie6 )
	{
		// fix empty element padding issue pushing down in ie6
		$(".pad").each(function() {
			var $ul = $(this).find("ul.list");
			if(  $("li", $ul ).length == 0 ) $ul.remove();
		});

		// wrap nav dropdowns to avoid breaks
		$(".dropdown li a").wrapInner("<nobr></nobr>");
	}
	
	// SEARCH FIELD INPUT LABELS SHOW/HIDE
	$("label.block input, label.block textarea").each(function() {
		var $this = $(this);
		if($this.val() != "") $this.prev("span").addClass("hide");
	});
	$("label input").bind("focus keydown", function() {
		// console.log("focus given");
		$span = $(this).prev();
		$input = $(this);
		if($span.parent().hasClass("disabled"))
		{
			$input.blur();
			return false;
		}
		$span.addClass("hide");

		$input.bind("blur", function() {
			var $this = $(this);
			if($this.val() == "")
			{
				$this.prev().removeClass("hide");
			}
		});
	});
	$("label:has(input), label:has(textarea)").bind("click keydown", function() {

		$span = $(this).find("span");
		if($span.attr("title") == "Add to Shotgun") return;
		$input = $span.next();
		if($span.parent().hasClass("disabled"))
		{
			$input.blur();
			return false;
		} else {
			$input.focus();
		}
		$span.addClass("hide");

		$input.bind("blur", function() {
			var $this = $(this);
			if($this.val() == "")
			{
				$this.prev().removeClass("hide");
			}
		});
	});

	$("input#ctl00_search_keywords").bind("focus", function() {
															
		$(this).bind("keydown", function(e) {
			var $this 	= $(this);
			var val 	= $this.val();
			var key 	= e.which;
			var words 	= $this.val().split(" ");
			var count	= 4;						// this is the number of words to limit the search to.
			
			if( key != 8 && key != 0 && words.length > count ) {
				
				smlTooltip.call("The less words searched the broader your results.<br />Search is limited to "+ count +" words to give you the best results.", "ctl00_search_keywords" );
				return false;
			
			} else if(val == "" && key == 13) {
				
				smlTooltip.call("Please enter the keyword(s) you wish to search for!", "ctl00_search_keywords" );
				$this.focus().prev().addClass("hide");
				return false;
				
			} else if(val != "" && key == 13) {
				
				$("#ctl00_search_go").trigger("click");
			}
		});
	});
	
	if($("#tumbler").length > 0)
	{
		embedTumbler();
	}
	
	if($("#ctl00_CPH1_colour").length > 0)
	{
		var colour = $("#ctl00_CPH1_colour").val();
		if(colour != "")
		{
			$(".customColour").css({ color: colour });
			$("div.customColour").css({ backgroundColor: colour });
		}
	}
	
	$("#ctl00_CPH1_vs li:not(:last)").append(", ");
	$("#ctl00_CPH1_vs li:last").append(".");
	
	$("#tt-dynamic-office").hoverIntent({
		sensitivity: 5, 	// integer = sensitivity threshold (must be 1 or higher)
		interval: 500,  	// integer = milliseconds of polling interval
		over: function() {	// callback (required)
			if(!smlTooltip.visible)
			{
				smlTooltip.call("<p>Dynamic Office Lite is in&ndash;built within Sourcing City &amp; enables you to quickly &amp; simply build Ideas Lists, Quotations, Order Acknowledgements, Purchase Orders and Invoices.</p>\n<p>Dynamic Office Lite also enables you to create your own E-Shots for your own E&ndash;Marketing Campaigns.</p>\n<p>To see how this works simply create an Ideas List, Quotation or E&ndash;Shot &amp; you can see how simple &amp; effective the process is!</p>", "tt-dynamic-office");
				smlTooltip.visible = true;
			}
		},  	
		timeout: 250,   		// integer = milliseconds delay before onMouseOut function call
		out: function() {   	// callback (required)
			if($.browser.msie) {
				$("#tooltip-sml").hide().remove();
				smlTooltip.visible = false;
				smlTooltip.index = false;
			} else {
				$("#tooltip-sml").fadeOut(500, function() {				
					smlTooltip.visible = false;
					smlTooltip.index = false;
					$(this).remove();
				});
			}
		}
	});
	
	// COLOUR PICKERS
	$('.select-colour').each(function() {
		$(this).ColorPicker({
			color: '#023fa3',
			onShow: function (picker) {
				if($.browser.msie)
				{
					$(picker).show();
				} else {
					$(picker).fadeIn(500);
				}
				return false;
			},
			onHide: function(picker) {
				if($.browser.msie)
				{
					$(".customColour").css("color", "#" + customColour);
					$("div.customColour").css("backgroundColor", "#" + customColour);
					$("#ctl00_CPH1_colour").val("#" + customColour);
					$(picker).hide();
				} else {
					$(picker).fadeOut(500);
				}
				return false;
			},
			onChange: function (hsb, hex, rgb) {
				if(!$.browser.msie)
				{
					$(".customColour").css("color", "#" + hex);
					$("div.customColour").css("backgroundColor", "#" + hex);
				}
				$("#ctl00_CPH1_colour").val("#" + hex);
				$("#ctl00_CPH1_colourChanged").val("Y");
				customColour = hex;
			},
			onSubmit: function (hsb, hex, rgb) {
				if($.browser.msie)
				{
					$(".customColour").css("color", "#" + hex);
					$("div.customColour").css("backgroundColor", "#" + hex);
				}
				$("#ctl00_CPH1_colour").val("#" + hex);
				$("#ctl00_CPH1_colourChanged").val("Y");
			}
		});
	});
	
	// DATE PICKERS
	if($("label.date").length > 0)
	{
		$("label.date input").datePicker({ 
			createButton: false, 
			clickInput: true, 
			verticalOffset: "-230px", 
			horizontalOffset: "-30px" 
		}).bind("blur", function() {
			var $this = $(this);
			$this.prev("span").addClass("hide");
		}).bind("dateSelected", function(event, date, $td, status) {
			if(status)
			{
				$(this).prev().addClass("hide");
			}
		});
	}
	
	if($(".result").length > 0)
	{
		$(".result:even").filter(function() {
			return !$(this).hasClass("first");
		}).addClass("first");
	}
		
	// tracking baskets
	if( $("#baskets").length > 0 && !$("body").hasClass("no-basket-scroll") && $("#columnB").height() > $("#columnA").height() )
	{
		var $window 		= $(window);
		BASKETS 			= $("#baskets");
		BASKETS.os 			= BASKETS.offset();
		BASKETS.toppadding 	= 0;			// POSITION FROM TOP EDGE
		BASKETS.realtop 	= BASKETS.os.top - BASKETS.toppadding;
		BASKETS.isfixed 	= (BASKETS.css('position') == 'fixed');
		BASKETS.curheight 	= BASKETS.outerHeight();
		
		$window.scroll(function () {
			
			BASKETS.curheight 	= BASKETS.outerHeight();
			BASKETS.footertop	= $("#footer").offset().top;
			
			if( $window.scrollTop() > BASKETS.realtop ) {
				
				BASKETS.bottom 	= $(window).scrollTop() + BASKETS.curheight;
				BASKETS.diff 	= BASKETS.bottom + 40 > BASKETS.footertop ? ( BASKETS.bottom - BASKETS.footertop ) + 40 : 0;
				
				if(ie6) {
					
					BASKETS.css('top', $window.scrollTop() + BASKETS.toppadding);
					
				} else if ( !BASKETS.isfixed ) {
					
					BASKETS.css({
						left: BASKETS.os.left,
						top: BASKETS.toppadding - BASKETS.diff +"px",
						position: "fixed",
						backgroundColor: "#fff",
						paddingTop: "5px"
					});
					BASKETS.isfixed = true;
					
				} else if( BASKETS.isfixed && BASKETS.isfixed != 0 ) {
					
					BASKETS.css({
						top: BASKETS.toppadding - BASKETS.diff +"px"
					});
				}
				
			} else {
				
				if (BASKETS.isfixed) {
					
					BASKETS.css({
						position: '',
						top: '',
						left: '',
						backgroundColor: '',
						paddingTop: '0'
					});
					BASKETS.isfixed = false;
				}
			}
		});
		
		$window.bind("resize", function() {

			BASKETS.os = $("#content > .inner").offset();
			BASKETS.os.left += 3; // baskets margin when seated normally.
			
			if(BASKETS.isfixed) {
				
				BASKETS.animate({ 'left': BASKETS.os.left }, 500);
			}
		});
	}

	// drop down lists (selects)
	if($("input.selectbox").length > 0)
	{
		// homepage specific panels & inputs
		if($("body").hasClass("home"))
		{
			// set inputs up for validation
			ddInputs =
			{
				master: [
					"ctl00_CPH1_DDPGIdeas", "ctl00_CPH1_DDIndustryIdeas", "ctl00_CPH1_DDThemedIdeas", "ctl00_CPH1_DDPGProducts", 
					"ctl00_CPH1_txtKeyword", "ctl00_CPH1_scprodref", "ctl00_CPH1_DDSuppliersDir", "ctl00_CPH1_DDPriceRanges", "ctl00_CPH1_DDShapes", "ctl00_CPH1_DDColours", "ctl00_CPH1_DDBrands",
					"ctl00_CPH1_DDTradeServices", "ctl00_CPH1_DDProductBySuppliers", "ctl00_CPH1_DDMarkingService", "ctl00_CPH1_DDTradeBody", "ctl00_CPH1_ddShotgunGroup",
					"ctl00_CPH1_DDExpressTime", "ctl00_CPH1_DDExpressPriceRange"
				],
				multisearchpad: {
					type: $("input#ctl00_CPH1_txtMSType"),
					value: $("input#ctl00_CPH1_txtMSValue")
				},
				ideassearch: {
					type: $("input#ctl00_CPH1_txtISType"),
					value: $("input#ctl00_CPH1_txtISValue"),
					disable: {
						ctl00_CPH1_DDPGIdeas: $("#ctl00_CPH1_DDIndustryIdeas, #ctl00_CPH1_DDThemedIdeas, #ctl00_CPH1_DDPGProducts"),
						ctl00_CPH1_DDIndustryIdeas: $("#ctl00_CPH1_DDPGIdeas, #ctl00_CPH1_DDThemedIdeas, #ctl00_CPH1_DDPGProducts"),
						ctl00_CPH1_DDThemedIdeas: $("#ctl00_CPH1_DDPGIdeas, #ctl00_CPH1_DDIndustryIdeas, #ctl00_CPH1_DDPGProducts"),
						ctl00_CPH1_DDPGProducts: $("#ctl00_CPH1_DDPGIdeas, #ctl00_CPH1_DDIndustryIdeas, #ctl00_CPH1_DDThemedIdeas"),
						ALL: $("#ctl00_CPH1_DDPGIdeas, #ctl00_CPH1_DDIndustryIdeas, #ctl00_CPH1_DDThemedIdeas, #ctl00_CPH1_DDPGProducts, #ctl00_CPH1_DDExpress")
					}
				},
				productsearch: {
					type: $("input#ctl00_CPH1_txtPSType"),
					value: $("input#ctl00_CPH1_txtPSValue"),
					disable: {
						ctl00_CPH1_txtKeyword: $("#ctl00_CPH1_scprodref"),
						ctl00_CPH1_scprodref: $("#ctl00_CPH1_txtKeyword, #ctl00_CPH1_DDPriceRanges, #ctl00_CPH1_DDColours, #ctl00_CPH1_DDShapes, #ctl00_CPH1_DDBrands"),
						//ctl00_CPH1_DDBrands: $("#ctl00_CPH1_scprodref, #ctl00_CPH1_txtKeyword, #ctl00_CPH1_DDShapes, #ctl00_CPH1_DDPriceRanges, #ctl00_CPH1_DDColours"),
						ALL: $("#ctl00_CPH1_scprodref, #ctl00_CPH1_txtKeyword, #ctl00_CPH1_DDPriceRanges, #ctl00_CPH1_DDColours, #ctl00_CPH1_DDShapes, #ctl00_CPH1_DDBrands")
					}
				},
				suppliersearch: {
					type: $("input#ctl00_CPH1_txtSSType"),
					value: $("input#ctl00_CPH1_txtSSValue"),
					disable: {
						ctl00_CPH1_DDSuppliersDir: $("#ctl00_CPH1_DDTradeServices, #ctl00_CPH1_DDProductBySuppliers, #ctl00_CPH1_DDMarkingService, #ctl00_CPH1_DDTradeBody"),
						ctl00_CPH1_DDTradeServices: $("#ctl00_CPH1_DDSuppliersDir, #ctl00_CPH1_DDProductBySuppliers, #ctl00_CPH1_DDMarkingService, #ctl00_CPH1_DDTradeBody"),
						ctl00_CPH1_DDProductBySuppliers: $("#ctl00_CPH1_DDSuppliersDir, #ctl00_CPH1_DDTradeServices, #ctl00_CPH1_DDMarkingService, #ctl00_CPH1_DDTradeBody"),
						ctl00_CPH1_DDMarkingService: $("#ctl00_CPH1_DDSuppliersDir, #ctl00_CPH1_DDTradeServices, #ctl00_CPH1_DDProductBySuppliers, #ctl00_CPH1_DDTradeBody"),
						ctl00_CPH1_DDTradeBody: $("#ctl00_CPH1_DDSuppliersDir, #ctl00_CPH1_DDTradeServices, #ctl00_CPH1_DDProductBySuppliers, #ctl00_CPH1_DDMarkingService"),
						ALL: $("#ctl00_CPH1_DDTradeBody, #ctl00_CPH1_DDSuppliersDir, #ctl00_CPH1_DDTradeServices, #ctl00_CPH1_DDProductBySuppliers, #ctl00_CPH1_DDMarkingService")
					}
				},
				shotgunsearch: {
					type: $("input#ctl00_CPH1_txtSGType"),
					value: $("input#ctl00_CPH1_txtSGValue") 
				},
				expresssearch: {
					type: $("input#ctl00_CPH1_txtEDType"),
					value: $("input#ctl00_CPH1_txtEDValue")
				}
			}
		}
		
		$("body.home #itemtypesearch div.search input").click(function(e) {
			if($("input#ctl00_CPH1_itemtypeSearchKeyword").val() == "")
			{
				e.preventDefault();
				smlTooltip.call("<p>Please ensure you have typed at least one keyword!</p>", "ctl00_CPH1_itemtypeSearchKeyword");
			} else {
				return true;
			}
		});
		$("body.home input#ctl00_CPH1_txtKeyword, body.home input#ctl00_CPH1_scprodref, body.home #ctl00_CPH1_itemtypeSearchKeyword").bind("keypress", function(e) {
			
			var $this 	= $(this);
			var val 	= $this.val();
			var key 	= e.which;
			var words 	= $this.val().split(" ");
			var id 		= $this.attr("id");
			var count 	= ( id == "ctl00_CPH1_itemtypeSearchKeyword" ) ? 2 : 4; // this is the number of words to limit the search to.
			
			if( ( id == "ctl00_CPH1_txtKeyword" || id == "ctl00_CPH1_itemtypeSearchKeyword" ) && key != 8 && key != 0 && words.length > count ) {
			
				smlTooltip.call("The less words searched the broader your results.<br />Search is limited to "+ count +" words to give you the best results.", id );
				return false;
			
			} else if ( id == "ctl00_CPH1_itemtypeSearchKeyword" ) {
				
				return;
			}
			
			if(val == "" && key == 13)
			{
				smlTooltip.call("Please enter the keyword(s) you wish to search for!", id );
				$this.focus().prev().addClass("hide");
				return false;
				
			} else if(val != "" && key == 13) {
				
				$this.attr("master", "true");
				return true;				
			}
			
		});
		$("body.home #productsearch input#ctl00_CPH1_txtKeyword").bind("blur", function(e) {
			var $this = $(this);
			if($this.val() != "") {
				$this.attr("master", "true");
			}
		});
		$("body.home #productsearch input#ctl00_CPH1_scprodref").bind("blur", function(e) {
			$activeInput = $(this);
			if($activeInput.val() != "") {
				$activeInput.attr("master", "true");
				disableInputs("productsearch");
			}
		});
		$("body.home #ideassearch div.search input").click(function(e) {
			
			setValues($(this), "ideassearch", $("#ideassearch"), e);
		});
		$("body.home #productsearch div.search input").click(function(e) {
			
			setValues($(this), "productsearch", $("#productsearch"), e);
		});
		$("body.home #suppliersearch div.search input").click(function(e) {
			
			setValues($(this), "suppliersearch", $("#suppliersearch"), e);
		});
		$("body.home #shotgunsearch div.search input").click(function(e) {
			
			setValues($(this), "shotgunsearch", $("#shotgunsearch"), e);
		});
		$("body.home #expresssearch div.search input").click(function(e) {
			
			//setValues($(this), "expresssearch", $("#expresssearch"), e);
		});

		$("body.home #columnB label:has(input.selectbox)").bind("click", checkDisabled);
		$("body.home #columnB label:has(input.selectbox) input").bind("blur", bindSelectBox);
		$("input.selectbox").each(setupSelectBox);
	}
	
	// hide add to favourites
	if(!$.browser.msie)
	{
		$("#set-homepage").hide();
	}
	
	$("#tooltip-lg .close").livequery("click", closeTooltip);
	
	// left hand side search by panel
	var ddtitle;
	$("#searchby li a").bind("mouseover", function() {												   
		var $this = $(this);
		ddtitle = $this.attr("title");
		$this.removeAttr("title");
		$(this).parent().next("li").addClass("over");		
	}).bind("mouseout", function() {		
		var $this = $(this);
		if(ddtitle) $this.attr("title", ddtitle);
		$this.parent().next("li").removeClass("over");		
	});
		
	if($("body").hasClass("results") && ie6)
	{
		$("label.get-supplier").click(function() {
			$(this).children("input:eq(0)").attr("checked", !$(this).children("input:eq(0)").attr("checked"))
		});
	}
	$("label.select-all").click(function() {
		$(".listing input[type='checkbox']").attr("checked", $(this).children("input").attr("checked"));
	});
	$("img.clear-all").click(function() {
		$(".listing input[type='checkbox']").attr("checked", false);
		$(this).siblings("label.select-all").find("input[type='checkbox']").attr("checked", false);
	});
	
});

function printPopup() {
	window.open('print.html','','fullscreen=no,resizable=1,width=700,height=700,top=40,left=40,menubar=yes,scrollbars=yes');
	return false;
};

function loadInfo() {
	var referrer = window.opener.location;
	var refer = referrer + " table#preview-email";
	
	if (referrer == "http://www.sourcingcity.co.uk/getsuppliers.aspx" || referrer == "http://192.168.7.123/sourcingcity3.co.uk/getsuppliers.aspx") {
		refer = referrer + " div.suppliers";
	}
	if (referrer == "http://www.sourcingcity.co.uk/getprices.aspx" || referrer == "http://192.168.7.123/sourcingcity3.co.uk/getprices.aspx") {
		refer = referrer + " div.confirm";
	}
	if (referrer == "http://www.sourcingcity.co.uk/SearchResults.aspx.aspx" || referrer == "http://192.168.7.123/sourcingcity3.co.uk/SearchResults.aspx") {
		// refer = referrer + " div.char";
	}
	
	$(".content").load(refer, function() {
		window.print();									   
	});

};

/*#################################### END DOM READY */
$(window).load(function() {

	//development- page load monitoring
	// console.log("PAGE LOAD TIME: "+ (((new Date()).getTime() - BEGAN_LOADING) / 1000));

	// $("#ticker ul#tickerscroll").liScroll(); 

	// this sets bg colour to the orange fade, as initial colour is purple so that its easier on the eyes!
	$("body").css({ backgroundColor: "#e95815" });
	
	if( $("#ctl00_search_keywords").val() != "" )
	{
		$("#ctl00_search_keywords").prev().addClass("hide");
	}

	if($.browser.msie)
	{
		$("body").append("<style type=\"text/css\"></style>");// this seems to fix bizarre layout issues in ie6 ?!
		try {
			document.execCommand('BackgroundImageCache', false, true); // IE6 background image flicker fix.
		} catch(e){}
		
		// add to favourites IE only
		$("#footer #set-homepage").click(function() {	 
			if($.browser.msie) 
			{
				document.body.style.behavior = 'url(#default#homepage)';
				document.body.setHomePage(window.location.href);
				return false;
			}
		});
	}
	
	try {
		$(".result img.thumb").draggable(options.draggable);
		$(".dragzone").droppable(options.droppable);
	}catch(e){}
	
});

// below is the result of a lot of changes, additional requests and unforseen circumstances!
// could've and should've been cleaner but grew to accomodate the the requests!
var smlTooltip = {
	visible: false,
	index: false,
	className: "supplier-websites",
	call: function(content, elem, options) {
		
		var opts  =  options || { left: 0, top: 0 }
		var $elem = $("#"+ elem).length > 0 ? $("#"+ elem) : false;
		var minus = elem == "tt-dynamic-office" ? 15 : 0;		// more dodgy fix for positioning for dyn office tooltip
		
		// if(!$elem)
		// {
			// console.error("No element supplied, please report this to the system administrator.\nContent supplied: "+ content);
			// return false;
		// }
		
		smlTooltip.append("sml");
		$smlTooltip = $("#tooltip-sml");
		
		cursor("default");
		
		cont = function() {
			var width = $smlTooltip.css({ width: "auto" }).width();
			width = width > 500 ? 500 : width;
			$smlTooltip.width(width);
			var position = $elem.offset();
			var dimensions = {
				w: width / 2,
				h: $smlTooltip.height() + minus,
				eh: $elem.height(),
				ew: $elem.width()
			}
			position.left = ( ( position.left - dimensions.w ) + ( dimensions.ew / 2 ) + 15 ) + opts.left;
			position.top = position.top - dimensions.h - 42 + ( dimensions.eh / 2 );
			$smlTooltip.css({ display: "none", top: position.top, left: position.left });
			if(opts.aleft) { $(".arrow", $smlTooltip).css({ left: opts.aleft }) }
			
			smlTooltip.show("#tooltip-sml");
			
			var ie6 = ($.browser.msie && parseInt($.browser.version) <= 6) ? true : false;
			var $content = $smlTooltip.find(".content");
		
			if( ie6 ) 
			{
				var ieheight = $smlTooltip.outerHeight(); 
				$smlTooltip.bgiframe();
				$("#tooltip-sml .right-bdr, #tooltip-sml .left-bdr").css({ height : ieheight - 30 });	
			}	
									
			$("#tooltip-sml div.close").bind("click", function() {
				if($(".ui-draggable").length > 0) bindDD();
				smlTooltip.close("#tooltip-sml");
			});
		}
		$("#tooltip-sml .content").html(content);
		cont();
	},
	login: function(elem) {
		var $ttlogin = $("#tooltip_login");
		var width = $ttlogin.css({ width: "350px" }).width();
		var pos = { left: 424 - ( width / 2 ), top: returnCenter( $ttlogin.outerHeight() ) }
		var anim = $.browser.msie ? "show()" : "fadeIn(500)";
		var ie6 = ($.browser.msie && parseInt($.browser.version) <= 6) ? true : false;
		var $content = $ttlogin.css({ top: "-9999em", left: "-9999em" }).show().find(".content");
		
		if( ie6 ) 
		{
			var ieheight = $content.outerHeight(); 
			$ttlogin.bgiframe();	
			$("#tooltip_login .right-bdr, #tooltip_login .left-bdr").css({ height : ieheight });
		}

		cursor("default");

		$ttlogin.width( width );
		eval('$ttlogin.css({ display: "none", top: pos.top, left: pos.left }).'+ anim);

		$("div.close", $ttlogin).bind("click", function() {
			
			if($(".ui-draggable").length > 0) bindDD();
			smlTooltip.close("#tooltip_login");
			
		});		
	},
	close: function(elem) {
		if($.browser.msie) {
			
			$( elem ).hide().remove();
			
		} else {
			$( elem ).fadeOut(500, function() {				
				
				$(this).remove();				
			});
		}
		smlTooltip.visible = false;
		smlTooltip.index = false;
	},
	show: function(e, index) {
		var index = index || false;
		if($.browser.msie) {
			$(e).show();
			smlTooltip.visible = true;
			smlTooltip.index = index;
		} else {
			$(e).fadeIn(500, function() {
				smlTooltip.visible = true;
				smlTooltip.index = index;
			});
		}
	},
	append: function(className) {
		if($("#tooltip"+ className).length == 0)
		{
			var elem = className == "lg" ? "#wrap-glow" : "body";
			$( elem ).append('<div class=\"tooltip-'+ className +'\" id="tooltip-'+ className +'">\n\t<div class="wrapper">\n\t<div class="top-wrapper">\n\t<div class="top-left"></div>\n\t<div class="top-bdr"></div>\n\t<div class="top-right"></div>\n\t</div>\n\t<div class="middle-wrapper clear">\n\t<div class="left-bdr"></div>\n\t<div class="content clear"></div>\n\t<div class="right-bdr"></div>\n\t</div>\n\t<div class="bottom-wrapper">\n\t<div class="bottom-left"></div>\n\t<div class="bottom-bdr"></div>\n\t<div class="bottom-right"></div>\n\t</div>\n\t<div class="arrow"></div>\n\t<div class="close"></div>\n\t</div>\n</div>');
			return true;
			
		} else {
			
			return false;
		}
	},
	moreinfo: function(elem) {
		var $ttmore = $("#tooltip_moreinfo");		
		var height = $ttmore.css({ top: "-9999em", left: "-9999em", display: "block" }).outerHeight();
		
		lgTooltip.init("a.print");
		
		$ttmore
		.css({ display: "none", top: returnCenter( height ), left: "160px" })
		
		if($.browser.msie)
		{
			$ttmore.show();			
		} else {
			$ttmore.fadeIn(500);
		}

		var ie6 = ($.browser.msie && parseInt($.browser.version) <= 6) ? true : false;
		var $content = $ttmore.find(".content");
		
		if( ie6 ) 
		{
			var ieheight = $content.outerHeight(); 
			$ttmore.bgiframe();
			$("#tooltip_moreinfo .right-bdr, #tooltip_moreinfo .left-bdr").css({ height : ieheight });
		}

		$(".thumb", $ttmore).draggable( options.draggable );
	
		$("div.close", $ttmore).bind("click", function() {
			
			if($(".ui-draggable").length > 0) bindDD();
			smlTooltip.close("#tooltip_moreinfo");
		});
	},
	init: function() {
		$("."+ this.className +"").bind("click", function() {
														  
			smlTooltip.append("sml");
			
			var $this = $(this);
			var index = $( $this.get(0).tagName.toLowerCase() ).index(this);
			if(smlTooltip.visible && smlTooltip.index == index)
			{
				return false;
			}
			var copy = $this.prev("div").html();
			var offset = $this.offset();
			var height = $("#tooltip-sml .content")
			.html( copy )
			.parents("#tooltip-sml")
			.css({ top: "-9999em", left: "-9999em", display: "block" })
			.find(".content")
			.outerHeight();
					
			$("#tooltip-sml")
			.hide()
			.css({ top: (offset.top - ( $("#tooltip-sml").height() + 45 ) ), left: ( offset.left - ( ( $("#tooltip-sml").width() / 2 ) - 60 ) ) })
			.find(".right-bdr, .left-bdr")
			.css({ height: height });
			
			smlTooltip.show("#tooltip-sml", index);

			$("#tooltip-sml div.close").bind("click", function() {
				if($(".ui-draggable").length > 0) bindDD();
				smlTooltip.close("#tooltip-sml");
			});
		});
	}
}

var lgTooltip = {
	visible: false,
	index: false,
	init: function(element) {
		/* if(!element)
		 {
			 console.error("No element passed - large tooltip not bound!");
			 return false;
		 } */
		
		$( element ).bind("click", function(e) {
			
			e.preventDefault();
			$activeButton = $(this);
			
			var index  		= $( $activeButton.get(0).tagName.toLowerCase() ).index(this);
			var href   		= $activeButton.attr("href");
			var className  	= $activeButton.attr("class");
			var type   		= $activeButton.attr("rel") || "tooltip";
			
			if(lgTooltip.visible && lgTooltip.index == index) 
			{
				return false;
				
			} else if($("#tooltip-lg").length == 0)	{
				
				smlTooltip.append("lg");
				$tooltip = $("#tooltip-lg");
			}
			
			if(className == "calc")
			{
				var $prevInput = $activeButton.prev().find("input");
				$markupInput = $activeButton.next().find("input");
				var price = $prevInput.val();
				if(price == "" || price === undefined)
				{
					smlTooltip.call("You must first specify a cost price for this item!", $prevInput.attr("id"));
					return false;
					
				} else {
					href += "?c="+ price;
				}
			}
			
			$.ajax({
				dataType: "html",
				type: "GET",
				timeout: 30000,
				url: href,
				error: function() {
					// console.error("failed to load url: "+ href +" | timeout set to: "+ this.timeout);
					$tooltip.remove();
				},
				success: function(data) {
					
					$("#tooltip-lg .content").html( data );
					
					var $content = $tooltip.css({ top: "-9999em", left: "-9999em" }).show().find(".content");				
					var height   = $tooltip.outerHeight();
					var width    = $tooltip.outerWidth();
					var ie6 = ($.browser.msie && parseInt($.browser.version) <= 6) ? true : false;

					if( ie6 ) 
					{
						var ieheight = $content.outerHeight(); 					
						
						$("#tooltip-lg").bgiframe();	
						$("#tooltip-lg .right-bdr, #tooltip-lg .left-bdr").css({ height : ieheight });
					}
					
					switch( type )
					{
						//case "print":
						//	var left = 160;
						//	break;
						case "report":

							var left = ( 848 - width ) / 2;
							break;
						default:
							var left = ( 848 - width ) / 2;
							break;						
					}
					
					$tooltip.hide().css({ top: returnCenter( height ), left: left });

					if(type == "tooltip")
					{				
						if(className == "calc") 
						{
							$("#tooltip-lg div.close").remove();
							$("#tooltip-lg input.close").click(function(e) {
								e.preventDefault();
								closeTooltip();
							});
						}
						
					} else {
						
						// $("#tooltip-lg .arrow").after("<div id=\"print\"></div>");
						$("div#print").click(function() {
							window.print();
						});
					}
					
				},
				complete: function(xml, status) {
					if(status != "error")
					{
						if($.browser.msie || type == "report") {
							
							$tooltip.show();
							lgTooltip.visible = true;
							lgTooltip.index = index;
							
						} else {
							
							$tooltip.css({ opacity: "0", display: "block" });
							$tooltip.animate({ opacity: "1", top: "-=20px" }, 500, function() { // top: "-=20px"
								lgTooltip.visible = true;
								lgTooltip.index = index;
							});
						}
					} /* else {
						console.error("error status: "+ xml.statusText +" (error code: "+ xml.status +")");
					} */
				}
			});
		});
	}
}

// this is used fired by .net to animate basket and fade in item accordingly
// doesn't work as was intended due to .net
var appendItem = function(basket, count) {
	
	var $basket = $("#"+ basket);
	var $wrapper = $basket.find(".wrapper");
	var $li = $basket.find("li:hidden");
	var toHeight = options.basket.hInitial +"px"
	var dur = 800;

	if($li.length < 1) return false;

	if( count != 1 )
	{
		toHeight = ( options.basket.hItem * count ) + 60 +"px";
		dur = 300;
	}
	
	$wrapper.animate({ height: toHeight }, dur, function() {
		$li.fadeIn(500);
		$(".actions input", $wrapper).fadeIn(500);
	});
	
	bindDD();
	cursor("default");
	
}

// rebind drag n drop - 
//	function for .net update panel as we can't monitor dom additions/amends as with .live()
var bindDD = function() {
	$(".result img.thumb").draggable(options.draggable);
	$(".dragzone").droppable(options.droppable);
}

// options object for draggables, droppables and basket li's
var options = {
	droppable: {
		accept: "img.thumb",
		activate: function() {
			$(".pad").addClass("active");
		},
		deactivate: function() {
			$(".pad").removeClass("active");
		},
		over: function() {
			$(".pad").removeClass("active");
			$(this).parents(".pad:first").addClass("active");
		},
		out: function() {
			$(".pad").addClass("active");
		},
		fit: "touch",
		drop: function(e, ui) {
			
			var $pad = $(this);
			var basket = $pad.attr("bid")
			var $product = $("#"+ ui.draggable.attr("pid") );
			
			switch(basket) 
			{
				case "ideaslist":
					eq = 0;
					break;
				case "quotation":
					eq = 1;
					break;
				case "eshot":
					eq = 2;
					break;
			}
			
			var $button = $(".actions a:eq("+ eq +")", $product );
			var href 	= $button.attr("href");
			
			cursor("wait");
			
			if( href === undefined || href == "" )
			{
				smlTooltip.call("<p>This product is already in your basket!</p>", $product.attr("id") );
				return false;
			}
			$button.bind("click", function() {
				window.location = href;
			}).trigger("click");
		}
	},
	draggable: {
		helper: "clone",
		zIndex: "5000", 
		opacity: "0.6", 
		revert: "invalid", 
		revertDuration: "250",
		addClasses: false
	},
	basket: {
		hEmpty: 4,
		hItem: 20,
		hInitial: 77
	}
}