var galleryWin = undefined;
var _imageURL = '';

var url_arr = location.href.split('/');
var	libPath = url_arr[0] + '/' + url_arr[1] + '/' + url_arr[2] + '/' + url_arr[3];

function makePopup( imageURL ) {
    _imageURL = imageURL;
	if ( typeof(galleryWin) == 'undefined'  ) {
        openPopup(_imageURL);
    } else {
        if ( galleryWin.closed ) {
            openPopup(_imageURL);
        } else {
            if ( _imageURL.indexOf('.jpg') != -1 || _imageURL.indexOf('.gif') != -1  ) {
                galleryWin.document.popupSRC.src = _imageURL;
                resizePopup();
            } else {
                openPopup();
            }
        }
    }
}

function openPopup() {
    galleryWin=window.open(_imageURL,"galleryWin","width=660,height=420,menubar=no,locationbar=no,statusbar=no,status=no,toolbar=no,scrollbars=no,resizable=yes");
	galleryWin.document.write('<html><title>Volkswagen - Galerie</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">'
			+'<param name="allowScriptAccess" value="always" />'
			+'<param name="movie" value="' + _imageURL + '" />'
			+'<param name="quality" value="high" />'
			+'<embed src="' + _imageURL + '" quality="high" name="popupSRC" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
			+'</object></div>');
	} else if ( _imageURL.indexOf('.mov') != -1 ) {
		galleryWin.document.write('<div style="margin:0px; text-align:center;"><object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" viewastext id="popupSRC">'
            +'<param name="src" value="' + _imageURL + '">'
            +'<param name="controller" value="true">'
            +'<param name="pluginspage" value="http://www.apple.com/quicktime/download/indext.html">'
            +'<embed controller="true" src="' + _imageURL + '" border="0" pluginspage="http://www.apple.com/quicktime/download/indext.html" name="popupSRC" LOOP="TRUE" AUTOPLAY="TRUE"></embed>'
            +'</object></div>');
 	} else {
		galleryWin.document.write('<div style="margin:0px; text-align:center;"><img name="popupSRC" src="' + _imageURL + '" border="0" alt="">');
    
    }
    
    galleryWin.document.write('<div style="margin:0px; margin-top:10px; text-align:right;"><a href="javascript:self.close();"><img name="closeBtn" src="' + libPath + '/etc/medialib/vwcms/virtualmaster/english_master/models/common/webspecial.Par.0003.Image.gif" border="0" alt="Close" width="58" height="15"></a></div>');
   
   galleryWin.document.write('</div></body>'
		+'</html>');
    
    resizePopup();
}
function resizePopup() {
    if ( _imageURL.indexOf('.jpg') != -1 || _imageURL.indexOf('.gif') != -1  ) {
        if ( typeof(galleryWin.document.popupSRC.width) != 'number' || galleryWin.document.popupSRC.width < 200 ) { 
            setTimeout("resizePopup()",1000);
        } else {
            width = galleryWin.document.popupSRC.width + 30;
            height = galleryWin.document.popupSRC.height + 95;
            if ( navigator.appName.indexOf('Netscape') != -1 ) {
                height += 38;
            }            
            galleryWin.resizeTo(width,height);
        }
	}
    galleryWin.focus();
}


