var galleryWin = undefined;
var _imageURL = '';


function makePopup( imageURL, width, height ) {
    //alert('make width ' + width +', height ' + height);
    var width = 800;
    var height = 600;
    setWidth(width);
    setHeight(height);
    
    _imageURL = imageURL;
    //alert(libPath + imageURL);
    openPopup();
}

function openPopup() {
	//alert('getWidth() ' + getWidth() +', getHeight() ' + getHeight());
    
    galleryWin=window.open("","galleryWin","width=" + (getWidth()+20) + ",height=" + (getHeight()+50) + ",menubar=no,locationbar=no,statusbar=no,status=no,toolbar=no,scrollbars=no,resizable=yes");
	
    galleryWin.document.open();
    
    galleryWin.document.write('<html><title>Volkswagen - Галерея</title>'
		+'<body style="margin:10px;">');
	if ( _imageURL.indexOf('.swf') != -1 ) {
		galleryWin.document.write('<div style="margin:0px; text-align:center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="popupSRC" align="middle" width="' + getWidth() + '" height="' + getHeight() + '">'
			+'<param name="allowScriptAccess" value="always" />'
			+'<param name="movie" value="' + _imageURL + '" />'
			+'<param name="quality" value="high" />'
			+'<embed src="' + _imageURL + '" width="' + getWidth() + '" height="' + getHeight() + ' quality="high" name="popupSRC" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
			+'</object>');
	} else if ( _imageURL.indexOf('.mov') != -1 ) {
    
        galleryWin.document.write('<div style="margin:0px; text-align:center;"><object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="' + getWidth() + '" height="' + getHeight() + '" codebase="http://www.apple.com/qtactivex/qtplugin.cab" viewastext id="popupSRC">'
            +'<param name="src" value="' + _imageURL + '">'
            +'<param name="controller" value="false">'
            +'<param name="target" value="myself">'
            +'<param name="bgcolor" value="#EAEFF5">'
            +'<param name="pluginspage" value="http://www.apple.com/quicktime/download/indext.html">'
            +'<embed width="' + getWidth() + '" height="' + getHeight() + '" controller="false" src="' + _imageURL + '" bgcolor="#EAEFF5" border="0" pluginspage="http://www.apple.com/quicktime/download/indext.html" name="popupSRC" LOOP="TRUE" AUTOPLAY="TRUE"></embed>'
            +'</object>');
    
 	} else {
		galleryWin.document.write('<div style="margin:0px; text-align:center;"><img name="popupSRC" src="' + _imageURL + '" border="0" alt="Fenster schliessen">');
    }
    
    galleryWin.document.write('<div style="margin:0px; margin-top:10px; text-align:right;"><a href="javascript:self.close();">Закрыть</a></div>');
    
    
    galleryWin.document.write('</div></body>'
		+'</html>');
    
    galleryWin.document.close();
    
    resizePopup();
    
    galleryWin.focus();
}

function resizePopup() {
    if ( galleryWin.document.popupSRC.width == 'undefined' || galleryWin.document.popupSRC.width < 25 ) {
        setTimeout("resizePopup()",1000);
    } else {
        width = new Number(galleryWin.document.popupSRC.width) + 30;
        height = new Number(galleryWin.document.popupSRC.height) + 82;
        if ( navigator.appName.indexOf('Netscape') != -1 ) {
            height += 38;
        }            
        galleryWin.resizeTo(width,height);
    }
}

function setWidth(width){
    if ( typeof(width) == 'undefined' ) {
        _width = 800;
    } else {
        _width = 800;
    }
}
function getWidth(){
    return _width;
}

function setHeight(height){
    if ( typeof(height) == 'undefined' ) {
        _height = 600;
    } else {
        _height = height;
    }
}
function getHeight(){
    return 600;;
}


