// JavaScript Document
var end_opacity = 60; //end opacity, 25 = 25%, 50 = 50%, 100 = 100%, etc.
var increase_opacity_by = 15; //how much to increase by each time the timeout ends
var timeout = 10; //timeout in miliseconds, 0 = instant fade-out

var win = document.getElementById('thewindow');
var winbackground = document.getElementById('thewindowbackground');
var wincontent = document.getElementById('thewindowcontent');
var cur_opacity = 0;

var timer = null;

var _showWindowCallback = function(){};
var _hideWindowCallback = function(){};

function showWindow(wid, hit, title) 
{
	win = document.getElementById('thewindow');
	winbackground = document.getElementById('thewindowbackground');
	wincontent = document.getElementById('thewindowcontent');
	popTitle = document.getElementById('winTitle');
	
	try
	{
		popTitle.innerHTML = " " + title;
		wincontent.style.left = (getClientWidth() - wid) / 2 + "px";
		wincontent.style.top = (getClientHeight() - hit) / 2 + "px";
		thewindowbackground.style.height = getClientHeight() + "px";
	}
	catch(e)
	{
		
	}

	if(timeout > 0) 
	{
		cur_opacity = 0;
		winbackground.style.opacity = cur_opacity / 100;
		winbackground.style.filter = "alpha(opacity=" + cur_opacity + ")";
		win.style.display = 'block';
		wincontent.style.display = 'none';
	
		timer = setTimeout("increase_opacity()", timeout);
		
	}
	else 
	{
		winbackground.style.opacity = end_opacity / 100;
		winbackground.style.filter = "alpha(opacity=" + end_opacity + ")";
		win.style.display = 'block';
		wincontent.style.display = 'block';
		wincontent.style.left = (getClientWidth() - wid) / 2;
	}
	
	try
	{
		document.getElementById('flashmovie').style.display = 'none';
	}
	catch(e)
	{
		
	}
	
	_showWindowCallback();
}

function getClientWidth() {
       return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
     }
     
function getClientHeight() {
       return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
     }

function increase_opacity() {
	cur_opacity += increase_opacity_by;

	winbackground.style.opacity = cur_opacity / 100;
	winbackground.style.filter = "alpha(opacity=" + cur_opacity + ")";
	
	if(cur_opacity < end_opacity) {
		timer = setTimeout("increase_opacity()",timeout);
	}
	else {
		wincontent.style.display = 'block';
	}
}

function hideWindow() 
{
	win.style.display = 'none';
	try
	{
		document.getElementById('flashmovie').style.display = '';
	}
	catch(e)
	{
		
	}
	_hideWindowCallback();
}


//====================================================================================
// Accordian
//====================================================================================
var accordion=function(){
	var tm=5; var sp=5;
	function slider(n){
		this.nm=n; this.arr=[]; this.sel=''
	}
	slider.prototype.init=function(t,c,k){
		var a,h,s,l,i; a=document.getElementById(t);
		h=a.getElementsByTagName('dt'); s=a.getElementsByTagName('dd');
		l=h.length;
		for(i=0;i<l;i++){
			var d=h[i]; this.arr[i]=d; d.onclick=new Function(this.nm+".process(this)");
			if(k!=null&&c==i){this.sel=d.className=k}
		}
		l=s.length;
		for(i=0;i<l;i++){
			var d=s[i]; d.maxh=d.offsetHeight;
			if(c!=i){d.style.height='0'; d.style.display='none'}
		}
	}
	slider.prototype.process=function(d){
		var i,l; l=this.arr.length;
		for(i=0;i<l;i++){
			var h=this.arr[i]; var s=h.nextSibling;
			if(s.nodeType!=1){s=s.nextSibling}
			clearInterval(s.timer);
			if(h==d&&s.style.display=='none'){
				s.style.display=''; setup(s,1); h.className=this.sel}
			else if(s.style.display==''){setup(s,-1); h.className=''}
		}
	}
	function setup(c,f){c.timer=setInterval(function(){slide(c,f)},tm)}
	function slide(c,f){
		var h,m,d; h=c.offsetHeight; m=c.maxh; d=(f==1)?Math.ceil((m-h)/sp):Math.ceil(h/sp);
		c.style.height=h+(d*f)+'px'; c.style.opacity=h/m; c.style.filter='alpha(opacity='+h*100/m+')';
		if(f==1&&h>=m){clearInterval(c.timer)}
		else if(f!=1&&h==1){c.style.display='none'; clearInterval(c.timer)}
	}
	return{slider:slider}
}();
//=================================== Accordian end ==================================

//===================================== recent posts =================================

var captions = new Array();
var mytime;
function ShowItem(id, msg)
{
	mytime = setInterval(function(){resetItem();}, 1000);
	var stat = true;
	
	function resetItem()
	{
		if(stat)
		{
			try
			{
				//document.getElementById('dummy').value = captions[m];
				document.getElementById('repost').innerHTML = captions[m];
				//opacity('repost', 0, 100, 1000);
				m++;
				if(m >= captions.length)
				{
					m=0;
				}
			}
			catch(e)
			{
				//
			}
			clearInterval(mytime);
		}
		else
		{
			opacity('repost', 100, 0, 1000);
		}
		stat = !stat;
	}
}
var m = 0;
setInterval(ShowItem, 4000,"repost" ,captions[m]);
ShowItem("repost" ,captions[m]);


//==================================================================================
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
		clearInterval(mytime);
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
		clearInterval(mytime);
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


//=========================== News ticker ================================

var currentNewsIndex = 0;
var newsCont;
var newsShowCount;
var newsArr;
function newTicker(arr, cont, showCount)
{
	newsCont = cont;
	newsShowCount = showCount;
	newsArr = arr;
	
	dupArr = new Array();
	dupArr = dupArr.concat(arr, arr);
	
	// build show arr
	var showArr = new Array();
	for(var i = 0; i < showCount; i++)
	{
		showArr[i] = dupArr[(currentNewsIndex+i)];
	}
	
	var output = "";
	
	for(var i = 0; i < showArr.length; i++)
	{
		output += showArr[i] + "<br/>";
	}
	
	if(arr.length != 0)
	{
		cont.innerHTML = output;
	}
	else
	{
		cont.innerHTML = "<span style=\"color:#ffffff; padding-left:20px\">No posts available</span>";
	}
}

function nextNews()
{
	currentNewsIndex++;
	if(currentNewsIndex >= newsArr.length)
	{
		currentNewsIndex = 0;
	}
	newTicker(newsArr, newsCont, newsShowCount)
}
