/*
##################################################################
Javascript file for theHour to handle theWall launch
2008 - Written & Modified by Saurabh 
##################################################################
*/
 

var songID;
var albumID; 
var onairSongID;
var onairAlbumID;
var host; 
// Station Id 
var stationId;
var theWall=null;
var launchWindowURL = "";

/*
Function Name: widgetAction
Description: Function that takes three parameters actionId, infoType and info(optional) 
* currently disabled, see ad.js for proper version.
Parameter: actionId - Id of the action performed in the Flash widget
		   infoType - information asssociated with actionId
		   info - Optional parameter containing the artistName.
Return: Void.
*/ 
function widgetAction(actionId, infoType, info) {
 	setHostDomain();
	stationId = getStation();
	var actId = actionId.toUpperCase();
	var infoObj = {};
	if (infoType == "songData") {
		infoObj = decodeJSON(unescape(info));
	} else if (infoType == "songId") {
		infoObj.songId = info;
	} else if (infoType == "artistId") {
		infoObj.artistId = info;
	}
	adInfo = info;
	launchWindowURL = getWallLaunchUrl(actId, info, infoObj);
    if (launchWindowURL.length > 0) {
		theWall=launchTheWall(launchWindowURL,"_blank","width=1010,height=650,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,titlebar=no",theWall, infoObj);
	}
	// refresh theHour Ad
	//refreshAd(actionId, infoType, adInfo);
}

function getWallLaunchUrl(actId, info, infoObj) {
    initParams();
  	var url = "";
  	if (params.wallActive == "true") {
		switch (actId) {
			case "WELCOME":
			break;
			case "NPSONGUPDATED": // nothing to do unless in wall
			break;
			case "CLICKFORSONGSBYARTIST":
	//		case "DISPLAYLISTUPDATED":
			case "LOGSONGLISTENEDTO":
			case "CLICKLYRICS":  
			case "CLICKTITLE":  
			case "CLICKARTIST":
				adInfo = infoObj.songId;
				url = host+"index.php?stationId="+stationId+"&m2gSongData="+info; 
			break;
			case "CLICKHOUR":
				adInfo = infoObj.index;
				url = host+"index.php?stationId="+stationId+"&m2gSongData="+info; 
			break;
			case "SIMPLE":
			case "CLICKVERSIONS":
			case "CLICKSEARCH":
			case "CLICKPLAYLIST":
			case "CLICKSTATIONPLAYLIST":
			case "USERACTIVITY":
				url = host+"index.php?stationId="+stationId; 
			break;
			default:
				// TODO
		}
	}
	// only launch wall in sticky if specifically clicking on the wall button
	if ( (actId != "CLICKLYRICS") && (params.CartType == "iTunes")) url = ""; 
	return url;
}


/*
Function Name: refreshAd
Description: refresh theHour Ad
Parameters: actionId, infoType, info
Return: 
*/
function refreshAd(actionId, infoType, info) {
	clickEventHandler(actionId, infoType, info);
}

/*
Function Name: setHostDomain
Description: Returns the Host Domain name.
Parameters: None.
Return:String
*/
function setHostDomain() { 
	host = "/wallstations/"+stationId+"/";  
}

/*
Function Name: launchTheWall
Description: launches theWall but not opens new window if already launched
Parameters: winURL- url of theWall main page.
			winName- name of theWall window (pop up window).
			winFeatures- features of the pop up window like width, height and so on.
			winObj- name of the variable to uniquely identify the pop up window status.
Return: 
*/
function launchTheWall(winURL, winName, winFeatures, winObj, infoObj) {
  var theWin; // this will hold opened theWall window
  // check if theWall window already exists
  if (winObj != null) {
    // check if user closed theWall window.
    // if so, then reopen it. Otherwise make it the active window.
    if (!winObj.closed) {
	  // reload theWall window if already opened.
	  //winObj.loadWallContent(stationId, infoObj, 'bySongData'); 
      winObj.focus();
      return winObj;
    }
    // otherwise re-open the window
  } 
  // if not launched yet. launch theWall
  theWin = window.open(winURL, winName, winFeatures);
  //theWin.moveTo(0,0);
  return theWin;
}

//
function wallIndexBody(_useDefaultSize) {
	indexBody(_useDefaultSize);
}



