/*
 * CQ Corner specific static class
 */
if (typeof(w2) == 'undefined') { alert('requires Web2.0 library'); }
if (typeof(window.cq) == 'undefined') { var cq = null; }
cq = {
	links : false,
	popup : {
		show : function(uri) {
			// get the content for the specified URI
			var obj = document.getElementById('w2linkbox');
			if (obj == null) return;
			obj.innerHTML = cq.getContent(uri);
			w2.popup.delay.show('w2linkup', 28, -0.39, 500);	
		},

		hide : function() {
			w2.popup.hide('w2linkup');
		}
	},

	extract : function() {
		w2.links = w2.xml.doc.documentElement.getElementsByTagName('link');
	},

	getContent : function(uri) {
		var icon = false;
		var title = false;
		var content = false;
		var url = false;

		// find the link with the uri specified
		for (var i = 0; i < w2.links.length; i++)
		{
			url = w2.links[i].getAttribute('url');
			if (url == null) continue;
			if (uri.indexOf(url) > -1)
			{
				// get the icon, title and content.
				icon = w2.links[i].getAttribute('icon');
				title = w2.links[i].getAttribute('title');
				content = w2.links[i].childNodes[0].nodeValue;
				break;
			}
		}

		if (icon == null || icon == false) icon = '/united-states/compaq/cqcorner/images/cqc_promo_00_64.jpg';
		if (title == null || title == false) title = 'Welcome to CQ Corner';
		if (content == null || content == false) content = '';

		return '<table cellspacing="6" class="w2linkup"><tr><td class="w2linkup"><img src="' + icon + '" height="64" width="64" alt="" /></td><td class="w2linkup">' + decodeURI(title) + '</td></tr><tr><td colspan="2">' + decodeURI(content) + '</td></tr></table>';
	}
}

w2.xml.load("/united-states/compaq/cqcorner/xml/cqcorner.xml", cq.extract);
