//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["suckertree1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
	for (var i=0; i<menuids.length; i++){
		var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
		for (var t=0; t<ultags.length; t++){
			ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
			ultags[t].parentNode.getElementsByTagName("a")[0].innerHTML=ultags[t].parentNode.getElementsByTagName("a")[0].innerHTML + "&nbsp;&nbsp;&nbsp;&#187"
			if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
				ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
			else //else if this is a sub level submenu (ul)
				ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
			ultags[t].parentNode.onmouseover=function(){
				this.getElementsByTagName("ul")[0].style.display="block"
			}
			ultags[t].parentNode.onmouseout=function(){
				this.getElementsByTagName("ul")[0].style.display="none"
			}
		}

		for (var t=ultags.length-1; t>-1; t--) { //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
			ultags[t].style.visibility="visible"
			ultags[t].style.display="none"
		}
	}
} // Function buildsubmenus

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)

//------------------------------------------------------------------------------------------------------------------------------------------------------
// Routines for using the API for fleshing out the listings
function getItem(itemid)
{
	var sMyAppId = "JoshuaMa-0866-49fb-ae1f-dceacedb49ed" ;

	var bodyTag = document.getElementsByTagName("body").item(0);
	var scriptTag = document.createElement("script");
	scriptTag.src = "http://open.api.ebay.com/shopping?version=515&callname=GetSingleItem&ItemID=" + itemid + "&responseencoding=JSON&appid=" + sMyAppId + "&callback=true&IncludeSelector=Details,ItemSpecifics,ShippingCosts";
	bodyTag.appendChild( scriptTag );
}

function _cb_GetSingleItem(root)
{
	var item = root.Item;
	var html = [];
	var sText = '';
	var sShipping = "";
	
	if (null == item) return;
	if (null != item.ShippingCostSummary.ShippingType) 
		sShipping = item.ShippingCostSummary.ShippingType;
	if (sShipping == "Flat") {
	    if (null != item.ShippingCostSummary.ShippingServiceCost) {
			var s2 = item.ShippingCostSummary.ShippingServiceCost.Value;
			if ((s2 == 0) || (s2 == "0.0")) {
				sShipping = "Free"
			} else {
				sShipping = 'US $' + s2;
			}
		}	
	}

	sText = '<span style="font-weight:normal"><u>Seller:</u> ' + item.Seller.UserID ;
    if (null != item.Seller.FeedbackScore) {
		sText = sText +	" (" + item.Seller.FeedbackScore + ") " + item.Seller.PositiveFeedbackPercent + "%<br />";
	}
	if (sShipping != "")
		sText = sText +	"<u>Shipping:</u> " + sShipping  + "<br />" ;
    if ((null != item.Location) && (null != item.Country)) {
		sText = sText +	"<u>Location:</u> " + item.Location + ", " + item.Country + "</span>";
	}	
//	alert(item.ItemID);
	      
	// Find the links in the item
	var links = document.getElementsByTagName("a");
	for (var i = 0; i<links.length; i++) {
		if (links[i].href.search(item.ItemID) > -1) {
		    // Change the item text
		    var str = links[i].innerHTML
			str = str.replace(/<span><\/span>/i, '<br />' + sText);
			links[i].innerHTML = str;
			// Keep looping because there are multiple auctions with the same id
		}
	}
}

function FixLinks()
{
	// Find the links in the item
	var links = document.getElementsByTagName("a");
	for (var i = 0; i<links.length; i++) {
		if (links[i].href.search(document.domain+"/item-") > -1) {
			aUrl = links[i].href.split("_");
			itemid = aUrl[1];
			getItem(itemid);
		}
	}
} // FixLinks


