PLZ = {
	
	storeCategoryCollapsedHeight: 20,
	expandingInterval: false,
	expandedCategory: null,
	expandedNum: 0,
	expandedNumMax: 10,
	regularImageName: 'collapser.gif',
	selectedImageName: 'collapser_selected.gif',
	
	getItemDetail: function(cID) {
		if (PLZ.expandingInterval) {
			return false;
		}
		detail = document.getElementById("store-detail");
		window.scrollTo(0,0);
		ar = new Ajax.Request("/tools/store_detail.php", {parameters: 'cID=' + cID, onSuccess: function(xm) {
			
			innerDIVs = detail.getElementsByTagName("DIV");
			innerDIVs[0].innerHTML = xm.responseText;
			targetHeight = innerDIVs[0].offsetHeight + PLZ.storeCategoryCollapsedHeight;
			PLZ._doSlide(detail,targetHeight, true);
		
		}});
	
	},
	
	_doSlide: function(obj, targetHeight, keepOpen) {
		
		PLZ.clearCaption();	
		
		if (obj.id == PLZ.expandedCategory) {
			PLZ.collapseCategory();
			return;
		}
		
		if (!keepOpen) {
			if (PLZ.expandedCategory) {
				exObj = document.getElementById(PLZ.expandedCategory);
				collapsedHeight = (document.all) ? PLZ.storeCategoryCollapsedHeight + 18 : PLZ.storeCategoryCollapsedHeight;
				exObj.style.height = collapsedHeight + "px";
				exObj.className = "store-category-collapsed";
				PLZ.expandedCategory = null;
			}
		}
		
		PLZ.expandingInterval = setInterval(function() {
			currHeight = (!isNaN(parseInt(obj.style.height))) ? parseInt(obj.style.height) : 0;
			newHeight = parseFloat(currHeight + ((targetHeight - currHeight) * .36));
			newHeightInt = Math.round(newHeight);
			newHeightInt++;
			
			if ((targetHeight - newHeightInt <= 1 && targetHeight - newHeightInt > 0) || (newHeightInt - targetHeight <= 1 && newHeightInt - targetHeight > 0) || PLZ.expandedNum > PLZ.expandedNumMax) {
				obj.style.height = targetHeight + "px";
				clearInterval(PLZ.expandingInterval);
				PLZ.expandingInterval = false;
				PLZ.expandedNum = 0;
			}

			// we don't collapse the detail pane
				
			if (!keepOpen) {
				PLZ.expandedCategory = obj.id;
			}
				
			if (PLZ.expandingInterval) {
				obj.style.height = newHeightInt + "px";
				PLZ.expandedNum++;
			}
		}, 40);	
		
	},
	
	expandCategory: function(objID) {
		if (!PLZ.expandingInterval) {
			window.scrollTo(0,0);
			PLZ.swapArrow(PLZ.expandedCategory, objID);
			PLZ.swapOnClick(PLZ.expandedCategory, objID);	
			detail = document.getElementById("store-detail");
			detail.style.height = "0px";
			cat = document.getElementById(objID);
			innerDIVs = cat.getElementsByTagName("DIV");
			targetHeight = innerDIVs[0].offsetHeight + PLZ.storeCategoryCollapsedHeight;
	
			PLZ._doSlide(cat, targetHeight, false);		
		}		
	},
	
	highlightImage: function(obj) {
		obj.oldClass = obj.className;
		obj.className = "highlight";
	},
	
	clearHighlight: function(obj) {
		if (obj.oldClass == "active") {
			obj.className = "active";
			obj.oldClass = null;
		} else {
			obj.className = "";
		}
	},
	
	displayFontCaption: function(obj, caption) {
		if (PLZ.expandingInterval) {
			return false;
		}
		dc = document.getElementById("image-caption");
		dc.innerHTML = caption;
		dc.style.backgroundColor = "#ffffff";
		
		x = ccmFindX(obj);
		y = ccmFindY(obj);
		x = x + 0;
		y = y + 0;
		
		if (document.all) {
			w = obj.width;
			x = x + 1;
			y = y + obj.height; // i don't know why
			//y = y + obj.height;
		} else {
			w = obj.width - 5; // allowing borders & padding
			y = y + obj.height;
			//dc.style.paddingTop = 0;
			//y = y + obj.height;
		}
		w = w + 2;
		dc.style.width = w + "px";		
		dc.style.top = y + "px";
		dc.style.left = x + "px";
		dc.style.visibility = "visible";
	},
	
	displayStoreFontCaption: function(obj, caption) {
		if (PLZ.expandingInterval) {
			return false;
		}
		dc = document.getElementById("image-caption");
		dc.innerHTML = caption;
		dc.style.backgroundColor = "#ffffff";
		
		x = ccmFindX(obj);
		y = ccmFindY(obj);
		x = x + 0;
		y = y + 0;
		
		if (document.all) {
			w = obj.width;
			y = y + obj.height; // i don't know why
			//y = y + obj.height;
		} else {
			w = obj.width - 5; // allowing borders & padding
			y = y + obj.height;
			//dc.style.paddingTop = 0;
			//y = y + obj.height;
		}
		w = w + 2;
		dc.style.width = w + "px";		
		dc.style.top = y + "px";
		dc.style.left = x + "px";
		dc.style.visibility = "visible";
	},
	
	
	displayActiveFontCaption: function(caption) {
		if (PLZ.expandingInterval) {
			return false;
		}
		var obj;
		divs = document.getElementsByTagName("IMG");
		for (i = 0; i < divs.length; i++) {
			if (divs[i].className == "active-font-signifier") {
				obj = divs[i];
				break;
			}
		}
		
		if (obj) {
			dc = document.getElementById("image-caption-font");
			dc.innerHTML = caption;
			dc.style.backgroundColor = "#ffffff";
			
			x = ccmFindX(obj);
			y = ccmFindY(obj);
			x = x + 0;
			y = y + 0;
			
			if (document.all) {
				w = obj.width;
				x = x + 1;
				y = y + obj.height; // i don't know why
				//y = y + obj.height;
			} else {
				w = obj.width - 5; // allowing borders & padding
				y = y + obj.height;
				//dc.style.paddingTop = 0;
				//y = y + obj.height;
			}
			w = w + 2;
			dc.style.width = w + "px";		
			dc.style.top = y + "px";
			dc.style.left = x + "px";
			dc.style.visibility = "visible";
		}
	},
	
	activateAllFonts: function() {
		objs = document.getElementsByTagName("IMG");
		for (i = 0; i < objs.length; i++) {
			if (objs[i].className == "font-signifier") {
				obj = objs[i];
								
				dc = document.createElement("DIV");
				dc.className = "image-caption-font";
				dc.innerHTML = obj.alt;
				dc.style.backgroundColor = "#ffffff";
				
				x = ccmFindX(obj);
				y = ccmFindY(obj);
				x = x + 0;
				y = y + 0;
				
				if (document.all) {
					w = obj.width;
					x = x + 1;
					y = y + obj.height; // i don't know why
					//y = y + obj.height;
				} else {
					w = obj.width - 5; // allowing borders & padding
					y = y + obj.height;
					y = y + 1;
					//dc.style.paddingTop = 0;
					//y = y + obj.height;
				}
				w = w + 2;
				y = y + 3;
				dc.style.width = w + "px";		
				dc.style.top = y + "px";
				dc.style.left = x + "px";
				document.body.appendChild(dc);
				dc.style.visibility = "visible";
			}
		}
	},
	
	displayStoreCaption: function(obj, caption) {
		if (PLZ.expandingInterval) {
			return false;
		}
		dc = document.getElementById("image-caption");
		dc.innerHTML = caption;
		dc.style.backgroundColor = "#ffffff";
		
		x = ccmFindX(obj);
		y = ccmFindY(obj);
		x = x + 0;
		y = y + 0;
		
		if (document.all) {
			w = obj.width;
			y = y + obj.height - 16; // i don't know why
			//y = y + obj.height;
		} else {
			w = obj.width - 5; // allowing borders & padding
			y = y + obj.height - 16;
			
			//y = y + obj.height;
		}
		
		dc.style.width = w + "px";		
		dc.style.top = y + "px";
		dc.style.left = x + "px";
		dc.style.visibility = "visible";
	},
	
	displayCaption: function(obj, caption) {
		if (PLZ.expandingInterval) {
			return false;
		}
		dc = document.getElementById("image-caption");
		dc.innerHTML = caption;
		dc.style.backgroundColor = "#ffffff";
		
		x = ccmFindX(obj);
		y = ccmFindY(obj);
		x = x + 0;
		y = y + 0;
		
		if (document.all) {
			w = obj.width;
			x = x + 1;
			y = y + obj.height - 16; // i don't know why
			//y = y + obj.height;
		} else {
			w = obj.width - 5; // allowing borders & padding
			y = y + obj.height - 16;
			
			//y = y + obj.height;
		}
		
		dc.style.width = w + "px";		
		dc.style.top = y + "px";
		dc.style.left = x + "px";
		dc.style.visibility = "visible";
	},
	
	clearCaption: function(linkObj) {
		dc = document.getElementById("image-caption");
		dc.style.visibility = "hidden";
	},
	
	swapArrow: function(old_id, new_id) {
		var image_id = '';
		var img_src = '';
		
		if (old_id != new_id) {
		
			if (old_id) {
				image_id = eval(old_id + "_collapser");
				img_src = image_id.src;
				//alert(image_id.src);
				img_src = img_src.replace(PLZ.selectedImageName, PLZ.regularImageName);			
				image_id.src = img_src;
				//alert(image_id.src);

			}
			if (new_id) {
				image_id = eval(new_id + "_collapser");		
				img_src = image_id.src;		
				//alert(image_id.src);

				img_src = img_src.replace(PLZ.regularImageName, PLZ.selectedImageName);			
				image_id.src = img_src;
			}
		
		}
	
	},
	
	swapOnClick: function(old_id, new_id) {
			var div_id = '';
			
			if (old_id) {
				div_id = eval(old_id + "_rollover");
				div_id.onClick = "PLZ.expandCategory('"+old_id+"')";
				//div_id.style.cursor = 'pointer';
			}
			//alert('Checking ' + new_id);
			div_id = eval(new_id + "_rollover");

			div_id.onClick = '';

			//alert('div onClick is: ' + div_id.onClick);
			
			//div_id.onClick = "PLZ.collapseCategory('"+new_id+"')";
			
			//div_id.style.cursor = 'default';

			//alert('div onClick is: ' + div_id.onClick + " and id is " + div_id.id);
		
	},
	
	collapseCategory: function() {
	
		if (PLZ.expandedCategory) {
			exObj = document.getElementById(PLZ.expandedCategory);
			collapsedHeight = (document.all) ? PLZ.storeCategoryCollapsedHeight + 18 : PLZ.storeCategoryCollapsedHeight;
			
			exObj.style.height = collapsedHeight + "px";
			
			
			exObj.className = "store-category-collapsed";
	
			//var div_id = eval(PLZ.expandedCategory + "_rollover");
			//div_id.onClick = "PLZ.expandedCategory('"+old_id+"')";
			//div_id.style.cursor = 'pointer';
			
			
				
			PLZ.swapArrow(PLZ.expandedCategory, null);

			PLZ.expandedCategory = null;
				
		}	
		
		return;
	
	},
	
	collapseNav: function(id) {
		imgobj = document.getElementById("_im" + id);
		obj = document.getElementById("subtree" + id);
		thelink = document.getElementById("_l" + id);
		obj.style.display = "none";
		imgobj.src = "/images/collapser_small_closed.gif";
		thelink.onclick = function() {
			PLZ.showNav(id);
		}
	},
	
	showNav: function(id) {
		imgobj = document.getElementById("_im" + id);
		obj = document.getElementById("subtree" + id);
		thelink = document.getElementById("_l" + id);
		obj.style.display = "block";
		imgobj.src = "/images/collapser_small_opened.gif";
		thelink.onclick = function() {
			PLZ.collapseNav(id);
		}
	},
	
	toggleNews: function(linkObj, cID) {
		dv = document.getElementById("bscon" + cID);
		linkObj.innerHTML = (dv.style.display == "none") ? "&lt;&lt; Less" : "More &gt;&gt;";
		dv.style.display = (dv.style.display == "none") ? "block" : "none";
	}
	
	
}
