// JavaScript Document

// Globals

// Default Major version of Flash required
var requiredMajorVersion = 10;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Revision of Flash required
var requiredRevision = 0;
// Base de URL para los Clips
//var clipBaseUrlRaw = 'http://localhost/tamakumWebTV/index.php?playlistxml=scifi.xml&idvideo=';
var clipBaseUrlRaw = '';
var clipBaseUrl = encodeURIComponent(clipBaseUrlRaw);
// Base de URL para el reproductor
//var playerBaseUrl = 'http://www.tamakum.com/webtv/tmkPlayer.swf?playlistxml=http://www.tamakum.com/webtv/default.xml&amp;idvideo=';
var playerBaseUrl = '';
var playerWidth = 400;
var playerHeight = 225;

/*****************************************************************/
/* toggleTab(baseName,number,total,classNormal,classActive) ver 1.0 - 28/05/09 */ 
/*****************************************************************/
function toggleTab(baseName,number,total,classNormal,classActive){
for (i=1;i<=total;i++)
	{
	document.getElementById(baseName+i).className = classNormal;
	};
document.getElementById(baseName+number).className = classActive;
};

/*****************************************************************/
/* switchDiv(divBaseName,divNumber,divTotal) ver 1.0 - 28/05/09 */ 
/*****************************************************************/
function switchDiv(divBaseName,divNumber,divTotal){
for (i=1;i<=divTotal;i++)
	{
	document.getElementById(divBaseName+i).style.display='none';
	} ;
document.getElementById(divBaseName+divNumber).style.display='block';
};

/*****************************************************************/
/* cclass(obj,id,newClass) ver 1.0 - 28/05/09 */ 
/*****************************************************************/
function cclass(obj,id,newClass) {
	if (obj==null) 
	{
	document.getElementById(id).className=newClass;
	}
	else { 
		obj.className=newClass;
		};
	};

/*****************************************************************/
/* changeDescription(idMain,idChild,content) ver 1.0 - 28/05/09 */ 
/*****************************************************************/
function changeDescription(idMain,idChild,content) {
//document.getElementById(idMain).removeChild(document.getElementById(idChild));
//var newdiv = document.createElement('div');
//var divIdName = idChild;
//newdiv.setAttribute('id',divIdName);
//newdiv.innerHTML = content;
//document.getElementById(idMain).appendChild(newdiv);
//alert(document.getElementById(idMain).style.height);
document.getElementById(idChild).innerHTML = content;
if (!(document.getElementById(idMain).style.height=='0px')){
document.getElementById(idMain).style.height=document.getElementById(idChild).offsetHeight+"px";};
//alert(document.getElementById(idMain).style.height);
};

/*****************************************************************/
/* changeRating(valoracion,haSidoValorado) ver 1.0 - 20/08/09 */ 
/*****************************************************************/
function changeRating(valoracion,haSidoValorado){
var classTemp = '';
var valoracionInt = parseInt(valoracion);
//var rateCode1  = '<div id="rateMe" style="display:inline; margin:0px; padding:0px;"><div style="position:absolute; width:80px; margin:0px; margin-left:2px; padding:0px;">';
var rateCode1  = '<div id="rateMe" style="margin:0px; padding:0px;">';
//var rateCode2a = '<a class="';
var rateCode2a = '<img src="plantillas/images/spcd.gif" width="12" height="13" class="';
var rateCode2b = '" onclick="rateIt(this)" id="_';
var rateCode2c = '" alt="valoraci&oacute;n actual: ';
var rateCode2d = '" title="valoraci&oacute;n actual: ';
var rateCode2e = '" onmouseover="ratingOver(this)" onmouseout="off(this,';
//var rateCode2f = ')"></a>';
var rateCode2f = ')" />';
//var rateCode3  = '</div></div>';
var rateCode3  = '</div>';

if(valoracion>0.5) {
	classTemp='starOn';
	var rateHTMLCode1 = rateCode2a+classTemp+rateCode2b+1+rateCode2c+valoracion+rateCode2d+valoracion+rateCode2e+valoracionInt+rateCode2f;
	} else {
	classTemp='';
	var rateHTMLCode1 = rateCode2a+classTemp+rateCode2b+1+rateCode2c+valoracion+rateCode2d+valoracion+rateCode2e+1+rateCode2f;
	};

if(valoracion>1.5){classTemp='starOn'} else {classTemp=''};
var rateHTMLCode2 = rateCode2a+classTemp+rateCode2b+2+rateCode2c+valoracion+rateCode2d+valoracion+rateCode2e+valoracionInt+rateCode2f;
if(valoracion>2.5){classTemp='starOn'} else {classTemp=''};
var rateHTMLCode3 = rateCode2a+classTemp+rateCode2b+3+rateCode2c+valoracion+rateCode2d+valoracion+rateCode2e+valoracionInt+rateCode2f;
if(valoracion>3.5){classTemp='starOn'} else {classTemp=''};
var rateHTMLCode4 = rateCode2a+classTemp+rateCode2b+4+rateCode2c+valoracion+rateCode2d+valoracion+rateCode2e+valoracionInt+rateCode2f;
if(valoracion>4.5){classTemp='starOn'} else {classTemp=''};
var rateHTMLCode5 = rateCode2a+classTemp+rateCode2b+5+rateCode2c+valoracion+rateCode2d+valoracion+rateCode2e+valoracionInt+rateCode2f;
//alert(rateCode1+rateHTMLCode1+rateHTMLCode2+rateHTMLCode3+rateHTMLCode4+rateHTMLCode5+rateCode3);
//document.getElementById('dynamicStat1').innerHTML = '';
document.getElementById('dynamicStat1').innerHTML = rateCode1+rateHTMLCode1+rateHTMLCode2+rateHTMLCode3+rateHTMLCode4+rateHTMLCode5+rateCode3;
if (haSidoValorado == null) { haSidoValorado = false};
if ((haSidoValorado)) {document.formRating.ratingField.value = 0} else {document.formRating.ratingField.value = parseInt(valoracion)};
	};

/*****************************************************************/
/* changeSharing(idMain,idClip,title) ver 1.0 - 28/05/09 */ 
/*****************************************************************/

function changeSharing(idMain,idClip,title) {
if (idClip==null) {idVideo=0};
var sharePreTitle = encodeURIComponent('Vídeo: ');
var shareTitle = encodeURIComponent(title);
//alert(document.title);
//var shareButton1 = '<img class="socialIcon" src="plantillas/social/facebook.gif" alt="" /> ';
var shareButton1 = '<a rel="nofollow" href="http://www.facebook.com/sharer.php?u='+clipBaseUrl+idClip+'&amp;t='+sharePreTitle+shareTitle+'" target="_blank" ><img class="iconSocialFacebook" src="plantillas/images/spcd.gif" alt="Compartir en Facebook" /><\/a> ';
//var shareButton2 = '<img class="socialIcon" src="plantillas/social/myspace.gif" alt="" /> ';
var shareButton2 = '<a rel="nofollow" href="http://www.myspace.com/Modules/PostTo/Pages/?u='+clipBaseUrl+idClip+'&amp;t='+sharePreTitle+shareTitle+'" target="_blank" ><img class="iconSocialMyspace" src="plantillas/images/spcd.gif" alt="Compartir en MySpace" /><\/a> ';
//var shareButton3 = '<img class="socialIcon" src="plantillas/social/digg.gif" alt="" /> ';
var shareButton3 = '<a rel="nofollow" href="http://digg.com/submit?phase=2&amp;url='+clipBaseUrl+idClip+'&amp;title='+sharePreTitle+shareTitle+'" target="_blank" ><img class="iconSocialDigg" src="plantillas/images/spcd.gif" alt="Compartir en Digg" /><\/a> ';
//var shareButton4 = '<img class="socialIcon" src="plantillas/social/meneame.gif" alt="" /> ';
var shareButton4 = '<a rel="nofollow" href="http://meneame.net/login.php?return=/submit.php?url='+clipBaseUrl+idClip+'&amp;title='+sharePreTitle+shareTitle+'" target="_blank" ><img class="iconSocialMeneame" src="plantillas/images/spcd.gif" alt="Menea este v&iacute;deo" /><\/a> ';
//var shareButton5 = '<img class="socialIcon" src="plantillas/social/yahoo.gif" alt="" /> ';
var shareButton5 = '<a rel="nofollow" href="http://bookmarks.yahoo.com/toolbar/savebm?opener=tb&amp;u='+clipBaseUrl+idClip+'&amp;t='+sharePreTitle+shareTitle+'&amp;d=&amp;ei=UTF" target="_blank" ><img class="iconSocialYahoo" src="plantillas/images/spcd.gif" alt="Guardar en Yahoo" /><\/a> ';
//var shareButton6 = '<img class="socialIcon" src="plantillas/social/twitter.gif" alt="" /> ';
var shareButton6 = '<a rel="nofollow" href="http://twitter.com/home?status='+sharePreTitle+shareTitle+' '+clipBaseUrl+idClip+'" target="_blank" ><img class="iconSocialTwitter" src="plantillas/images/spcd.gif" alt="Compartir en Twitter" /><\/a> ';
//var shareButton7 = '<img class="socialIcon" src="plantillas/social/live.gif" alt="" /> ';
var shareButton7 = '<a rel="nofollow" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;mkt=es&amp;url='+clipBaseUrl+idClip+'&amp;title='+sharePreTitle+shareTitle+'" target="_blank" ><img class="iconSocialLive" src="plantillas/images/spcd.gif" alt="Compartir en Live" /><\/a> ';
//var shareButton8 = '<img class="socialIcon" src="plantillas/social/google.gif" alt="" /> ';
var shareButton8 = '<a rel="nofollow" href="http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk='+clipBaseUrl+idClip+'&amp;title='+sharePreTitle+shareTitle+'" target="_blank" ><img class="iconSocialGoogle" src="plantillas/images/spcd.gif" alt="Compartir en Google" /><\/a> ';
document.getElementById(idMain).innerHTML = shareButton1+shareButton2+shareButton3+shareButton4+shareButton5+shareButton6+shareButton7+shareButton8;
};


/*****************************************************************/
/* changeEmbed(idMain) ver 1.0 - 28/05/09 */ 
/*****************************************************************/

function changeEmbed(textField,idClip) {
// NOTA: Depende de las variables globales: playerWidth, playerHeight, playerBaseUrl
if (idClip==null) {idClip=0};
//var txt1 = '<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="TMKVideoPloayer" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" border="0" width="320" height=180" >\n';
var embedHTMLCode1 = '<object width="'+playerWidth+'" height="'+playerHeight+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" style="border:none" >';
var embedHTMLCode2 = '<param name="movie" value="'+playerBaseUrl+idClip+'"></param>';
var embedHTMLCode3 = '<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="SCALE" value="ExactFit"></param><param name="quality" value="High"></param><param name="loop" value="false"></param><param name="swliveconnect" value="true"></param><param name="wmode" value="opaque"></param>';
var embedHTMLCode4 = '<embed width="'+playerWidth+'" height="'+playerHeight+'" src="'+playerBaseUrl+idClip+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowscriptaccess="always" quality="High" loop="false" allowfullscreen="true" scale="exactFit" swliveconnect="true"></embed>';
var embedHTMLCode5 = '</object>';
textField.value = embedHTMLCode1+embedHTMLCode2+embedHTMLCode3+embedHTMLCode4+embedHTMLCode5;
};

/*****************************************************************/
/* changeVideoData(titulo,valoracion,visto,fecha,descripcion,link,embed,haSidoValorado) ver 1.1 - 20/08/09 */ 
/*****************************************************************/

//function changeVideoData(titulo,valoracion,reproducciones,fecha,descripcion,link,embed,idClip,haSidoValorado,urlClip,urlPlayer){
function changeVideoData(titulo,valoracion,reproducciones,fecha,descripcion,idClip,haSidoValorado,urlClip,urlPlayer){
if (idClip==null) {idClip="indefinido"};
if (urlClip==null) {urlClip="*url clip indefinido* id="};
if (urlPlayer==null) {urlPlayer="*url player indefinido* id="};
clipBaseUrlRaw = urlClip;
clipBaseUrl = encodeURIComponent(clipBaseUrlRaw);
playerBaseUrl = urlPlayer;
// NOTA: Depende de las variables globales: clipBaseUrl
//document.title = titulo+' - '+originalDocumentTitle;
document.title = titulo;
document.getElementById('dynamicTitle').innerHTML = titulo;
/*
var rateFull = '<img src="images/rate-full.gif" align="bottom" alt="'+valoracion+'" title="'+valoracion+'"/>'
var rateMid  = '<img src="images/rate-mid.gif" align="bottom" alt="'+valoracion+'" title="'+valoracion+'"/>'
var rateNone  = '<img src="images/rate-none.gif" align="bottom" alt="'+valoracion+'" title="'+valoracion+'"/>'
if (valoracion>=0 && valoracion<0.5) { document.getElementById('dynamicStat1').innerHTML = rateNone+rateNone+rateNone+rateNone+rateNone };
if (valoracion>=0.5 && valoracion<1) { document.getElementById('dynamicStat1').innerHTML = rateMid+rateNone+rateNone+rateNone+rateNone };
if (valoracion>=1 && valoracion<1.5) { document.getElementById('dynamicStat1').innerHTML = rateFull+rateNone+rateNone+rateNone+rateNone };
if (valoracion>=1.5 && valoracion<2) { document.getElementById('dynamicStat1').innerHTML = rateFull+rateMid+rateNone+rateNone+rateNone };
if (valoracion>=2 && valoracion<2.5) { document.getElementById('dynamicStat1').innerHTML = rateFull+rateFull+rateNone+rateNone+rateNone };
if (valoracion>=2.5 && valoracion<3) { document.getElementById('dynamicStat1').innerHTML = rateFull+rateFull+rateMid+rateNone+rateNone };
if (valoracion>=3 && valoracion<3.5) { document.getElementById('dynamicStat1').innerHTML = rateFull+rateFull+rateFull+rateNone+rateNone};
if (valoracion>=3.5 && valoracion<4) { document.getElementById('dynamicStat1').innerHTML = rateFull+rateFull+rateFull+rateMid+rateNone };
if (valoracion>=4 && valoracion<4.3) { document.getElementById('dynamicStat1').innerHTML = rateFull+rateFull+rateFull+rateFull+rateNone };
if (valoracion>=4.3 && valoracion<4.75) { document.getElementById('dynamicStat1').innerHTML = rateFull+rateFull+rateFull+rateFull+rateMid };
if (valoracion>=4.75) { document.getElementById('dynamicStat1').innerHTML = rateFull+rateFull+rateFull+rateFull+rateFull }
*/
changeRating(valoracion,haSidoValorado);
document.formRating.ratingIdClip.value = idClip;
//document.getElementById('dynamicStat1').innerHTML = valoracion;
document.getElementById('dynamicStat2').innerHTML = reproducciones;
document.getElementById('dynamicStat3').innerHTML = fecha;
changeDescription('videoDescriptionCont','dynamicDescription',descripcion);
document.videoShareForm.shareLink.value = clipBaseUrlRaw+idClip;
document.videoShareForm.shareTitle.value = titulo;
changeEmbed(document.videoShareForm.shareEmbed,idClip);
changeSharing('dynamicShare',idClip,titulo);
// parche
/*document.getElementById('relatedVideosThumb').style.top='1px';
document.getElementById('relatedVideosThumb').style.top='0px';*/
};

/*****************************************************************/
/* getUrlParams() ver 1.0 - 20/08/09 */
/*****************************************************************/

//Global
var urlParams = new Array();

function getUrlParams() {
var idx = document.URL.indexOf('?');
if (idx != -1) {
	var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
	for (var i=0; i<pairs.length; i++) {
		nameVal = pairs[i].split('=');
		urlParams[nameVal[0]] = nameVal[1];
   };
};
return urlParams;
};

/*****************************************************************/
/* inclVideo(url,w,h,id,wmode) ver 1.0 - 20/08/09 */
/*****************************************************************/

function inclVideo(url,w,h,id,wmode,idForAlternateContent,requiredFlash){
	if (!(requiredFlash == null)) requiredMajorVersion = requiredFlash;
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if(hasRightVersion) {  
	// if we've detected an acceptable version
	if (wmode == null) wmode= "transparent";
	document.write('<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="');
	document.write(id);	
	document.write('" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" border="0" width="');
	document.write(w);
	document.write('" height="');
	document.write(h);
	document.write('" >\n');
	document.write('<param name="movie" value="');
	document.write(url);
	document.write('">\n');
	document.write('<param name="SCALE" value="ExactFit">\n');
	document.write('<param name="quality" value="High">\n');
	document.write('<param name="loop" value="false">\n');
	document.write('<param name="swliveconnect" value="true">\n');
	document.write('<param name="allowScriptAccess" value="always">\n');
	document.write('<param name="allowFullScreen" value="true">\n');
	document.write('<param name="wmode" value="');
	document.write(wmode);
	document.write('">\n');
	document.write('<embed src="');
	document.write(url);
	document.write('" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="');
	document.write(id);	
	document.write('" width="');
	document.write(w);
	document.write('" height="');
	document.write(h);
	document.write('" quality="High" loop="false" allowFullScreen="true" allowScriptAccess="always" scale="exactFit" swliveconnect="true" wmode="');
	document.write(wmode);
	document.write('"></object>\n');
	}
	else {  
		// flash is too old or we can't detect the plugin
		var alternateContent = '<br /><br /><br />Para visualizar los v&iacute;deos necesitas el Flash Player 10 o superior, <a href="http://get.adobe.com/flashplayer" target="_blank">descárgalo aqu&iacute;</a><br /><br /><br /><br />';
		document.getElementById(idForAlternateContent).innerHTML=alternateContent;
		//document.writeln(alternateContent);  // insert non-flash content
	};
};
