var ns = (navigator.userAgent.indexOf("MSIE") == -1)
var opera = (navigator.userAgent.indexOf("Opera") > -1)
var arrColors=new Array("004d7a","0074c5", "b57229", "006847");
var arrColorSchema=new Array(arrColors[0],arrColors[3],arrColors[0],arrColors[2],arrColors[3],arrColors[1],arrColors[0],arrColors[2],arrColors[0],arrColors[3],arrColors[3],arrColors[1],arrColors[2],arrColors[0],arrColors[2],arrColors[0],arrColors[3],arrColors[1],arrColors[0],arrColors[0],arrColors[3],arrColors[1],arrColors[2]);
var nColor=0;
var bBannerFlag = false

var g_nCount = -1;

var nTimeout = null;

function WriteString(str, r, d, f) {
strResult="";
if (nColor==arrColorSchema.length) nColor=0;
var strObj;
if (f) strObj=str.split(" ");
else strObj=str;
if (r==true) 	return "<font color='#"+ arrColorSchema[nColor++]+"'>"+str+"</font>";
var i=0;
while (i< strObj.length){
if (f) strResult += "<font color='#"+arrColorSchema[nColor++]+"'>"+strObj[i++]+"</font> ";
else if (str.charAt(i) != " ") strResult += "<font color='#"+arrColorSchema[nColor++]+"'>"+strObj.charAt(i++)+strObj.charAt(i++)+strObj.charAt(i++)+"</font>";
else strResult += strObj.charAt(i++);
if (nColor==arrColorSchema.length) nColor=0;
}
if (d != null) d.write(strResult);
else return strResult;
}

var arrA;
var arrShowImg = new Array(5);
var nImgRight = 0;
var nScrollImageCount = 0;
var nScrollVisibleImage = 0;
var nStartImg = 0;

var x=0;
var y=0;
var o=0;
var arr= new Array(5);
var arrX = new Array(5);

var nActiveMenu = -1;

function InitAllMenu(nCount) {
	if (ns && !opera) return;
	for(i=1;i<=nCount;i++) {
		var srcE = document.all["menu_head"][i - 1];
		arr[i-1]=document.all["menu_item"][i - 1];
		x=srcE.offsetLeft + getxy(srcE, 0) + 4;
		w=srcE.offsetWidth+2;
		y=6+getxy(srcE,1);
		y+=srcE.offsetTop+srcE.offsetHeight-4;
		arr[i-1].style.left=x-5;
		arr[i-1].style.top=y;
		arr[i-1].style.width=w;
		arrX[i - 1] = srcE.offsetLeft + srcE.offsetParent.offsetLeft;
	}
}

function SM(n) {
if (o != 0) arr[o - 1].style.display="none";
o=n;
arr[n-1].style.display="inline";
}

function HM(f){
if(o < 1) return;
if (f==1) {
	arr[o-1].style.display="none";
	o=0;
	return;
}
h=arr[o-1].offsetHeight;
w=arr[o-1].offsetWidth;
cY=event.clientY+document.body.scrollTop;
cX=event.clientX;
if (!(cY>(y-10) && cY<=(y+h) && cX>=arrX[o-1]+5 && cX<=arrX[o-1]+w-7)) {
arr[o-1].style.display="none";
o=0;
}
}

function SetRandom() {
	if (nTimeout != null) clearTimeout(nTimeout);
	if (nScrollVisibleImage < 1) return;
	if (nScrollImageCount<=nScrollVisibleImage) {
		if (nStartImg >= nScrollImageCount || bBannerFlag)  {
			nStartImg = 0;
			bBannerFlag = !bBannerFlag;
		}
		if (!bBannerFlag) {			
			document.all["img_tbl"].rows[0].cells[arrShowImg[nStartImg]].style.filter = "revealTrans(Transition=" + parseInt(Math.random() * 24)+ ", Duration=1.5)";
			document.all["img_tbl"].rows[0].cells[arrShowImg[nStartImg]].innerHTML="";
			ShowImg(arrShowImg[nStartImg], arrShowImg[nStartImg]);
			nStartImg++;
			nInterval = 1000; //10000;
		}
	} else {
		for(i=0;i<nScrollVisibleImage;i++) {
			n=nImgRight+1;
			if(n>nScrollImageCount-1) n=0;
			document.all["img_tbl"].rows[0].cells[i].style.filter = "revealTrans(Transition=" + parseInt(Math.random() * 24)+ ", Duration=1.5)";
			ShowImg(i,n);
			nImgRight=n;
		}
		bBannerFlag = !bBannerFlag;
		nInterval = nScrollVisibleImage*3000;
	}
	if (bBannerFlag) nInterval = 1;

	var divBanner = document.all["divBanner"]
	var div = document.all["divScr"]
	divBanner.style.display = bBannerFlag ? "inline": "none"
	div.style.display = bBannerFlag ? "none": "inline"

	nTimeout = setTimeout("SetRandom()", nInterval);
}

function SetImgCount(nCount) {
	nScrollImageCount=nCount;
	nScrollVisibleImage = (nCount > 5)? 5 : nCount;
	nImgRight=nScrollVisibleImage-1;
	InitScreen(nScrollVisibleImage);
	if (nScrollVisibleImage % 2 != 0) {
		arrShowImg[0] = parseInt((nScrollVisibleImage - 1) / 2);
		n = 1;
		nOffset = 1;
		for (i = 0;i < nScrollVisibleImage / 2; i++) {
			arrShowImg[n++] = arrShowImg[0] - nOffset;
			arrShowImg[n++] = arrShowImg[0] + nOffset;
			nOffset++;
		}
	} else {
		arrShowImg[0] = nScrollVisibleImage / 2 - 1;
		arrShowImg[1] = nScrollVisibleImage / 2;
		n = 2;
		nOffset = 1;
		for (i = 0;i < nScrollVisibleImage / 2; i++) {
			arrShowImg[n++] = arrShowImg[0] - nOffset;
			arrShowImg[n++] = arrShowImg[1] + nOffset;
			nOffset++;
		}
	}
}

function WriteImg() {
	if (nStartImg < nScrollVisibleImage) ShowImg(arrShowImg[nStartImg], arrShowImg[nStartImg]);
	if (nStartImg == nScrollVisibleImage) {
		SetRandom();
	} else setTimeout('WriteImg()', 2200);
	nStartImg++;
}

function ShowImg(n,n1) {
	table = document.all["img_tbl"];
	table.rows[0].cells[n].filters[0].apply();
	table.rows[0].cells[n].innerHTML=arrA[n1];
	table.rows[0].cells[n].filters[0].play();
}

function getxy(obj,nFlag) {
	nLocal = 0;
	if(obj.offsetParent) {
		nLocal=(nFlag==1)?obj.offsetParent.offsetTop:obj.offsetParent.offsetLeft;
		nLocal+=getxy(obj.offsetParent,nFlag);
	}
	return nLocal;
}

function InitScreen(nCount) {
	if (nCount < 1) return;
	g_nCount = nCount;
	var div = document.all["divScr"];
	strTableHTML = "<table border=0 id=img_tbl cellpadding=0 cellspacing=14><tr>"
	for (i = 0; i < nCount;i++)
		strTableHTML = strTableHTML + "<td width=63 height=69 style='filter:revealTrans(Transition="+parseInt(Math.random() * 24)+", Duration=1.5)'>&nbsp;</td>" //12
	strTableHTML = strTableHTML + "</tr></table>"
	div.innerHTML = strTableHTML;
	SetResolution(g_nCount);
}

function SetResolution(nCount) {
	if (nCount < 1) return;
	var div = document.all["divScr"];
	var table = document.all["img_tbl"];
	imgScreen = document.all["screen"];
	nX = imgScreen.offsetLeft + getxy(imgScreen, 0);
	nY = 50;
	div.style.top = nY;
	if (opera) nTableWidth = 63 * nCount + 14 * (nCount + 1);
	else nTableWidth = table.offsetWidth;
	div.style.left = nX + (imgScreen.offsetWidth - nTableWidth) / 2;
	var divBanner = document.all["divBanner"];
	divBanner.style.left = nX - 75
	divBanner.style.top = nY + 15
	divBanner.style.height = 90
	divBanner.style.width = 395
}

function DoResize() {
	InitAllMenu(5);
	SetResolution(g_nCount);
}

var dtCurrentDate=new Date();
var nCurrentYear=dtCurrentDate.getFullYear();
var arrAllowDays=new Array();
var arrMonthNames2=new Array("января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря");

function GetDaysInMonth(nYear, nMonth) {
var dtPrevDate=new Date(nYear, parseInt(nMonth)+1,0);
return dtPrevDate.getDate();
}


function GetCell(n, nYear, nMonth,f, type) {
strType = (type) ? "&type=" + type: "";
for(var i=0; i<arrAllowDays.length; i++)
if (n==arrAllowDays[i]) return "<a href='"+(f==1?"news.asp?":"jokes.asp?")+"d="+n+"&m="+nMonth+"&y="+nYear+strType+"'  style='text-decoration:underline'  title='Показать подборку " + (f==1?"новостей":"анекдотов")+" за "+n+" "+arrMonthNames2[nMonth]+"'>"+WriteString(n.toString(), true)+"</a>";
return "<font style='color:747463' disabled>"+n.toString()+"</font>";
}

function CreateCalendar(strMonth, d, f,ff, type) {
//if (ns) return;
arrAllowDays.length=0;
var arr = strMonth.split(",");
if (arr.length < 1) return;
if (opera && (f == null || f == -1)) {
if (!document.NextForm) return;
document.NextForm.m.value = arr[1];
document.NextForm.y.value = arr[0];
document.NextForm.submit();
return;
}
for (var i=2; i<arr.length; i++)
arrAllowDays[i-1]=arr[i];
strTopLine="";
strBottomLine="";
strLeftLine="";
strRightLine=""
nDays=GetDaysInMonth(arr[0], arr[1]);
nFirstLine=Math.floor((nDays-14) / 2)+((nDays-14) % 2)
nSecondLine=nDays-14-nFirstLine;
for (i=0; i<nFirstLine; i++)
strTopLine +="<td align=center width="+Math.round(100 / nFirstLine)+"%>"+GetCell(i +4, arr[0],arr[1],ff, type);
for (i=3; i >0; i--)
strLeftLine += "<tr><td align=center>"+GetCell(i, arr[0],arr[1],ff, type);
for (i=nDays; i >= (nFirstLine+nSecondLine+11); i--)
strLeftLine += "<tr><td align=center>"+GetCell(i, arr[0],arr[1],ff, type);
for (i=0; i <7; i++)
strRightLine +="<tr><td align=center>"+GetCell(i +4+nFirstLine, arr[0],arr[1],ff,type);
for (i=nSecondLine; i >0; i--)
strBottomLine += "<td align=center width="+Math.round(100 / nSecondLine)+"%>" +GetCell(i+3+nFirstLine +7, arr[0],arr[1],ff,type);
strTopLine="<table border=0 cellspacing=0 cellpadding=0 width=100% style='font-size:8pt;'><tr>"+strTopLine+"</table>";
strBottomLine="<table border=0 cellspacing=0 cellpadding=0 width=100% style='font-size:8pt;'><tr>"+strBottomLine+"</table>";
strLeftLine="<table border=0 cellspacing=0 cellpadding=0 width=100% height=100% style='font-size:8pt;'>"+strLeftLine+"</table>";
strRightLine="<table border=0 cellspacing=0 cellpadding=0 width=100% height=100% style='font-size:8pt;'>"+strRightLine+"</table>";
if( (d==null) && (f==0)) return strTopLine;
if( (d==null) && (f==1)) return strLeftLine;
if( (d==null) && (f==2)) return strRightLine;
if( (d==null) && (f==3)) return strBottomLine;
if (d==null) d=parent.document;
d.all["trTopLine"].innerHTML=strTopLine;
d.all["trBottomLine"].innerHTML=strBottomLine;
d.all["trLeftLine"].innerHTML=strLeftLine;
d.all["trRightLine"].innerHTML=strRightLine;
}

function FShow(id, nType) {
nWidth=(nType==2)?650:350;
w=window.open("show_img.asp?type=" + nType + "&id=" +id, null, "height=450,width="+nWidth+",menubar=no,toolbar=no,location=no,status=no,resizable=yes");
}

function ShowReview(id) {
w=window.open("review.asp?rrid="+id, null, "menubar=no,toolbar=no,location=no,status=no,resizable=yes,scrollbars=yes");
}

function doMouseOver(){
	oSource = event.srcElement;
	if (oSource.className != "clsMenu") return;
	oSource.style.color = "#004d7a";
}

function doMouseOut(){
	oSource = event.srcElement;
	if (oSource.className != "clsMenu") return;
	oSource.style.color = "#000000";
}

