var N47 = (navigator.appName.indexOf('Netscape') != -1 && navigator.appVersion.indexOf('4.7') != -1);

function findObj(n, d){
	var p,i,x;  if(!d) d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}


function setLayerContent(objLayer,strContent){
	if(N47){
		objLayer.document.open();
		objLayer.document.write(strContent);
		objLayer.document.close();
	}else{
		objLayer.innerHTML = strContent;
	}
}

function randomizeValue(intValue){
    return Math.floor(Math.random() * intValue);
}

function getQueryString()
{
	var strQueryString;
	queryString = new Array();
	strQueryString = document.location.href;
	if (strQueryString.indexOf("?") == -1)
	{
		strQueryString = null;
	}else{
		strQueryString = strQueryString.substring((strQueryString.indexOf("?")+1),strQueryString.length);
	}

	var arrParms = new Array();
	if (strQueryString != null)
	{
		if (strQueryString.indexOf("&") != -1)
		{
			arrParms = strQueryString.split("&");
		}else{
			arrParms = strQueryString.split("%26");
		}
		for(intX=0;intX<arrParms.length;intX++)
		{
			queryString[arrParms[intX].substring(0,arrParms[intX].indexOf("="))] = arrParms[intX].substring(arrParms[intX].indexOf("=")+1,arrParms[intX].length);
		}
	}
}

function loadPageDivContent(){
	getQueryString();
	if(queryString['strArray'] != null && queryString['intMovieId'] != null && queryString['intSpotId'] == null){
		if(queryString['intSubItemId'] != null){
			document.write(changeVideo(queryString['strArray'],parseInt(queryString['intMovieId']),parseInt(queryString['intSubItemId'])));
		}else{
			document.write(changeVideo(queryString['strArray'],parseInt(queryString['intMovieId'])));		
		}
	}else if(queryString['strArray'] != null && queryString['intSpotId'] != null){
		if(queryString['intSpotSubItemId'] != null){
			document.write(changeVideo(queryString['strArray'],parseInt(queryString['intMovieId']),parseInt(queryString['intSubItemId']),parseInt(queryString['intSpotId']),parseInt(queryString['intSpotSubItemId'])));
		}else{
			document.write(changeVideo(queryString['strArray'],parseInt(queryString['intMovieId']),parseInt(queryString['intSubItemId']),parseInt(queryString['intSpotId'])));
		}
	}else{
		document.writeln('<div id="lbl_main"><img src="images/mapa.gif" width="229" height="213"></div>');
	}
}

function changeVideo(strArrayName,intMovieId,intSubitem,intSpotId,intSpotSubitem){
    intSubitem=(typeof(intSubitem)=="undefined"?0:intSubitem);
	var strContent;
	
	//if(typeof(arrMovies[strArrayName]['subitem_name'][intMovieId]) == "undefined"){
			strContent='<div id="lbl_main">';
				strContent+='<table width="218" border="0" cellpadding="0" cellspacing="0">';
					strContent+='<tr>';
						strContent+='<td valign="top" width="218" bgcolor="#E6E6E6" colspan="3"><img src="images/hsbc_img_clear.gif" width="218" height="1" alt="" border="0"></td>';
					strContent+='</tr>';
					strContent+='<tr>';
						strContent+='<td valign="top" width="1" bgcolor="#E6E6E6"><img src="images/hsbc_img_clear.gif" width="1" height="193" alt="" border="0"></td>';
						strContent+='<td valign="top" width="216">';
							strContent+='<table width="216" border="0" cellpadding="0" cellspacing="0">';
								strContent+='<tr>';
									strContent+='<td valign="middle" align="center" width="216" height="177">';
									if(intSpotId == null){
										strContent+='<object id="mediaplayer1" width="' + arrMovies[strArrayName]['width'][intMovieId] + '" height="' + arrMovies[strArrayName]['height'][intMovieId] + '" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">';
											strContent+='<param name="ShowStatusBar" value="false">';
											strContent+='<param name="Volume" value="false">';
											strContent+='<param name="ShowDisplay" value="false">';
											strContent+='<param name="ShowControls" value="0">';
											strContent+='<param name="ShowAudioControls" value="false">';
											strContent+='<param name="ShowPositionControls" value="false">';
											strContent+='<param name="AutoStart" value="true">';
											strContent+='<param name="FileName" value="' + arrMovies[strArrayName]['source'][intMovieId] + '">';
											strContent+='<embed src="' + arrMovies[strArrayName]['source'][intMovieId] + '" width="' + arrMovies[strArrayName]['width'][intMovieId] + '" height="' + arrMovies[strArrayName]['height'][intMovieId] + '" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" name="mediaplayer1" showcontrols="0" showdisplay="0" showstatusbar="0" autostart="1" displaysize="0" showvolumecontrols="0"></embed>';
										strContent+='</object>';
									}else{
										var arrSpots = arrMovies[strArrayName]['source_spot'][intSpotId].split(',');
										var intCurrentSpot = randomizeValue(arrSpots.length);
										strContent+='<object id="mediaplayer1" width="182" height="19" border="0" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95F" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby=""	type="application/x-oleobject">';
											strContent+='<param name="FileName" value="' + arrSpots[intCurrentSpot] + '">';
										    strContent+='<param name="TransparentAtStart" value="True">';
											strContent+='<param name="ShowControls" value="0">';
										    strContent+='<param name="ShowDisplay" value="0">';
										    strContent+='<param name="ShowStatusBar" value="1">';
										    strContent+='<param name="AutoSize" value="0">';
										    strContent+='<embed type="application/x-mplayer2" pluginspage="http://download.microsoft.com/download/winmediaplayer/nsplugin/6.4/WIN98/EN-US/wmpplugin.exe" src="' + arrSpots[intCurrentSpot] + '" name="mediaplayer1" showcontrols="0" showstatusbar="1" displaysize="0" width="182" height="19"></embed>';
										strContent+='</object>';
									}
									strContent+='</td>';
								strContent+='</tr>';
								strContent+='<tr>';
									strContent+='<td valign="top" width="216" bgcolor="#E6E6E6"><img src="images/hsbc_img_clear.gif" width="216" height="1" alt="" border="0"></td>';
								strContent+='</tr>';
								strContent+='<tr>';
									strContent+='<td valign="top" width="216">';
										strContent+='<table width="216" border="0" cellpadding="0" cellspacing="0">';
											strContent+='<tr>';
												strContent+='<td valign="top" width="15"><a href="javascript:void(findObj(\'mediaplayer1\', false).play());"><img src="images/hsbc_btn_play.gif" width="15" height="15" alt="" border="0"></a></td>';
												strContent+='<td valign="top" width="5"><img src="images/hsbc_img_clear.gif" width="5" height="1" alt="" border="0"></td>';
												strContent+='<td valign="top" width="15"><a href="javascript:void(findObj(\'mediaplayer1\', false).stop());"><img src="images/hsbc_btn_stop.gif" width="15" height="15" alt="" border="0"></a></td>';
												strContent+='<td valign="top" width="137"><img src="images/hsbc_img_clear.gif" width="137" height="15" alt="" border="0"></td>';
												/*if(intSpotId == null){
													if(arrMovies[strArrayName]['source_spot'][intMovieId] != null){
														strContent+='<td valign="top" width="44"><a href="index.htm?strArray='+ strArrayName +'&intMovieId='+ intMovieId +'&intSpotId='+ intMovieId +'"><img src="images/hsbc_btn_radio.gif" width="44" height="15" alt="RÁDIO" border="0"></a></td>';
													}else{
														strContent+='<td valign="top" width="44"><img src="images/hsbc_img_clear.gif" width="44" height="15" alt="" border="0"></td>';
													}
												}else{
													strContent+='<td valign="top" width="44"><a href="index.htm?strArray='+ strArrayName +'&intMovieId='+ intMovieId +'"><img src="images/hsbc_btn_video.gif" width="44" height="15" alt="VÍDEO" border="0"></a></td>';
												}*/
											strContent+='</tr>';
										strContent+='</table>';
									strContent+='</td>';
								strContent+='</tr>';
							strContent+='</table>';
						strContent+='</td>';
						strContent+='<td valign="top" width="1" bgcolor="#E6E6E6"><img src="images/hsbc_img_clear.gif" width="1" height="193" alt="" border="0"></td>';
					strContent+='</tr>';
					strContent+='<tr>';
						strContent+='<td valign="top" width="218" bgcolor="#E6E6E6" colspan="3"><img src="images/hsbc_img_clear.gif" width="218" height="1" alt="" border="0"></td>';
					strContent+='</tr>';
				strContent+='</table>';
			strContent+='</div>';
	
	return strContent;
}
