// detect browser ==============================================================
isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isOpera=isOpera5=window.opera && isDOM //Opera 5+
isOpera6=isOpera && window.print //Opera 6+
isOpera7=isOpera && document.readyState //Opera 7+
isMSIE=document.all && document.all.item && !isOpera //Microsoft Internet Explorer 4+
isMSIE5=isDOM && isMSIE //MSIE 5+
isNetscape4=document.layers //Netscape 4.*
isMozilla=isDOM && navigator.appName=="Netscape" //Mozilla или Netscape 6.*

// globals =====================================================================
sHints = "";
iMouseX = 0;
iMouseY = 0;

// Новости
iMinNewsCnt = 3;
iMaxNewsCnt = 10;

// Информеры
// digits delimiter "|"
sProjsInPortfolio = "2|0|5";	// проектов в портыолио
sProjsInWork = "1";		// проектов в работе
sCountFishes = "2|9";				// рыб в аквариуме



// mouse coords
if (isNetscape4) document.captureEvents(Event.MOUSEMOVE);
if (isMSIE || isOpera7) {
	document.onmousemove=function() {
		iMouseX=window.event.clientX + document.body.scrollLeft;
		iMouseY=window.event.clientY + document.body.scrollTop;
		return true;
	}
} else if(isOpera) {
	document.onmousemove=function() {
		iMouseX=window.event.clientX;
		iMouseY=window.event.clientY;
		return true;
	}
} else if (isNetscape4 || isMozilla) {
	document.onmousemove=function(e) {
		iMouseX = e.pageX;
		iMouseY = e.pageY;
		return true;
	}
}


// functions ==================================================================
function changeDivVisible(sDivId) {
	oDiv = document.getElementById(sDivId);
	if (oDiv) {
		oDiv.style.display = (oDiv.style.display != 'block'? oDiv.style.display = 'block': oDiv.style.display = 'none');
		oDiv.style.overflow = (oDiv.style.display != 'block'? 'hidden': 'visible');
	}
}

function  rerenderNews(iCountVis) {
	collNews = document.getElementsByTagName("div");
	var iCnt = 0;
	for (iI=0; iI<collNews.length; iI++) {
		oNextNew = collNews.item(iI);
		if (oNextNew.className == "news_dscs") {
			if (iCnt < iCountVis) {
				oNextNew.style.display = 'block';
				oNextNew.style.overflow = 'visible';
				iCnt++;
			} else {
				oNextNew.style.display = 'none';
				oNextNew.style.overflow = 'hidden';
			}
		}
	}
}

function changeProjectDesc(sProjId) {
	collProjDscs = document.getElementsByTagName("div");
	var bNewsExpanded = false;
	for (iI=0; iI<collProjDscs.length; iI++) {
		oNextProj = collProjDscs.item(iI);
		if (oNextProj.className == "proj_desc") {
			if (oNextProj.id == sProjId && oNextProj.style.display != 'block') {
				oNextProj.style.display = 'block';
				oNextProj.style.overflow = 'visible';
				bNewsExpanded = true;
			} else {
				oNextProj.style.display = 'none';
				oNextProj.style.overflow = 'hidden';
			}
		}
	}
	if (bNewsExpanded) {
		rerenderNews(iMaxNewsCnt);
	} else {
		rerenderNews(iMinNewsCnt);
	}
}

function writeRandImg(){
	var iRand = Math.round(Math.random() * 4);
	switch (iRand) {
		case 0 : this.document.write("<img src=\"/images/red_girl.jpg\" />"); break;
		case 1 : this.document.write("<img src=\"/images/boy_butterfly.jpg\" />"); break;
		case 2 : this.document.write("<img src=\"/images/child_flowers.jpg\" />"); break;
		case 3 : this.document.write("<img src=\"/images/storberry.jpg\" />"); break;
		case 4 : this.document.write("<img src=\"/images/tukan.jpg\" />"); break;
	}
}

function writeDot(sImgName, sWidth, sHeight, sPhrase) {
	//
	document.write('<img onmousemove="showHint(\''+sImgName+'\'); return true;" onmouseout="hideHint(\''+sImgName+'\'); return true;" src="/images/'+sImgName+'" alt="" width="'+sWidth+'" height="'+sHeight+'" />');
	sHints += '<div style="position: absolute; display: none;z-index:60" id="'+sImgName+'_hint"><table width="148"><tr><td class="bg_top"></td></tr><tr><td class="bg_cen" align="center" style="vertical-align:top">'+sPhrase+'</td></tr><tr><td class="bg_bot"></td></tr></table></div>';
}

function writeDigits(sDigits, sColor, sPhrase, iWidth) {
	var iWidth = (iWidth? iWidth: 148);
	var arrDigits = sDigits.split('|');
	document.write('<div onmousemove="showHint(\''+sDigits+'\'); return true;" onmouseout="hideHint(\''+sDigits+'\'); return true;">');
//	var iDigHeight = (sColor=='w') ? 16 : 15;
	var iDigHeight = 16;
	var iDigWidth = (sColor=='w') ? 11 : 10;

	for(iI=0; iI<(arrDigits.length); iI++){
		if (arrDigits[iI]=='3') iDigHeight=16;
		document.write('<img src="/images/'+arrDigits[iI]+'_'+sColor+'.png" alt="" width="'+iDigWidth+'" height="'+iDigHeight+'" class="png" />');
	}
	document.write('</div>');
	// create hint layer
	//sHints += '<div style="position: absolute; display: none;z-index:60" id="'+sDigits+'_hint"><table width="148"><tr><td class="bg_top_l"></td></tr><tr><td class="bg_cen" align="center" style="vertical-align:top; padding-top: 0px;">'+sPhrase+'</td></tr><tr><td class="bg_bot"></td></tr></table></div>'
	sHints += '<div style="position: absolute; display: none; z-index:1000;" id="'+sDigits+'_hint"><table width="'+iWidth+'"><tr><td class="bg_top"></td></tr><tr><td class="bg_cen" align="center" style="vertical-align:top">'+sPhrase+'</td></tr><tr><td class="bg_bot"></td></tr></table></div>';
}

function showHint(sDigits) {
	var oHint = document.getElementById(sDigits+'_hint');

	if (oHint) {
		oHint.style.left = iMouseX - 116 + 'px';
		oHint.style.top = iMouseY + 20 +'px';
		oHint.style.display = 'block';
	}
}

function hideHint(sDigits) {
	var oHint = document.getElementById(sDigits+'_hint');
	if (oHint) {
		oHint.style.display = 'none';
	}
}

var h = (typeof window.onload == "function") ? window.onload : function () {};

window.onload = function () { h(); rerenderNews(iMinNewsCnt); }


function popH(src, width, height, page_header) {
	if(!page_header)
		page_header = "Фоторепортаж с места событий";

	win = window.open("", "_blank", "width=" + (width) + ",height=" + (height) + ",titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
	win.document.write("<html><head><title>" + page_header + "</title></head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><table style='height: 100%' cellspacing='0' cellpadding='0' border='0'><tr><td valgin='middle'>");
	win.document.write("<" + "script" + ">\r\nfunction _CloseOnEsc() {if (event.keyCode == 27) { window.close(); return; }} document.onkeydown = _CloseOnEsc;<" + "/script>");
	win.document.write("<img src=\"" + src +  "\" onclick=\"javascript: window.close();\" style=\"cursor: pointer;\" />");
	win.document.write("</td></tr></table></body></html>");

	win.document.close();
	return false;
}


function popSwf(src,width,height,page_header) {
	if(!page_header)
		page_header = "Ф_'__п__'аж _ __'а __+<'ий";

	var codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0';
	var pluginspage = 'http://www.macromedia.com/go/getflashplayer';

	win = window.open("", "_blank", "width=" + (width) + ",height=" + (height) + ",titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
	win.document.write("<html><head><title>" + page_header + "</title></head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><table style='height: 100%' cellspacing='0' cellpadding='0' border='0'><tr><td valgin='middle'>");
	win.document.write("<" + "script" + ">\r\nfunction _CloseOnEsc() {if (event.keyCode == 27) { window.close(); return; }} document.onkeydown = _CloseOnEsc;<" + "/script>");


win.document.write("<object width='"+width+"' height='"+height+"' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' id='map_programmed' />"+
"<param name='_cx' value='13018' />"+
"<param name='_cy' value='7117' />"+
"<param name='FlashVars' />"+
"<param name='Movie' value='"+src+"' />"+
"<param name='Src' value='"+src+"' />"+
"<param name='WMode' value='Window' />"+
"<param name='Play' value='0' />"+
"<param name='Loop' value='-1' />"+
"<param name='Quality' value='High' />"+
"<param name='SAlign' />"+
"<param name='Menu' value='-1' />"+
"<param name='Base' />"+
"<param name='AllowScriptAccess' value='sameDomain' />"+
"<param name='Scale' value='ShowAll' />"+
"<param name='DeviceFont' value='0' />"+
"<param name='EmbedMovie' value='0' />"+
"<param name='BGColor' value='FFFFFF' />"+
"<param name='SWRemote' />"+
"<param name='MovieData' />"+
"<param name='SeamlessTabbing' value='1' />"+
"<param name='Profile' value='0' />"+
"<param name='ProfileAddress' />"+
"<param name='ProfilePort' value='0' />"+
"<embed width='"+width+"' height='"+height+"' src='"+src+"' quality='high' bgcolor='#ffffff' name='"+src+"' allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
"</object>");


	win.document.write("</td></tr></table></body></html>");

	win.document.close();
	return false;
}

function bgShadow(divId){
    var obj = document.getElementById(divId);
    if (obj)
    if (obj.style.display == 'none') {
      obj.style.display = 'block';
      obj.style.height = document.body.offsetHeight+'px';
    }else{
      obj.style.display = 'none';
    }
    return false;
  }
