/* -- basic browser sniffer -- */
	var agt=navigator.userAgent.toLowerCase();
  // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
  var is_major = parseInt(navigator.appVersion);
  var is_minor = parseFloat(navigator.appVersion);
	var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
	            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
	            && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
	var is_nav6 = (is_nav && (is_major == 5));
	var is_nav6up = (is_nav && (is_major >= 5));
	var is_gecko = (agt.indexOf('gecko') != -1);
	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
  var is_ie3    = (is_ie && (is_major < 4));
  var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
  var is_ie4up  = (is_ie && (is_major >= 4));
  var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
  var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
  var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
  var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
	var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
	var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
/* -- end sniffer -- */
function printfire() { try { console.log.apply(console.log, arguments); } catch(e) {}}

/* -- 
		popDetailsList is a class that handles detail popups and basic template parsing
		instantiate the object and pass in:
		details - the object of details (see below)
		observers - the items you want the user to interact with to show the popup
		links - an array of links or of anchor tags to link the whole popup to
		observerAction - either "mouseover" or "click" to determine what the user
		            has to do to show the item. Note: if you choose click, you must
								set your own overserver to hide the item.
		listName - when you instantiate the item (var X = new popDetailsList(...);)
		           include, as a string, the name of the item (...new popDetailsList(..., "X"))
		template - the html template or an id of a DOM element that contains it.
		offsety - the vertical offset of the item from the observer
		offsetx - the horizontal offset
		effectDurationOn - how long the fade in should take in milliseconds
		effectDurationOff - how long the fade out should take in milliseconds
		effectDelayOn - for mouseover, how long to wait after the user mousesover before you show the element
		effectDelayOff - for mouseout, how long to wait after the user mousesout before you show the element
		iframeShimSelector - the css selector *within your template* that should have 
								an iframe shim under it to obscure select lists and the like.
		linkItems - make the whole popup clickable
 -- */
var popDetailsList = Class.create();
popDetailsList.prototype = {
	linkItems: true,
	initialize: function(args) {
		try {
			this.template = $(args.template).innerHTML;
		} catch(e) {
			this.template = args.template;
		}
		this.observerAction = args.observerAction;
		this.listName = args.listName;
		this.observers = args.observers;
		this.links = args.links;
		if(typeof args.linkItems != "undefined") this.linkItems = args.linkItems;
		this.observeCorner = args.observeCorner;
		this.details = args.details;
		this.offsetx = args.offsetx;
		this.offsety = args.offsety;
		this.effectDurationOn = args.effectDurationOn;
		this.effectDurationOff = args.effectDurationOff;
		this.effectDelayOn = args.effectDelayOn;
		this.effectDelayOff = args.effectDelayOff;
		this.isMoused = [];
		this.isMousedShown = [];
		this.popupHTML = [];
		this.renderedDOMElement = [];
		this.fxObjs = [];
		if (this.observers.length != this.details.length) {
			printfire("warning: observers and details are out of synch");
		}
		this.setUpObservers();
		var popupHolder = document.createElement('div');
		if (is_ie && typeof args.iframeShimSelector != "undefined") {
			this.shims = [];
			this.iframeShimSelector = args.iframeShimSelector;
		} else {
			this.shims = false;
		}
	},
	setUpObservers: function () {
		var pdl = this;
		$A(this.observers).each(function(el, index) {
			var onAction = "mouseover";
			if (pdl.observerAction == "click") {
				onAction = "click";
			}
			Event.observe(el, onAction, function() {
				pdl.observed = index;
				setTimeout(pdl.listName + ".makePopup(" + index + ")", pdl.effectDelayOn);
			});
			if (onAction != "click") {
				Event.observe(el, "mouseout", function() {
					setTimeout(pdl.listName + ".removePopup(" + index + ")", pdl.effectDelayOff);
					pdl.observed = -1;
				});
			}
		});
	},
	makePopup: function (index) {
		values = this.details[index];
		if (values && this.observed == index) {
			try {
				if(this.fxObjs[index].off.now <= 0) {
					this.fxObjs[index].on.custom(0,1);
					this.fxObjs[index].off.now = 0.9999;
					if(this.shims) $(this.shims[index]).style.display = "block";
					setTimeout(this.listName + ".checkObserver(" + index + ");", this.effectDurationOn + this.effectDelayOn + 50);
				}
			} catch(e) {
				this.popupHTML[index] = this.template;
				for(key in values) {
					var replaceRegex = new RegExp("%"+key+"%","g");
					this.popupHTML[index] = this.popupHTML[index].replace(replaceRegex, values[key]);
				}
				if (! $(this.renderedDOMElement[index])) {
						var DOMel = document.createElement('div');
						DOMel.id = this.listName + '_popupHTML_' + index;
						this.renderedDOMElement[index] = DOMel.id;
						DOMel.innerHTML = this.popupHTML[index];
						var pos = Position.cumulativeOffset(this.observers[index]);
						if(this.observeCorner == "upperRight") {
							pos[0] = pos[0] + this.observers[index].offsetWidth;
						} else if (this.observeCorner == "bottomRight") {
							pos[0] = pos[0] + this.observers[index].offsetWidth;
							pos[1] = pos[1] + this.observers[index].offsetHeight;
						} else if (this.observeCorner == "bottomLeft") {
							pos[1] = pos[1] + this.observers[index].offsetHeight;
						}
						DOMel.style.position = "absolute";
						DOMel.style.left = (pos[0] + this.offsetx) + "px";
						DOMel.style.top = (pos[1] + this.offsety) + "px";
						DOMel.style.visibility = "hidden";
						DOMel.style.display = "none";
						document.body.appendChild(DOMel);
						this.fxObjs[index] = {};
						this.fxObjs[index].on = new fx.Opacity(DOMel.id, {duration: this.effectDurationOn});
						this.fxObjs[index].off = new fx.Opacity(DOMel.id, {duration: this.effectDurationOff});
						DOMel.style.visibility = "hidden";
						DOMel.style.display = "block";
					if (this.shims) {
						var innerEl = this.iframeShimSelector.getElementsBySelector($S(DOMel))[0];
						var innerElPos = Position.cumulativeOffset(innerEl);
						var shm = document.createElement('iframe');
						shm.id = this.listName + "_shim_" + index;
						this.shims[index] = shm.id;
						shm.style.position = "absolute";
						shm.style.zIndex = "50";
						DOMel.style.zIndex = "51";
						shm.style.border = "none";
						shm.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
						shm.setAttribute('src', 'javascript:false;');
						shm.setAttribute('frameborder', '0');
						shm.setAttribute('scrolling', 'no');
						shm.style.left = innerElPos[0] + "px";
						shm.style.top = innerElPos[1] + "px";
						shm.style.width = innerEl.offsetWidth;
						shm.style.height = innerEl.offsetHeight;
						shm.style.display = "block";
						document.body.appendChild(shm);
					}
					var DOMelId = DOMel.id;
					DOMel = null;
					var pdl = this;
					Event.observe(DOMelId, "mouseover", function() {
						pdl.observed = index;
					});
					if(pdl.observerAction != "click") {
						Event.observe(DOMelId, "mouseout", function() {
							setTimeout(pdl.listName + ".removePopup(" + index + ")", pdl.effectDelayOff);
							pdl.observed = -1;
						});
					}
					if(this.linkItems) {
						$(DOMelId).style.cursor = "pointer";
						Event.observe(DOMelId, "click", function() {
							try {
								if(typeof pdl.links[index].href != "undefined")
									window.location.href = pdl.links[index].href;
								else
									window.location.href = pdl.links[index];
							} catch(e) {
								try {
									window.location.href = pdl.links[index];
								} catch(e) {
								}
							}
						});
					}
					this.fxObjs[index].on.custom(0,1);
					setTimeout(this.listName + ".checkObserver(" + index + ");", this.effectDurationOn + this.effectDelayOn + 50);
				}
			}
		}
	},
	checkObserver: function (index) {
		if (this.observed != index) {
			this.removePopup(index);
		}
	},
	removePopup: function(index, force) {
		try {
			if (this.observed != index ||  force) {
				if (this.fxObjs[index].on.now > 0) {
					this.fxObjs[index].off.custom(1,0);
					this.fxObjs[index].on.now = 0;
					if (this.shims) $(this.shims[index]).style.display = "none";
				}
			}
		} catch(e) {}
	}
}




/* -- 	//set up the instance of our popDetailsList object and attach it to the onload event of the window
	var dlListingPopups = null;
  Event.observe(window,"load",function() {
    		//get all the product links by css selector
    		var prodLinks = $S("table#dl-tbl-list th.titleCell a.prod");
    		//instantiate our object
    			dlListingPopups = new popDetailsList({
						details: titleDetails, 
						observers: prodLinks, 
						links: prodLinks, 
						observeCorner: "upperRight", 
						observerAction: "mouseover", 
						listName: "dlListingPopups", 
						template: "popupDetailHTML", 
						offsety: -145, 
						offsetx: 30, 
						effectDurationOn: 250, 
						effectDurationOff: 150, 
						effectDelayOn: 500, 
						effectDelayOff: 1000, 
						iframeShimSelector: "div.popupDetails"
				});
	}); -- */
