var my_open = false;
function newwin(url, width, height, bgurl, top, left, scrollbars, resizable)
{
    if(width != undefined && width > 0 && height > 0)
    {
        var jetzt = new Date();
        var name = "win_" + jetzt.getTime();
        left = left != undefined ? left : 0;
        top = top != undefined ? top : 0;
        scrollbars = (scrollbars != undefined && scrollbars == 1) ? ",scrollbars=yes" : "";
        resizable = (resizable != undefined && resizable ==1) ? ",resizable=yes" : "";
        f = window.open(url, name, "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + scrollbars + resizable);
    }else{
        f = window.open(url);
    }
    if(bgurl != undefined && bgurl != "")
            location.href = bgurl;
    f.focus;
}
function videoplayer(div,video)
{
    if(my_open != undefined && my_open == true)
        return false;
    
    my_open = true;
    
    if($('changewebcontainer'))
    {
        $('changewebcontainer').remove();
    }
    var objBody = $$('body')[0];

    objBody.appendChild(Builder.node('div',{id:'overlay'}));	
    // var webcontainerid = tmp[1];
    new Ajax.Request('/Player/Videoplayer.php',
    {
        method: 'post',
        parameters: {video: video},        
        onSuccess: function(transport)
        {
            $(div).innerHTML += transport.responseText;	
	    var arrayPageScroll = document.viewport.getScrollOffsets();
	    var Top = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
	    var Left = arrayPageScroll[0];
	    $(div).setStyle({ top: Top + 'px', left: Left + 'px' }).show();
	    $('edit_container').observe('click', (function(event) { if (event.element().id == 'edit_container') closechange(div) }));	    
	    // stretch overlay to fill page and fade in
	    var arrayPageSize = getPageSize();
	    $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.6});
	    $('overlay').observe('click', (function() { closechange(div) }));
	    startPlayer(video);
	}
    }
    );
}

function startPlayer(video)
{
    var so = new SWFObject('/Player/player.swf','ply','600','360','9','#000000');
    so.addParam('allowfullscreen','true');
    so.addParam('allowscriptaccess','always');
    so.addParam('wmode','opaque');
    so.addVariable('file','/Player/'+video+'.flv');
    so.addVariable('autostart','true');
    so.addVariable('image','/Player/'+video+'.jpg');
    so.write('mediaspace');    
};

function getPageSize() {
		
	 var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

function closechange(div)
{
    my_open = false;
    if($('galeriedetail'))
	$('galeriedetail').remove();    
    if($('overlay'))
	$('overlay').remove();
    
    $(div).hide();
}

/*
i=0;
document.observe("dom:loaded", function()
{
  
}
);
*/
