var bigPhoto_tmp = null;
var bigPhoto_onload_div = null;
var bigPhoto_act = null;

function bigPhotoShowWindow() {
    if (bigPhoto_tmp) { clearInterval(bigPhoto_tmp); }
    if (bigPhoto_act) {
        var o = bigPhoto_act;
        bigPhoto_act = null;
    	newWindow = window.open('', o.title, 'width='+o.w+', height='+o.h+', location=no,menubar=no');
        if (newWindow) {
            newWindow.document.writeln(o.text);
     	    newWindow.document.close();
        }
        if (bigPhoto_onload_div) {
            document.body.removeChild(bigPhoto_onload_div);
            bigPhoto_onload_div = null;
	}
    } else {
        bigPhoto_tmp = setInterval(bigPhotoShowWindow, 40);
    }
}

function bigPhotoParent(params) {
    newWindow = window.open('', params.title, 'width='+params.w+', height='+params.h);
	if (newWindow) {
        newWindow.document.writeln(params.text);
	    newWindow.document.close();
	}
	if (bigPhoto_onload_div) {
		document.body.removeChild(bigPhoto_onload_div);
		bigPhoto_onload_div = null;
	}
}

function bigPhoto(indx, hght, wdth, img_tag, imgData) {
    var now = new Date();
    var IMG1 = getImgTagO(img_tag);
    img_tag.src = "#";
    var out_text = ['<html><head>',
                '<title>Национальная оборона / Фотохроника</title>',
                '<meta http-equiv="Content-Type" content="text/html; charset=windows-1251"/>',
                '<link href="/styles/photo_one.css" type="text/css" rel="stylesheet" />',
                '</head>',
                '<body>',
                '<div id="root">',
                '<div class="text">']
    if (imgData.name!='') { out_text.push('<div class="name">'+imgData.name+'</div>'); }
    if (imgData.desc!='') { out_text.push('<div class="desc"><span>Альбом: </span>'+imgData.desc+'</div>'); }
    if (imgData.source!='') { out_text.push('<div class="source"><span>Фото: </span>'+imgData.source+'</div>'); }
    if (imgData.place!='') { out_text.push('<div class="place"><span>Категория: </span>'+imgData.place+'</div>'); }
    if (imgData.date!='') { out_text.push('<div class="date"><span>Дата публикации: </span>'+imgData.date+'</div>'); }
    out_text.push('</div>');
    out_text.push('<div class="image" style="width:'+wdth+'px"><a href="javascript:;" onclick="window.close();return false;">'+IMG1+'</a></div>');
    out_text.push('</div></body></html>');
    out_html = out_text.join('\n');
    var out_script = '';
    out_script += '<script type="text/javascript">'+
                  'var out_text = "'+escape(out_html)+'";'+
                  'var wdth = '+wdth+';'+
                  'var hght = '+hght+';'+
                  'function start() {'+
                  '  var now = new Date();'+
                  '  window.parent.bigPhotoParent({title:now.getTime(),w:(wdth + 40+230),h:(hght+40),text:unescape(out_text)});'+
                  '}'+
                  'window.onload = start;'+
                  '</script>';
    bigPhoto_tmp = setInterval(bigPhotoShowWindow, 40);
    var fr = document.createElement('iframe');
    var fr_p = document.createElement('div');
    fr_p.style.width = '1px';
    fr_p.style.height = '1px';
    fr_p.style.overflow = 'hidden';
    fr.style.width = (wdth+40)+'px';
    fr_p.appendChild(fr);
    document.body.appendChild(fr_p);
    fr.contentWindow.document.writeln(out_script + out_html);
    fr.contentWindow.document.close();
}

function getImgTag(file, alt, hght, wdth, border) {
    return '<img src="' + file + '" border="' + border + '" alt="' + alt + '" height="' + hght + '"  width="' + wdth + '" />';
}

function getImgTagO(data) {
    return '<img src="' + data.src + '" border="' + data.border + '" alt="' + data.alt + '" height="' + data.h + '"  width="' + data.w + '" />';
}

function navigation_map(indx, hght, wdth, src) {
    now = new Date();
    newWindow = window.open('',now.getTime(),'width=' + wdth + ', height=' + hght);
    newWindow.location.replace(src);
}