var counter = 0;
var z_index = 2000;
var resized = false;

// Open a new "popup" for showing the attachment
function show_attachment(url, attachment_type, guid)
{
    var day = new Date();
    var id = day.getTime();
    
    switch (attachment_type)
    {
        case 'picture':
            eval ('var page_' + id + ' = window.open("/show-attachment/?url=' + url + '&type=' + attachment_type + '&guid=' + guid + '", "' + id + '", "toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=1, width=440, height=330");');
            break;
            
        case 'movie':
            eval ('var page_' + id + ' = window.open("/player.php?url=' + url + '", "toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=1, width=440, height=330");');
            break;
        
        default:
            alert(attachment_type);
    }
    
}

function load_content (url, guid, type)
{
    container.innerHTML = inner_html;
}

function bring_on_top(object)
{
    object.style.zIndex = z_index;
    z_index++;
}

// Close the window
function close_window(object)
{ 
    var guid = object.id;
    Effect.Fade(object.id, {duration:1, afterFinish:setTimeout('remove_object("' + guid + '")', 2500)});
}

function remove_object(id)
{
    var object = document.getElementById(id);
    
    if (!object)
    {
        return;
    }
    
    object.parentNode.removeChild(object);
}

function resize(id)
{
    var object = document.getElementById(id);
    
    if (!object)
    {
        alert('Failed to get the object ' + id);
        return false;
    }
    
    var dw = 0;
    var dh = 0;
    
    switch (browser)
    {
        case 'MSIE':
            if (browser_version == 7)
            {
                dw = 40;
                dh = 60;
                
                height = object.height + dh + 20;
                width = object.width + dw + 20;
                
                window.resizeTo(width, height);
                return;
            }
            
            dw = 40;
            dh = 60;
            
            height = object.height + dh + 20;
            width = object.width + dw + 20;
            
            window.resizeTo(width, height);
            break;
            
        default:
            dw = window.outerWidth - document.body.clientWidth;
            dh = window.outerHeight - document.body.clientHeight;
            window.resizeTo(object.width + dw + 10, object.height + dh + 20);
            break;
    }
}

function resize_picture_window(width, height)
{

}

// Resizes the window according to the properties fetched by the Flash object
function resize_window(width, height)
{
    var object = document.getElementById('content');
    
    if (resized == true)
    {
        return;
    }
    
    if (!object)
    {
//        alert('Object not found!');
        return;
    }
    
    width = Math.round(width);
    height = Math.round(height);
    
    object.setAttribute('width', width);
    object.setAttribute('height', height);
    
    window.resizeTo(width + 50, height + 50);
    resized = true;
    
    var embed = object.getElementsByTagName('embed');
    
    if (embed && embed[0])
    {
    }
    else
    {
//        alert('Embedded object not reached!');
        return;
    }
    
}