var current_video = 0;

function showPlayer(id)
{
        if(albumvideos)
        {
                for(i = 0;i < albumvideos.length;i++)
                {
                        
                        if(albumvideos[i].id == id)
                        {
                                div = document.getElementById('play_video_popup');
                                if(!div)
                                {
                                        background = document.createElement('div');
                                        document.body.appendChild(background);
                                        div = document.createElement('div');
                                        document.body.appendChild(div);
                                        div.className = 'player';
                                        div.id = "play_video_popup";
                                        div.innerHTML = '<img src="'+root_url+'application/site/themes/default/img/loading.gif" alt="" />';
                                        ds = calcCenter(640, 480);
                                        div.style.left = ds[0]+'px';
                                        div.style.top = ds[1]+'px';
                                        background.className = "player_background";
                                        gs = alertSize();
                                        background.style.width = gs[0]+'px';
                                        background.style.height = gs[1]+'px';
                                        background.innerHTML = '&nbsp;';
                                        background.onclick = function()
                                        {
                                                background.parentNode.removeChild(background);
                                                div.parentNode.removeChild(div);
                                        }
                                }
                                current_video = albumvideos[i].fid;
                                  var ft = new FlashTag(gimg_dir+'player.swf'+'?flv='+root_url+image_dir+current_video+'&amp;width=640&amp;height=480&amp;autoplay=1&amp;margin=5&amp;bgcolor2=ffffff&amp;bgcolor1=ffffff&amp;showvolume=1&amp;showopen=0&amp;showfullscreen=1&amp;buffermessage=', 640, 480);
                                  ft.setParentNode(div.id);
                                  ft.setVersion("9,0,0,0");
                                  ft.write();
                                destroy = document.createElement('div');
                                destroy.className = "delete_player";
                                destroy.innerHTML = '<img src="'+root_url+'application/site/themes/default/img/delete.gif" alt="" />';
                                div.appendChild(destroy);
                                destroy.onclick = function()
                                {
                                        background.parentNode.removeChild(background);
                                        destroy.parentNode.parentNode.removeChild(destroy.parentNode);
                                }
                        }
                }
        }
}

function alertSize() 
{
        var myWidth = 0, myHeight = 0;
        myWidth = document.documentElement.scrollWidth;
        myHeight = document.documentElement.scrollHeight;
        return Array(myWidth, myHeight);
}

function calcCenter(w,h)
{
        var top = 0;
        var left = 0;
        top = (((screen.availHeight-168) - h) / 2) + document.documentElement.scrollTop;
        left = ((screen.availWidth - w) / 2) + document.documentElement.scrollLeft;
        return [left, top];
}
