var IsIE = !!(window.attachEvent && !window.opera);
var IsOpera = !!window.opera;
var IsMozilla = navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1;
function __(href){window.open(href+(href.indexOf('?')<0?'?':'&')+'window=' + Math.floor(Math.random() * 0xFFFFFFFF) ,Math.floor(Math.random() * 0xFFFFFFFF).toString(),'width=780,height=580,resizable=yes,scrollbars=yes');}

// ContextMenu
var __CM=[];
function __CCM(){var iid=arguments[0];var a=[];for(var i=1;i<arguments.length;i+=4)a.push({IconSrc:arguments[i],Href:arguments[i+1],Target:arguments[i+2],Caption:arguments[i+3]});__CM[iid]={id:iid,actions:a,timer:null,div:null};}
function __SCM(id){var s='';var menu=__CM[id];if(menu.timer!=null){clearTimeout(menu.timer);menu.timer=null;}if(menu.div!=null)return;var a=menu.actions;for(var i=0;i<a.length;i++)s+='<a onmouseover="__SCM(\''+id+'\');\" onmouseout=\"__HCM(\''+id+'\');\" href="'+a[i].Href+'" target="'+a[i].Target+'"><img src="'+a[i].IconSrc+'" align="absmiddle" /><img src="skn/spacer.gif" width="10" height="1" align="absmiddle" />'+a[i].Caption+'</a>';var body=$(document.body);var angor=$('__CMA'+id);var div=new Element('div');div.addClassName('ContextMenu');div.style.position='absolute';div.style.top=(angor.cumulativeOffset().top+angor.getHeight())+'px';div.style.left=angor.cumulativeOffset().left+'px';div.update(s);body.insert(div);menu.div=div;}
function __HCM(id){__CM[id].timer=setTimeout("__DHCM('"+id+"');",100);}
function __DHCM(id){var menu=__CM[id];if(menu.div!=null){menu.div.remove();menu.div=null;}menu.timer=null;}


// Balloons
function CallBalloon(url){new Ajax.Request(url,{method:'GET',onSuccess:function(transport){ShowBalloon(transport.responseText);}});}
function ShowBalloon(content){
    new Insertion.Bottom($(document.body),'<div id="BalloonContainer" style="position:absolute;top:0px;left:0px;width:'+document.body.scrollWidth+'px;height:'+document.body.scrollHeight+'px;background:#1A1A1A;" ><div>');
    new Insertion.Bottom($(document.body),'<div id="curBalloonContainer" style="position:absolute;top:0px;left:0px;display:none;"><div>');
    $('curBalloonContainer').update(''+content+'');
    $('BalloonContainer').setOpacity(0.8);
    $('BalloonContainer').style.zIndex=200;
    $('BalloonContainer').onclick=function(){RemoveBalloon();}
    var initLeft=parseInt(((document.body.clientWidth-200)/2))+'px';
    var initTop=parseInt(((document.body.clientHeight-200)/2))+'px';
    new Insertion.Bottom($(document.body),'<table id="BalloonLayer" width="300px" height="170px" cellspacing="0" cellpadding="0" border="0" style="position:absolute;top:'+initTop+';left:'+initLeft+';z-index:201;">'
     + '<tr><td width="16" height="16"><img src="skn/popup/tl.gif" /></td><td width="100%" style="background:#ffffff;"></td><td width="16" height="16"><img src="skn/popup/tr.gif" /></td></tr>'
     + '<tr style="background:#ffffff;" height="100%"><td></td><td class="Balloon" id="BalloonRealContainer"><div style="text-align:center;"><img id="barberpole" src="res/ac3/img/BarberPole.gif" /></div></td><td></td></tr>'
     + '<tr style="background:#ffffff;" height="30"><td></td><td><table cellspacing="0" cellpadding="0" border="0"><tr><td width="100%"></td><td style="cursor:hand;"><img src="skn/popup/close.gif"  onclick="RemoveBalloon();"></td></tr></table></td><td></td></tr>'
     + '<tr><td width="16" height="16"><img src="skn/popup/bl.gif" /></td><td width="100%" style="background:#ffffff;"></td><td width="16" height="16"><img src="skn/popup/br.gif" /></td></tr>'
     + '</table>');
    BalloonPositionTimer=setInterval(CenterBalloon,100);
	new PeriodicalExecuter(function(pe){$('BalloonRealContainer').update('');ResizeBalloon(parseInt($('curBalloonContainer').getWidth())+32,parseInt($('curBalloonContainer').getHeight())+62,40,''+content+'');pe.stop();},0.3);
	CenterBalloon();
}
function RemoveBalloon(){
	$('BalloonRealContainer').update('');
	$('curBalloonContainer').update('');
	$('BalloonRealContainer').remove();
	$('BalloonContainer').remove();
	$('curBalloonContainer').remove();
	$('BalloonLayer').remove();
	clearInterval(BalloonPositionTimer);
}
function CenterBalloon(){
	try{
		$('BalloonLayer').style.left=parseInt(((document.body.clientWidth-$('BalloonLayer').getWidth())/2))+'px';
		$('BalloonLayer').style.top=parseInt(((document.body.clientHeight-$('BalloonLayer').getHeight())/2)+document.body.scrollTop)+'px';
	}catch(err){}
}
function ResizeBalloon(toWidth,toHeight,frames,content){
	if(toWidth>parseInt(document.body.clientWidth)){toWidth=document.body.clientWidth};
	if(toHeight>parseInt(document.body.clientHeight)){toHeight=document.body.clientHeight};
	var curwidth=parseInt($('BalloonLayer').getWidth());
	var curheight=parseInt($('BalloonLayer').getHeight());
	var defWidth = (Math.abs(Math.abs(parseInt(toWidth))-Math.abs(parseInt(curwidth))));
	var defHeight = (Math.abs(Math.abs(parseInt(toHeight))-Math.abs(parseInt(curheight))));
	var dw = defWidth / frames;
	var dh = defHeight / frames;
	for (i = 0; i < frames-1; i++)
		setTimeout("DoResizeBalloon("+(curwidth+i*dw)+","+(curheight+i*dh)+");", (i+1)*10); 
	new PeriodicalExecuter(function(pe) {DoResizeBalloon(toWidth,toHeight);pe.stop();},frames*0.01);
	new PeriodicalExecuter(function(pe) {$('BalloonRealContainer').update(content);pe.stop();},frames*0.01+0.3);
}
function DoResizeBalloon(toWidth,toHeight){
	$('BalloonLayer').style.width=toWidth+'px';
	$('BalloonLayer').style.height=toHeight+'px';
	CenterBalloon();
}


















