/** NRJ SIDEBAR FONCTIONS
** NRJ GROUP
** Tous droits réservés (c) Copyright 2008, NRJ GROUP
**
** @DISPLAY
** @ANTENNE
** @METEO
** @TOPVIDEO
** @VIDEOLIST
** @TOPPLAYLIST
** @SOCNET INIT
**/

//variables global
var url_base = window.location.protocol + "//" + window.location.host;
var myCurrentPage = 0;
var myCurrentPageTwitterCarrousel = 0;
/* global functions */
var displayBlock = function(hideId,displayId)
{
    var show = document.getElementById(displayId);
    var hide = document.getElementById(hideId);
    show.style.display = 'block';
    hide.style.display = 'none';
}


/* antenne */
var antennecallAJAX = function(tri)
{
        
	var sUrl = url_base+"/sidebar/antenneajax?tri="+tri;
	var transaction = Nrj_Library.Execute(sUrl, {}, antennecallback);
	
	return false;
}
var antennecallback = function (o)
{
	document.getElementById('antennecontent').innerHTML =  o.responseText;
} 

/* meteo */
var selectCity = function(args,hideId,displayId)
{
    content = args.split('|');
    zipCode = content[0];
    cityName = content[1];
    var xhr = getXhr()
    // On défini ce qu'on va faire quand on aura la réponse
    xhr.onreadystatechange = function(){
            // On ne fait quelque chose que si on a tout reçu et que le serveur est ok
            if(xhr.readyState == 4 && xhr.status == 200){
                    //alert(xhr.responseText);
                    document.getElementById('meteo').innerHTML = xhr.responseText;
            }
    }
    xhr.open("GET", url_base+"/sidebar/meteobloc?zip_code="+zipCode+"&city_name="+cityName,true);
    //xhr.send("zip_code="+zipCode+"&city_name="+cityName);
    xhr.send(null);
    var show = document.getElementById(displayId);
    var hide = document.getElementById(hideId);
    show.style.display = 'block';
    hide.style.display = 'none';
}

/* topvideo */
var TopvideoCallAjax = function(tri){
        
	var sUrl = url_base  + "/" +"sidebar/topvideo?tri="+tri;
	var callback =
	{
		success: function(o)
		{
			document.getElementById('topvideocontent').innerHTML =  o.responseText;
		},
		failure: function(o)
		{
			//alert("AJAX doesn't work");
		}
	}
	var transaction = Nrj_Library.Ajax(sUrl, '!topvideocontent');
	return false;
}


/* videolist */
var videolistSide = function (id, key, url){
	document.getElementById('remontee_video_image_' + key).src = document.getElementById('remontee_video_' + id + key).value;
	document.getElementById('item_vid_tab_' + id + key).className = 'tab select';
	videolistFlushOthers(id,key);
	document.getElementById('linkeds').href = url;
}

var videolistFlushOthers = function(id,key){
	for (i=1; i <= 3; i++){
		if(i!=id)
			document.getElementById('item_vid_tab_' + i + key).className = 'tab';
	}
}

/** ----------------------------------------- @SOCNET INIT ------------------------------------- **/
/** ------------------------------------------------------------------------------------------------- **/
var socnetPrint = function (id, prefixeContent, initContent)
{
	var socnetScript = document.createElement('script');
	socnetScript.type = 'text/javascript';
	
	if(initContent.indexOf('http') != -1)
	{
		socnetScript.src = initContent;
	}
	else
	{
		socnetScript.innerHTML = initContent;
	}
	document.getElementById('section').appendChild(socnetScript);
}


/* CAROUSEL TWITTER */
var TwitterCarrouselCallAjax = function(choice, currentPage, userAction, maxPages){
	var sUrl = '/sidebar/twitter?choice='+choice+'&currentPage='+currentPage;
	var transaction = Nrj_Library.Execute(sUrl, {}, TwitterCarrouselCallback);
	
	if (myCurrentPageTwitterCarrousel == maxPages){myCurrentPageTwitterCarrousel = 0;}
	else {myCurrentPageTwitterCarrousel = currentPage}
	
	return false;
}

var TwitterCarrouselCallback = function(o){
	document.getElementById('twittercarrouselcontent').innerHTML = o.responseText;
	myCurrentPageTwitterCarrousel ++;
}

var ajax_exec = function(divId){
	var m = document.getElementById(divId);
  	var allscript = m.getElementsByTagName('script');
    for(var i=0;i< allscript.length;i++){
   	 eval(allscript[i].text);
    }
}

var replier = function(){	
	if(document.getElementById('replietop20webradio').style.display != 'none'){
    	document.getElementById('replietop20webradio').style.display = 'none';
    	document.getElementById('replietop20webradioa').innerHTML = "D&eacute;plier";
	}else{
		document.getElementById('replietop20webradio').style.display = '';
    	document.getElementById('replietop20webradioa').innerHTML = "Replier";
	}
}

var callAJAXtop20webradio = function(tri, current,type_id){
	var sUrl = "/sidebar/topplaylist?tri="+tri+"&current="+current+"&type_id="+type_id;
	var transaction = Nrj_Library.Execute(sUrl, {}, callback);
	
	return false;
}
var lancePlaylist = function(div, hit_lien_ecoute){
		$(div).style.display="block";
		$(div).style.height ="30px;";
		$(div).innerHTML = '<object width="190" height="16" align="middle" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=7,3,0,0" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"><param value="'+hit_lien_ecoute+'" name="src"/><param value="true" name="autoplay"/><param value="true" name="controller"/><param value="true" name="kioskmode"/><param value="false" name="showlogo"/><param value="myDiv4" name="destnode"/><embed width="190" height="16" align="middle" destnode="myDiv4" showlogo="false" kioskmode="true" controller="true" autoplay="true" pluginspage="http://www.apple.com/quicktime/download/" src="'+hit_lien_ecoute+'"/></object>';
}
var callback = function(o){
	document.getElementById('topcontenttop20webradio').innerHTML = o.responseText;
	ajax_exec('topcontenttop20webradio');
}
