var hyperModule = new Array();
// dojo.addOnLoad( writeHyperModule );

var layoutTypeWidth = new Array();
layoutTypeWidth[1] = '558px';
layoutTypeWidth[2] = '279px';
layoutTypeWidth[3] = '186px';

//visitor mode hypermodule override
var visitorHyperMod = new _hmData('/images/upsell/visitor_ver2.png','visitor','landing','3');

function writeHyperModule() {
	if(hyperModule.length > 0) {
		for(i = 0; i < hyperModule.length; i++) {
			if(i == 2) {
				// override if we're in a triple layout 
				// and we're on the web home page in visitor mode
				if(dojo.io.cookie.get('SL') == 'VIS' && (!isClient()) && SCqueryObj.genre_id < 1) {
					hyperModule[i] = visitorHyperMod;
				}
			}
			
			var newmod = document.createElement('a');
			var divIdName = 'hyperModule'+ i;
			newmod.setAttribute('id',divIdName);
			newmod.style.width = layoutTypeWidth[hyperModule[i].layoutType];
			var appVersionSplit = navigator.appVersion.split('MSIE');
			if((navigator.appName.indexOf('Microsoft') > -1) && (parseFloat(appVersionSplit[1]) <= 6)) {
				newmod.style.filter =  "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',src='" + hyperModule[i].imgURL + "',sizingMethod='scale')";
			}
			else {
				newmod.style.backgroundImage = "url(" + hyperModule[i].imgURL + ")";
			}
			var HMlink = resolveHMurl(hyperModule[i].linkType,hyperModule[i].linkID);
			if(hyperModule[i].linkType == 'url') {
				if(!isClient()) {
					newmod.setAttribute('href','javascript:' + HMlink);
					newmod.setAttribute('onclick',HMlink);
				}
				else {
					newmod.setAttribute('href','javascript:' + HMlink);
				}
			}
			else {
				newmod.setAttribute('href',HMlink);
			}
			document.getElementById("hyperModule").appendChild(newmod);
		}

		fixLinks(dojo.byId("hyperModule"));

		for( j = 0; j < hyperModule.length; j++) {
			var scDivIdName = 'hyperModule' + j;
			dojo.byId(scDivIdName).setAttribute('onclick','logSCHMClick(\'' + j + '\');' + dojo.byId(scDivIdName).getAttribute('onclick'));
			var currHref = dojo.byId(scDivIdName).getAttribute('href');
			dojo.byId(scDivIdName).setAttribute('href','javascript: logSCHMClick(\'' + j + '\');' + (currHref.indexOf('javascript:') > -1 ? currHref.substr(currHref.indexOf('javascript:') + 11) : ' clientGo(\'' + (currHref.indexOf("opcode.napster.com") > -1 ? currHref.substr(currHref.indexOf('http://opcode.napster.com/?') + 27 ) : currHref) + '\')'));
		}
		document.getElementById("hyperModule").style.display = "block";
		document.getElementById("content_inner_wrap").style.width = "100%";
		document.getElementById("hyperModule").style.zoom = "1";
		document.getElementById("hyperModule").style.marginLeft = "auto";
		// fixMainContentArea();
	}
}

function _hmData(imgURL,linkType,linkID,layoutType) {
	this.imgURL = imgURL;
	this.linkType = linkType;
	this.linkID = linkID;
	this.layoutType = layoutType;
	return this;
}

function resolveHMurl(linkType,linkID) {
	var linkURL = '';
	if(linkID == 'landing') {
		linkType += linkID;
	}
	eval(HMURLs[linkType]);
	return linkURL;
}

function logSCHMClick(id) {
	var HMEvtStr = 's.eVar8="' + SCqueryObj.genre_id + '_' + id + '_' + hyperModule[id].layoutType + '";';
	HMEvtStr += 's.eVar9="' + hyperModule[id].linkType + '-' + hyperModule[id].linkID + '";';
	var now = new Date();
	HMEvtStr += 's.eVar10="' + now + '";';
	HMEvtStr += 's.eVar3=s.PageName';
	$SCEG( 'HypermoduleClicks',HMEvtStr);
	//return false;
}

var HMURLs = new Array();
HMURLs['artist'] = 'linkURL = "/ns/view/artist/index.html?artist_id=" + linkID';
HMURLs['album'] = 'linkURL = "/cgi-bin/searchXML?type_id=albumtracks&result_type=track&select_by=album&select_value=" + linkID + "&format=json"';
HMURLs['playlistlanding'] = 'linkURL = "/ns/playlists/index.html"';
HMURLs['playlist'] = 'linkURL = "/cgi-bin/playlistXML?type_id=playlist&result_type=track&select_by=playlist&select_value=MIX_" + linkID + "&format=json"';
HMURLs['radiolanding'] = 'linkURL = "/cgi-bin/radioXML?type_id=stations&result_type=radio&select_by=all&select_value=all&format=json"';
HMURLs['videoslanding'] = 'linkURL = "/ns/videos/index.html"';
HMURLs['mkt'] = 'linkURL = linkID';
HMURLs['billboard'] = 'linkURL = "/cgi-bin/searchXML?type_id=billboard&result_type=track&select_by=chart&select_value=" + linkID + "&format=json"';
HMURLs['url'] = 'linkURL = "genericPop(\'" + linkID + "\',\'800\',\'600\',\'1\')"';
HMURLs['specialofferlanding'] = 'linkURL = "/devices/special_offers.html"'; 
HMURLs['visitorlanding'] = 'linkURL = "/marketing/visitor.html"'; 

function clientGo(op) {
	top.location.href = op.indexOf('op=') > -1 ? "http://opcode.napster.com/?" + op : op;
}
