var ca_popup_id = -1;
var ca_popup_counter = 0;
var ca_popup_list = new Array();
var ca_forums_list = new Array();
var ca_item;
var ca_item2;
var ca_list;
var ca_list2;
var ca_code;
var ca_timer;
var ca_left;
var ca_exp = new Date(); 

ca_exp.setTime(ca_exp.getTime() + (90*24*60*60*1000));
onload_functions[onload_functions.length] = 'ca_popup_init();';
onload_functions[onload_functions.length] = 'ca_forums_init();';
onload_functions[onload_functions.length] = 'ca_resize_images();';

// expand code
function ca_expand_code(a)
{
	// Get ID of code block
	var e = a.parentNode.parentNode.parentNode.getElementsByTagName('CODE')[0];
	if(e)
	{
	    if(e.style.overflow == 'visible')
	    {
	        e.style.maxHeight = '200px';
	        e.style.overflow = 'auto';
	    }
	    else
	    {
	        e.style.maxHeight = 'none';
	        e.style.overflow = 'visible';
	    }
	}
}


// expand forum
function ca_expand_forum(a, id)
{
	// Find parent block
	var e = a.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('UL')[1];
	var expanded = 1;
	if(e)
	{
	    if(e.style.display == 'none')
	    {
	        e.style.display = '';
        	var expanded = 2;
	    }
	    else
	    {
	        e.style.display = 'none';
	    }
	    if(id)
	    {
	        ca_cookie_set('expand' + id, expanded);
        }
	}
}

// add new item to queue
function ca_forum_register(id)
{
    ca_forums_list[ca_forums_list.length] = id;
}

// expand forums
function ca_forums_init()
{
    var id, i, j, do_minimize;
    for(i=0; i<ca_forums_list.length; i++)
    {
        id = ca_forums_list[i];
        // find item, expand block
        ca_item = document.getElementById('forumblock' + id);
        if(ca_item)
        {
            if(ca_cookie_get('expand' + id) == 1)
            {
                ca_expand_forum(ca_item, 0);
            }
        }
    }
}

// minimize/maximize post
function ca_post_minimize(num)
{
    ca_item = document.getElementById('profilediv' + num);
    ca_item2 = document.getElementById('body' + num);
    if(ca_item && ca_item2)
    {
        ca_item.style.display = 'none';
        ca_item2.className = 'postbody post-hidden';
        ca_item = document.getElementById('maximize' + num);
        if(ca_item)
        {
            ca_item.style.display = '';
        }
        ca_item = document.getElementById('author' + num);
        if(ca_item)
        {
            ca_item.style.display = '';
        }
    }
}

function ca_post_maximize(num)
{
    ca_item = document.getElementById('profilediv' + num);
    ca_item2 = document.getElementById('body' + num);
    if(ca_item && ca_item2)
    {
        ca_item.style.display = '';
        ca_item2.className = 'postbody';
        ca_item = document.getElementById('maximize' + num);
        if(ca_item)
        {
            ca_item.style.display = 'none';
        }
        ca_item = document.getElementById('author' + num);
        if(ca_item)
        {
            ca_item.style.display = 'none';
        }
    }
}

function ca_post_minimize_all()
{
    var id, i;
    for(i=0; i<ca_popup_list.length; i++)
    {
        id = ca_popup_list[i];
        ca_post_minimize(id);
    }
    ca_cookie_set('hideprofiles', 1);
}

function ca_post_maximize_all()
{
    var id, i;
    for(i=0; i<ca_popup_list.length; i++)
    {
        id = ca_popup_list[i];
        ca_post_maximize(id);
    }
    ca_cookie_set('hideprofiles', 0);
}
