// JavaScript Document

var iClientID = 2;


function gjs_common_newIFrame(id, attributes) {
	
	var IFrObj = document.getElementById(id);
	if (IFrObj != null) return IFrObj;
	if (!document.createElement) {
		return null;
	}
	else {
		
		var att = {};
		att.border	= (typeof(attributes.border) == 'string') 	? attributes.border 	: '0px';
		att.width	= (typeof(attributes.width) == 'string') 	? attributes.width 		: '0px';
		att.height	= (typeof(attributes.height) == 'string') 	? attributes.height 	: '0px';
		att.overflow= (typeof(attributes.overflow) == 'string') ? attributes.overflow 	: 'scroll';
		
		// create the IFrame and assign a reference to the
		// object to our global variable IFrameObj.
		// this will only happen the first time 
		// callToServer() is called
		try {
			
			var tempIFrame=document.createElement('iframe');
			tempIFrame.setAttribute('id',id);
			tempIFrame.style.border=att.border;
			tempIFrame.style.width=att.width;
			tempIFrame.style.height=att.height;
			tempIFrame.style.overflow=att.overflow;
			IFrObj = document.body.appendChild(tempIFrame);
			
			if (document.frames) {
				// this is for IE5 Mac, because it will only
				// allow access to the document object
				// of the IFrame if we access it through
				// the document.frames array
				IFrObj = document.frames[id];
			}
			
		} catch(exception) {
			// This is for IE5 PC, which does not allow dynamic creation
			// and manipulation of an iframe object. Instead, we'll fake
			// it up by creating our own objects.
			iframeHTML='<iframe id="' + id + '" style="';
			iframeHTML+='border:' + att.border + ';';
			iframeHTML+='width:' + att.width + ';';
			iframeHTML+='height:' + att.height + ';';
			iframeHTML+='overflow:' + att.overflow + ';';
			iframeHTML+='"><\/iframe>';
			document.body.innerHTML+=iframeHTML;
			IFrObj = new Object();
			IFrObj.document = new Object();
			IFrObj.document.location = new Object();
			IFrObj.document.location.iframe = document.getElementById(id);
			IFrObj.document.location.replace = function(location) {
				this.iframe.src = location;
			}
		
		}
	
	}
	
	return IFrObj;
	
}

function gjs_common_getIFrameDoc(id) {
	var IFrObj = $(id);
	if (IFrObj.contentDocument) {
		// For NS6
		return IFrObj.contentDocument; 
	} else if (IFrObj.contentWindow) {
		// For IE5.5 and IE6
		return IFrObj.contentWindow.document;
	} else if (IFrObj.document) {
		// For IE5
		return IFrObj.document;
	}
	return null;
	
}


var MyMemory = {
	memoArea:'/pt-BR',
	memoTime:2,
	_construct: function() {
		return this;
	},
	remember: function(name, value) {

		var json = Object.toJSON(value);
		Cookie.set(name, json, {path:this.memoArea,daysToExpire:this.memoTime});

		var mem_ifr = gjs_common_getIFrameDoc('mem_ifr');
		if (mem_ifr.mem_form) {
			mem_ifr.mem_form.mem_key.value = name;
			mem_ifr.mem_form.mem_val.value = json;
			mem_ifr.mem_form.submit();
		}

	},
	forget: function(name) {
		Cookie.erase(name,{path:this.memoArea});
	},
	whatis: function(name) {
		try {
			var Saved = Cookie.get(name);
			if (Saved != null) {
				var Val = Saved.evalJSON();
				Cookie.set(name, Saved, {path:this.memoArea,daysToExpire:this.memoTime});
				return Val;
			}
		}
		catch (e) {}
		return null;
	}
}._construct();

function gjs_common_insertFlash(id, src, width, height, flashvars) {
	
	AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width',width,'height',height,'src',src,'menu','false','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie',src, 'id', id, 'allowscriptaccess', 'always', 'flashvars',flashvars); //end AC code
	
}

function gjs_common_podcastPlayer(id, file) {
	gjs_common_insertFlash(id, '/pt-BR/podcast_player', 120, 18, 'file=' + file);
}


function gjs_common_setAsHomePage() {
// http://www.kirupa.com/web/sethomepage.htm
// http://flashmove.com/forum/archive/index.php/t-8186.html
	document.body.style.behavior='url(#default#homepage)';
	document.body.setHomePage(window.location.href);
}

function gjs_common_addToFavorites(){ 
	if (document.all) window.external.AddFavorite(document.location.href, document.title); 
	else if (window.sidebar) window.sidebar.addPanel(document.title, document.location.href, "") ;
} 


//  _/_/_/_/_/
// _/ ADS  _/
//_/_/_/_/_/

//document.write ('<' + 'script language="javascript" type="text/javascript" src="http://ads.radioinbox.net/ads/adx.js"><' + '/script>');

function gjs_ads_showBanner(sParams) {

	var m3_u = (location.protocol=='https:'?'https://ads.radioinbox.net/ads/www/delivery/ajs.php':'http://ads.radioinbox.net/ads/www/delivery/ajs.php');
	var m3_r = Math.floor(Math.random()*99999999999);
	if (!document.MAX_used) document.MAX_used = ',';
	document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
	document.write ('?cb=' + m3_r);
	document.write (sParams);
	if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
	document.write ("&amp;loc=" + escape(window.location));
	if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
	if (document.context) document.write ("&context=" + escape(document.context));
	if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
	document.write ("'><\/scr"+"ipt>");


}


//  _/_/_/_/_/_/_/
// _/ Player   _/
//_/_/_/_/_/_/_/

function gjs_player_volDown() {
	if (top && top.playerFrame && top.playerFrame.MPlayer) {
		top.playerFrame.MPlayer.decreaseVolume();
	}
}
function gjs_player_volUp() {
	if (top && top.playerFrame && top.playerFrame.MPlayer) {
		top.playerFrame.MPlayer.increaseVolume();
	}
}
function gjs_player_stop() {
	if (top && top.playerFrame && top.playerFrame.MPlayer) {
		top.playerFrame.MPlayer.stop();
	}
}
function gjs_player_play() {
	if (top && top.playerFrame && top.playerFrame.MPlayer) {
		top.playerFrame.MPlayer.play();
	}
	else {
		gjs_player_confirm_n_pop();
	}
}
function gjs_player_status() {
	if (top && top.playerFrame && top.playerFrame.MPlayer) {
		return top.playerFrame.MPlayer.status();
	}
	return 0;
}
function gjs_player_volume() {
	if (top && top.playerFrame && top.playerFrame.MPlayer) {
		return top.playerFrame.MPlayer.getVolume();
	}
	return 50;
}
function gjs_player_pop(idx) {
	if (top && top.playerFrame && top.playerFrame.MPlayer) {
		top.playerFrame.MPlayer.stop();
	}
	var qs = (idx == undefined ? '' : 'auch=' + idx);
	var tpw = window.open('/pt-BR/transaplayer.php?' + qs, 'transaplayer', 'width=329,height=248,scrollbars=no,location=yes');
	tpw.focus();
	
}
function gjs_player_confirm_n_pop(idx) {
		if (confirm("O canal de áudio não está disponível nesta página.\nClique em Ok para abrir o TransaPlayer numa janela popup.")) {
			gjs_player_pop(idx);	
//			if (idx != undefined) window.history.go(0);
			if (idx != undefined) setTimeout("updateNowPlaying()", 500);

		}
}
function gjs_player_change(obj) {
	if (obj && obj.options)
	{
		var idx = obj.options[obj.selectedIndex].value;
		if (top && top.playerFrame) {
			top.playerFrame.location.href = '/pt-BR/radio.php?auch=' + idx;
	//		setTimeout('window.history.go(0)', 1000);
			setTimeout("updateNowPlaying()", 500);
			return;
		}
		gjs_player_confirm_n_pop(idx);
	}
}


//  _/_/_/_/_/_/_/_/_/_/_/_/_/
// _/ Styles Customization _/
//_/_/_/_/_/_/_/_/_/_/_/_/_/

var MyStyles = {
	CurrentStyles: $H({handle:'#FF0000', bg0:'#424242', bg1:'#3D3D3D'}),
	_construct: function() {
		var Saved = MyMemory.whatis('my_styles');
		if (Saved != null) {
			this.CurrentStyles = Saved;	
		}
		return this;
	},
	saveChanges: function() {
		MyMemory.remember('my_styles', this.CurrentStyles);
	},
	get: function(sWhich) {
		return this.CurrentStyles[sWhich];
	},
	set: function(sWhich, sWhat) {
		this.CurrentStyles[sWhich] = sWhat;
// Moved to onmouseout of control panel's div
//		this.saveChanges(); 
	}
}._construct();


function gjs_styles_set(which, what) {

	switch(which) {
		case 'handle': 	gjs_styles_setHandle(what);
						break;
		case 'bg0': 	gjs_styles_setBg0(what);
						break;
		case 'bg1': 	gjs_styles_setBg1(what);
						break;
	}

}

// Handle
gjs_styles_setHandle = function (rgb) {
	MyStyles.set('handle', rgb);
	gjs_styles_updateHandle();
}
gjs_styles_getHandle = function () {
	return MyStyles.get('handle');
}
// http://xavisys.com/tag/prototype/
getStyleClass  = function (className) {
    if (document.styleSheets.length < 1) {
        return null;
    }
    if (document.styleSheets[0].cssRules) {
        var cssRules = 'cssRules';
    } else {
        var cssRules = 'rules';
    }
    for (var s = 0; s < document.styleSheets.length; s++) {
        for (var r = 0; r < document.styleSheets[s][cssRules].length; r++) {
            if (document.styleSheets[s][cssRules][r].selectorText == '.' + className) {
                return document.styleSheets[s][cssRules][r];
            }
        }
    }
    return null;
}

gjs_styles_updateHandle = function() {
	try {
		getStyleClass('aba_cor').style.backgroundColor = gjs_styles_getHandle();
	} catch(e) {}
}

// Bg 0
gjs_styles_setBg0 = function (style) {
	MyStyles.set('bg0', style);
	gjs_styles_updateBg0();
}
gjs_styles_getBg0 = function () {
	return MyStyles.get('bg0');
}
gjs_styles_updateBg0 = function() {
	try {
		document.body.style.background = gjs_styles_getBg0();	
	} catch(e) {}
}

// Bg 1
gjs_styles_setBg1 = function (style) {
	MyStyles.set('bg1', style);
	gjs_styles_updateBg1();
}
gjs_styles_getBg1 = function () {
	return MyStyles.get('bg1');
}
gjs_styles_updateBg1 = function() {
	try {
		$('main').style.background = gjs_styles_getBg1();	
	} catch(e) {}
}



//  _/_/_/_/_/_/_/_/
// _/ MM Library _/
//_/_/_/_/_/_/_/_/


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
