function toggleSection(id, itm){
	var n= document.getElementById(id);
	if(n){
		for(var i=0;i<n.parentNode.childNodes.length;i++){
			if(n.parentNode.childNodes[i].className&&hasClass(n.parentNode.childNodes[i], 'vertial_head')){
				n.parentNode.childNodes[i].style.backgroundImage="URL('/images/twist_closed.gif')";
			}
			if(n.parentNode.childNodes[i].id&&n.parentNode.childNodes[i].id.substring(0, 8)=='vertual_'&&n.parentNode.childNodes[i].id!=id){
				n.parentNode.childNodes[i].style.display='none';
			}
		}
		
		if(n.style.display=='block'){
			n.style.display='none';
			itm.style.backgroundImage="URL('/images/twist_closed.gif')";
		}else{
			n.style.display='block';
			itm.style.backgroundImage="URL('/images/twist_open.gif')";
		}
	}
}
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
 
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
 
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
    	var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}
function trace(msg){
	if(console)console.log(msg);
}
function amtabs(parent){
	this.parent=document.getElementById(parent);
	this.tablist = new Array();
	this.mtable = new Array();
	
}
amtabs.prototype.addTab=function(name, url, image, active, canclose, target){
	this.tablist[name]=new Object();
	this.tablist[name].active=active;
	this.tablist[name].name=name;
	this.tablist[name].url=url;
	this.tablist[name].image=image;
	this.tablist[name].canclose=canclose;
	this.tablist[name].target=target;
};
amtabs.prototype.render=function(){
	var otable=document.createElement("table");
	otable.className='tab';
	var tablebody=document.createElement("tbody");
	otable.appendChild(tablebody);	
	var row = tablebody.insertRow(-1);

	for (var tab in this.tablist){
		row.insertCell(-1).appendChild(this.makeTab(this.tablist[tab]));
//		this.parent.appendChild(this.makeTab(this.tablist[tab]));
	}
	lastimg=document.createElement("img");
	lastimg.id='lastimg';
	lastimg.src='/images/1px_tabright_normal.gif';
	row.insertCell(-1).appendChild(lastimg);
	this.parent.appendChild(otable);
};
amtabs.prototype.resetTabs=function(){
	for (var tab in this.tablist){
		var t=document.getElementById(tab);
		this.setState(t, 'normal');
		t.setAttribute('active', 0);
	}	
};
amtabs.prototype.setState=function(mtable, state){
	mtable.style.backgroundImage="URL('/images/tab_"+state+"_mid.gif')";
	mtable.rows[0].cells[0].firstChild.src='/images/tab_'+state+'_left.gif';
	mtable.rows[0].cells[2].firstChild.src='/images/tab_'+state+'_right.gif';
	
	var lastimg=document.getElementById('lastimg');
	if(lastimg&&mtable.getAttribute('tnum')==this.mtable.length-1)lastimg.src='/images/1px_tabright_'+state+'.gif';
};
amtabs.prototype.makeTab=function(tab){
	var tnum=this.mtable.length;
	this.mtable[tnum]=document.createElement("table");
	var mtable=this.mtable[tnum];
	mtable.className='tab';
//	mtable.style.cssFloat='left';
	mtable.id=tab.name;
	mtable.setAttribute('active', tab.active);
	mtable.setAttribute('tnum', tnum);
	var tablebody=document.createElement("tbody");
	mtable.appendChild(tablebody);	
	
	var left_img = document.createElement('img');
	var right_img = document.createElement('img');

	var tab_img = document.createElement('img');
	tab_img.src='/images/tabs/'+tab.image;
	tab_img.alt=tab.name;
	
	var row = tablebody.insertRow(-1);
	row.insertCell(-1).appendChild(left_img);
	row.insertCell(-1).appendChild(tab_img);
	row.insertCell(-1).appendChild(right_img);
	var url=tab.url;
	var target=tab.target;
	var canclose=tab.canclose;
	var amtabs=this;
	isis.addEventHandler(mtable, 'click', function(e){
		var iframe=document.getElementById(target);
		var gadgets=document.getElementById('gadgets');
		if(url=='gadgets'){
			iframe.style.display='none';
			gadgets.style.display='block';
		}else{
			if(iframe){
				iframe.style.display='block';
				gadgets.style.display='none';
				iframe.src=url;
			}else{
				window.open(url, target);
			}
		}
		amtabs.resetTabs();
		mtable.setAttribute('active', 1);
		amtabs.setState(mtable, 'active');
		
		var close=document.getElementById('close');
		if(canclose){
			close.style.display='block';
		}else{
			close.style.display='none';
		}
	});
	isis.addEventHandler(mtable, 'mouseover', function(e){
		if(mtable.getAttribute('active')==0){
			amtabs.setState(mtable, 'over');
		}
	});
	isis.addEventHandler(mtable, 'mouseout', function(e){
		if(mtable.getAttribute('active')==0){
			amtabs.setState(mtable, 'normal');
		}
	});
	if(tab.active==1){
		var gadgets=document.getElementById('gadgets');
		var iframe=document.getElementById(target);
		if(tab.url=='gadgets'){
			if(iframe)iframe.style.display='none';
			gadgets.style.display='block';
		}else{
			if(iframe)iframe.style.display='block';
			gadgets.style.display='none';
			if(iframe)iframe.src=tab.url;
		}

		this.setState(mtable, 'active');
	}else{
		this.setState(mtable, 'normal');
	}
	
	return mtable;
};
var widgetPropsList = new Array();
var widgetList = [];
var widgetProps= {
	movable: false,
	showButtons: false,
	bodyColour: '#ffffff',
	titleColour: '#2f4895',
	borderColour: '#c2cddf',
	headerHeight: '22px',
	corners: new Array('1','1','0', '0'),
	titleWeight: 'bold',
	titleSize: '14px',
	closeImg: '/images/hide.gif',
	minimiseImg: '/images/minimise.gif',
	restoreImg: '/images/restore.gif',
	closeImgOver: '/images/hideover.gif',
	minimiseImgOver: '/images/minimiseover.gif',
	restoreImgOver: '/images/restoreover.gif',
	closeAnimation: 'rollleft',
	cookieName: 'widgets',
	changedCallback: function(){
		saveCookie();
	}
};
function saveCookie(){
//	isis.ajax({'url': '/index/autoaction/savewidgets'});
}
function cloneObject(what){
    for (i in what) {
        if (typeof what[i] == 'object') {
            this[i] = new cloneObject(what[i]);
        }
        else
            this[i] = what[i];
    }
}
function restoreWidgets(cookie, widgetPropsList){
	if(cookie!='null'){
		var w=cookie.split('|');
		for(var ii=0;ii < w.length;ii++){
			w[ii]=w[ii].replace(/^\s+|\s+$/, '');
			var p = w[ii].split('^');
			if(p.length==3&&document.getElementById(p[2])){
				var thiswidget=widgetPropsList[p[0].replace(/[^a-z\d]/ig, '')];
				if(thiswidget){
					thiswidget.pos=p[2];
					addWidget(thiswidget);
				}
			}
		}
	}
	for(var thiswidget in widgetPropsList){
		if(!haveWidget(widgetPropsList[thiswidget].title))addWidget(widgetPropsList[thiswidget]);
	}
}
function haveWidget(name){
	for(var thiswidget in widgetList){
		if(widgetList[thiswidget].titletext==name){
			return true;
		}
	}
	return false;
}
function addWidget(props){
/*	var thiswidget=new Object();
	
	for(var i in widgetProps){
		thiswidget[i]=widgetProps[i];
	}
	for(var i in props){
		thiswidget[i]=props[i];
	}
*/
	var thiswidget=new cloneObject(widgetProps);
	thiswidget.movable=props.movable;
	thiswidget.showButtons=props.showButtons;
	thiswidget.cookieName=props.key_word;
	if(props.closeCallback.length>0)thiswidget.closeCallback=props.closeCallback;
	
	if(typeof props.loadedCallback=='function'){
		thiswidget.loadedCallback=props.loadedCallback;
	}
	if(props.backgroundcolour.length>0)thiswidget.bodyColour=props.backgroundcolour;
	if(props.bordercolour.length>0)thiswidget.borderColour=props.bordercolour;
	if(props.titlecolour.length>0)thiswidget.titleColour=props.titlecolour;
	if(props.icon.length>0)thiswidget.icon=props.icon;
	if(props.colour.length>0)thiswidget.headerColour=props.colour;

	widgetList.push(isis.widget(props.title, props.url, props.pos, thiswidget));
}
function dosearchv2(action, sid, span){	
/*	if(document.getElementById('q').value=='Search the web here...'||)return;
	window.location.href=url+document.getElementById('q').value;*/
	for(var i=0;i<span.parentNode.childNodes.length;i++){
		if(span.parentNode.childNodes[i].nodeName=='SPAN'){
			span.parentNode.childNodes[i].className='span_link';
		}
	}
	span.className='span_link_s';
	var q=document.getElementById('q');
	var search_from=document.getElementById('search_from');
	search_from.action=action;
	q.name=sid;
//	if(q.value!='Search the web here...'&&q.value!='')q.form.submit();
}
function dosearch(url){	
	if(document.getElementById('q').value=='Search the web here...')return;
	window.location.href=url+document.getElementById('q').value;
}
function removeFrame(){
	var iframe=document.getElementById('amframe');
	if(iframe){
//		window.location.href=iframe.src;
		var header=document.getElementById('header');
		header.style.display='none';
		iframe.style.height=(document.documentElement.clientHeight-5)+'px';

	}
}
isis.addEventHandler(window, 'load', function(){
	try {
		var pageTracker = _gat._getTracker("UA-9846192-1");
		pageTracker._trackPageview();
	} catch(err) {}
});
function hideRSSBody(uid, num){
	var rssbody=document.getElementById(uid+'rssbody'+num);
	if(rssbody)rssbody.style.display='none';
	var rsstitle=document.getElementById(uid+'rsstitle'+num);
	if(rsstitle)rsstitle.style.color='#000000';
	if(rsstitle)rsstitle.style.textDecoration='none';
}
function showRSSBody(e, uid, num){

	var rssbody=document.getElementById(uid+'rssbody'+num);
	if(rssbody){
		rssbody.style.display='block';
		var pos=isis.getMouseCoords(e);
		rssbody.style.left=(pos.x+245<=document.documentElement.clientWidth)?(pos.x+20)+'px':(document.documentElement.clientWidth-245)+'px';
//		alert(rssbody.style.left);
//		rssbody.style.left=(pos.x+20)+'px';
		rssbody.style.top=(pos.y+15)+'px';
	}
}
function rss_mouseover(gname, tnum){
	var gadget=document.getElementById('gadget_'+gname);
	if(gadget.rows[0].cells[tnum].className!='rsstab_selected')gadget.rows[0].cells[tnum].className='rsstab_hover';
}
function rss_mouseout(gname, tnum){
	var gadget=document.getElementById('gadget_'+gname);
	if(gadget.rows[0].cells[tnum].className!='rsstab_selected')gadget.rows[0].cells[tnum].className='rsstab';
}
function rss_change_tab(gname, tnum){
	var gadget=document.getElementById('gadget_'+gname);
	for(var i=0;i<gadget.rows[0].cells.length;i++){
		if(gadget.rows[0].cells[i].className!='rsstabspace')gadget.rows[0].cells[i].className=tnum==i?'rsstab_selected':'rsstab';
	}
	for(var i=0;i<gadget.rows[1].cells[0].childNodes.length;i++){
		gadget.rows[1].cells[0].childNodes[i].style.display=gadget.rows[1].cells[0].childNodes[i].id==gname+tnum?'block':'none';
	}
}
function bbcnews_showTab(number){
	bbcnews_hideallTabs();
	var tab = document.getElementById('bbcnews_tab_' + number);
	var label = document.getElementById('bbcnews_menu_' + number);
	isis.createCookie('bbcnewsTab', number, 1);
	if ( tab.style.display == 'none') {
		tab.style.display = 'block';
		if(label){
			label.className='isisTabPressed';
		}
	}
}
function calcHeight(id){
  //find the height of the internal page
  var the_height=document.getElementById(id).contentWindow.document.body.scrollHeight;
  //change the height of the iframe
  document.getElementById(id).height=the_height;
}
function showDesc(st){
	var shortdesc = document.getElementById('short_' + st);
	var longdesc = document.getElementById('long_' + st);
	shortdesc.style.display='none';
	longdesc.style.display='block';
}
function zoomout(){
	if(document.body.style.zoom!=0){ 
		document.body.style.zoom*=0.833;
	}else{
		document.body.style.zoom=0.833;
	}
	if(parent.document.body.style.zoom!=0){ 
		parent.document.body.style.zoom*=0.833;
	}else{
		parent.document.body.style.zoom=0.833;
	}
}
function zoomin(){
	if(document.body.style.zoom!=0){
		document.body.style.zoom*=1.2; 
	}else{
		document.body.style.zoom=1.2;	
	}	
	if(parent.document.body.style.zoom!=0){
		parent.document.body.style.zoom*=1.2; 
	}else{
		parent.document.body.style.zoom=1.2;	
	}
}
function f_open_window_max( aURL, aWinName ){
   var wOpen;
   var sOptions;

   sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName );
   wOpen.location = aURL;
   wOpen.focus();
   wOpen.moveTo( 0, 0 );
   wOpen.resizeTo( screen.availWidth, screen.availHeight );
   return wOpen;
}
var flickrLists=new Object();
function flickrShow(list, id){
	flickrLists[id]=list;
	var holder=document.getElementById(id);
	var img=document.createElement('img');
	holder.appendChild(img);
	var title=document.createElement('div');
	title.className='flickr_mini_title';
	title.id=id+'_mini_title';
	holder.appendChild(title);
	
	img.setAttribute('nextimg', 0);
	img.setAttribute('timerstate', 1);
	
	var changeFunc=function(){
		if(img.getAttribute('timerstate')==0)return;
		var n=img.getAttribute('nextimg');
		if(!list[n])n=0;
		img.src=list[n].url;
		title.innerHTML=list[n].title;
		n++;
		img.setAttribute('nextimg', n);
	};
	changeFunc();
	setInterval(changeFunc, 5000);
}
function flickrPauseToggle(id){
	var holder=document.getElementById(id);
	var img=holder.firstChild;
	if(img.getAttribute('timerstate')==0){
		img.setAttribute('timerstate', 1);
	}else{
		img.setAttribute('timerstate', 0);
	}
}
function flickrPrev(id){
	var holder=document.getElementById(id);
	var img=holder.firstChild;
	var n=img.getAttribute('nextimg');
	if(n>1){
		n=n-2;
	}else{
		n=flickrLists[id].length-1;
	}
	img.src=flickrLists[id][n].url;
	var title=document.getElementById(id+'_mini_title');
	title.innerHTML=flickrLists[id][n].title;
	n++;
	img.setAttribute('nextimg', n);		
}
function flickrNext(id){
	var holder=document.getElementById(id);
	var img=holder.firstChild;
	var n=img.getAttribute('nextimg');
	if(!flickrLists[id][n])n=0;
	img.src=flickrLists[id][n].url;
	var title=document.getElementById(id+'_mini_title');
	title.innerHTML=flickrLists[id][n].title;	
	n++;
	img.setAttribute('nextimg', n);	
}
function flickrEnlarge(id){
	var cover=isis.screenCover();
	cover.setColour('#FFFFFF');
	var holder=document.createElement('div');

	holder.className='flickrPopup';
	holder.style.position='absolute';
	isis.fx(holder).opacity(0);
	document.body.appendChild(holder);
	
	var popupbody=document.createElement('div');
	popupbody.className='flickrPopupBody';
	holder.appendChild(popupbody);
	

	var title=document.createElement('div');
	title.id=id+'_title';
	title.className='flickrTitle';
	popupbody.appendChild(title);
	

		
	var close=document.createElement('img');
	close.src='/images/common/flikr/flikr-reduce-normal.gif';
	
	isis.addEventHandler(close, 'mouseover', function(e){
		this.src='/images/common/flikr/flikr-reduce-hover.gif'
	});	
	isis.addEventHandler(close, 'mouseout', function(e){
		this.src='/images/common/flikr/flikr-reduce-normal.gif'
	});	
		
	
	close.style.cssFloat='right';
	close.style.styleFloat='right';
	close.style.cursor='pointer';

	popupbody.appendChild(close);
	isis.addEventHandler(close, 'click', function(e){
		isis.fx(holder, {'finishedCallback': function(){if(holder.parentNode)holder.parentNode.removeChild(holder);}}).tween("opacity:0");
		cover.distroy();
	});	
	
	var closet=document.createElement('img');
	closet.src='/images/common/flikr/flickr-c.png';
	closet.style.cssFloat='right';
	closet.style.styleFloat='right';
	popupbody.appendChild(closet);	
	
	var stage=document.createElement('div');
	stage.className='flickrStage';
	popupbody.appendChild(stage);	
	
	var canvas=document.createElement('div');
	canvas.className='flickrCanvas';
	canvas.id=id+'_canvas';
	stage.appendChild(canvas);
	
	
	var thumbs=document.createElement('div');
	thumbs.className='flickrThumbs';
	stage.appendChild(thumbs);

	
	for(var i=0;i<flickrLists[id].length;i++){
		var img=document.createElement('img');
		img.src=flickrLists[id][i].small;
		thumbs.appendChild(img);
		var img_n=i;
		img.setAttribute('img_n', i);
		img.setAttribute('set_id', id);
		isis.addEventHandler(img, 'click', function(e){
			if(!e.currentTarget)e.currentTarget=e.srcElement;
			showFlickrImage(e.currentTarget);
		});
	}
	

	var footer=document.createElement('div');
	footer.className='flickrFooter';
	stage.appendChild(footer);	
	
	var logo=document.createElement('img');
	logo.src='/images/common/flikr/flickr.png';
	logo.style.marginTop='15px';
	logo.style.cssFloat='right';
	logo.style.styleFloat='right';
	footer.appendChild(logo);	
	
	holder.style.top=(isis.getScrollTop()+(isis.getClientHeight()-holder.offsetHeight)/2)+'px';	
	holder.style.left=(isis.getScrollLeft()+(isis.getClientWidth()-holder.offsetWidth)/2)+'px';


	isis.addEventHandler(cover.holder, 'click', function(e){
		isis.fx(holder, {'finishedCallback': function(){if(holder.parentNode)holder.parentNode.removeChild(holder);}}).tween("opacity:0");
		cover.distroy();
	});

	var h=document.getElementById(id);
	var img=h.firstChild;
	var n=img.getAttribute('nextimg');
	n--;
	if(!flickrLists[id][n])n=0;
	_showFlickrImage(id, n);
	
	cover.show();
	isis.fx(holder).tween("opacity:1");	
	
}
function _showFlickrImage(id, img_n){
	var canvas=document.getElementById(id+'_canvas');
	var title=document.getElementById(id+'_title');
	
	while(canvas.firstChild)canvas.removeChild(canvas.firstChild);
	var img=document.createElement('img');
	img.src=flickrLists[id][img_n].large;
	img.style.border='1px solid #a1a1a1';
	canvas.appendChild(img);
	canvas.appendChild(document.createElement('br'));
	var desc=document.createElement('div');
	desc.innerHTML=flickrLists[id][img_n].desc;
	canvas.appendChild(desc);
	
	title.innerHTML=flickrLists[id][img_n].title;
		
}
function showFlickrImage(img){
	var img_n=img.getAttribute('img_n');
	var id=img.getAttribute('set_id');	
	_showFlickrImage(id, img_n);
}