/* WheeDesigns ProtoType version
document.observe("dom:loaded", function() {
	if (document.getElementById('ordering')) { 
		var WDshop = document.forms['prod_detail_form'].storeid.value;
		var WDsection = document.forms['prod_detail_form'].s.value;
		var url = WDshop + "/" + WDsection;
		
		new Ajax.Request(url, {
			method: 'get',
			onSuccess: function(transport) {
				var elRP = $('related_prods');
				
				// Parse the Section Items table out of the AJAX response and place in into the 'related_prods' div
				var aryResponse = transport.responseText.split('<!-- ### Items ### -->');
				var txtSection = aryResponse[1].split('<!-- ### end of ITEMS ### -->');
				elRP.update(txtSection[0]);
				
				// Add the Related Products header
				Element.insert(elRP, {before: '<h2 id="op-title" style="font-size: 16px; color: #676; font-weight: bold;padding: 1px 4px 1px 0px;text-align: right;background-color: #fffdcd;border: 1px solid #ccc;	letter-spacing: 1px;margin: 0 0 15px 0px;">Related Products</h2>'});
				
				// Add the More Products Graphic Badge
				var elTD240 = getElementsByAttribute(document.body, 'td', 'width', '240');
				Element.insert(elTD240[0], {bottom: '<div style="margin: 40px 10px 20px;"><a href="' + url + '"><img src="http://www.wheedesign.com/images/more-badge.png" /></a></div>'});
			}
		});
	}
});


function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue) {
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)", "i") : null;
	var oCurrent;
	var oAttribute;
	for(var i=0; i<arrElements.length; i++){
		oCurrent = arrElements[i];
		oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
		if(typeof oAttribute == "string" && oAttribute.length > 0){
			if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
				arrReturnElements.push(oCurrent);
			}
		}
	}
	return arrReturnElements;
}
*/


/* Orinigal ThreadYourself jQuery version
$(document).ready(function() {

	if ( $("#ordering").length > 0 ) { 

		var shop = document.forms['prod_detail_form'].storeid.value;
		var section = document.forms['prod_detail_form'].s.value;
		$("#related_prods").before("<div id=\"op-title\" style=\"font-size: 16px; color: #676; font-weight: bold;padding: 1px 4px 1px 0px;text-align: right;background-color: #fffdcd;border: 1px solid #ccc;	letter-spacing: 1px;margin: 0 0 15px 0px;\">Related Products</div>");
		$("#related_prods").load(shop+"/"+section+" #main table",{},function() { 
			$("#related_prods table tr td").css({ padding: "0 0 15px 0 "});
			$("td[width=240]").append("<div style=\"margin: 40px 10px 20px; \"><a href=\""+shop+"/"+section+"\"><img src=\"http://www.wheedesign.com/images/more-badge.png\" /></a></div>");
		});
	}
});
*/

/* Must be run from an onLoad event in order to allow CP jQuery to load 
wdRelated = function() {
	if ( $("#ordering").length > 0 ) { 
		var shop = document.forms['prod_detail_form'].storeid.value;
		var section = document.forms['prod_detail_form'].s.value;
		var isScriptedPage = false;
		$("#related_prods").before("<div id=\"op-title\" style=\"font-size: 16px; color: #676; font-weight: bold;padding: 1px 4px 1px 0px;text-align: right;background-color: #fffdcd;border: 1px solid #ccc;	letter-spacing: 1px;margin: 0 0 15px 0px;\">Related Products</div>");
		$("#related_prods").load(shop+"/"+section+" #main table",{},function() {
		
			$("#related_prods table tr td").css({ padding: "0 0 15px 0 "});
			$("td[width=240]").append("<div style=\"margin: 40px 10px 20px; \"><a href=\""+shop+"/"+section+"\"><img src=\"http://www.wheedesign.com/images/more-badge.png\" /></a></div>");
		});
	}
}
*/

wdRelated = function() {
	if ( $("#ordering").length > 0 ) { 
		var shop = document.forms['prod_detail_form'].storeid.value;
		var section = document.forms['prod_detail_form'].s.value;
		var isScriptedPage = false;
		$("#related_prods").before("<div id=\"op-title\" style=\"font-size: 16px; color: #676; font-weight: bold;padding: 1px 4px 1px 0px;text-align: right;background-color: #fffdcd;border: 1px solid #ccc;	letter-spacing: 1px;margin: 0 0 15px 0px;\">Related Products</div>");
		$.getScript("http://wheedesign.com/wdrelated.php?StoreID="+shop+"&SectionID="+section+"", function(){
			var a = displayProducts();
			$("#related_prods").append( a );
			$("td[width=240]").append("<div style=\"margin: 40px 10px 20px; \"><a href=\""+shop+"/"+section+"\"><img src=\"http://www.wheedesign.com/images/more-badge.png\" /></a></div>");
		});
	}
}



