function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function adjust_footer()
{
	var center = document.getElementById("middle");
	var right = document.getElementById("rightcolumn");
	var left = document.getElementById("leftcolumn");
	var center_height = center.offsetHeight + center.offsetTop;	
	var left_height = left.offsetHeight + left.offsetTop;	
	var right_height = 0;
	if (right)
	{
		right_height = right.offsetHeight + right.offsetTop;	
	}
	
	var max_height = left_height > center_height ? left_height : center_height;
	max_height = max_height > right_height ? max_height : right_height;
	document.getElementById("body").style.height= max_height;
}


current_lid = new Array();
layers_count = new Array();
time_changes = new Array();
tm = new Array();
blink_array = new Array();
blink_on = false;

debug_debug = false;


function add_time_change(name, n, t)
{
	if(!time_changes[name])
	{
		time_changes[name] = new Array();
	}
	
	time_changes[name][n] = t;
}

function init_layers_change(name, lc)
{
	current_lid[name] = 1;
	layers_count[name] = lc;
}

function init_auto_layer_change(name)
{
	if(layers_count[name] > 1 && time_changes[name])
	{
		if(debug_debug)
		{
			alert(name);
			alert(current_lid[name]);
			alert(time_changes[current_lid[name]]);
		}
		if(tm[name])
		{
			clearTimeout(tm[name]);	
		}
		tm[name] = setTimeout('next_layer("'+name+'")', time_changes[name][current_lid[name]]);
	}
}

function change_layers_src(lid, basename)
{
	var full_lid = basename + lid;
	
	var l_from = layer(full_lid);
	var l_to = layer(basename);

	l_to.write(l_from.read());
	
	l_to.object.className = l_from.object.className;
	
	adjust_footer();
}

function prev_layer(name)
{
	if(layers_count[name] > 1)
	{
		x = current_lid[name] - 1;
		if(x < 1)
		{
			x = layers_count[name];	
		}
		change_layers_src(x, name);
		current_lid[name] = x;
		init_auto_layer_change(name)
	}
	
	return false;
}

function next_layer(name)
{
	if(layers_count[name] > 1)
	{
		x = current_lid[name] + 1;
		if(x > layers_count[name])
		{
			x = 1;	
		}
		change_layers_src(x, name);
		current_lid[name] = x;
		init_auto_layer_change(name)
	}
	
	return false;
}

current_main_announce_lid = 1;
main_announce_layers_count = 0;

function prev_main_anno()
{
	if(main_announce_layers_count)
	{
		x = current_main_announce_lid - 1;
		if(x < 1)
		{
			x = main_announce_layers_count;	
		}
		change_layers_src(x, "main_announce");
		current_main_announce_lid = x;
	}
	
	return false;
}

function next_main_anno()
{
	if(main_announce_layers_count)
	{
		x = current_main_announce_lid + 1;
		if(x > main_announce_layers_count)
		{
			x = 1;	
		}
		change_layers_src(x, "main_announce");
		current_main_announce_lid = x;
	}
	
	return false;
}

function KImgShw(ID, width, height, alt)
{
	var scroll = "no";
	var top=0, left=0;
	if(width > screen.width-10 || height > screen.height-28) scroll = "yes";
	if(height < screen.height-28) top = Math.floor((screen.height - height)/2-14);
	if(width < screen.width-10) left = Math.floor((screen.width - width)/2-5);
	width = Math.min(width, screen.width-10);
	height = Math.min(height, screen.height-28);
	var wnd = window.open("","","scrollbars="+scroll+",resizable=yes,width="+width+",height="+height+",left="+left+",top="+top);
	wnd.document.write("<html><head>\n");
	wnd.document.write("<"+"script language='JavaScript'>\n");
	wnd.document.write("<!--\n");
	wnd.document.write("function KeyPress()\n");
	wnd.document.write("{\n");
	wnd.document.write("	if(window.event.keyCode == 27)\n");
	wnd.document.write("		window.close();\n");
	wnd.document.write("}\n");
	wnd.document.write("//-->\n");
	wnd.document.write("</"+"script>\n");
	wnd.document.write("<title>"+(alt == ""? "Image":alt)+"</title></head>\n");
	wnd.document.write("<body topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" onKeyPress=\"KeyPress()\">\n");
	wnd.document.write("<img src=\""+ID+"\" border=\"0\" alt=\""+alt+"\">");
	wnd.document.write("</body>");
	wnd.document.write("</html>");
	wnd.document.close();
}


// четвертый аргумент Scroll=yes|no
function OpenFile(url,width,height)
{
	var Left = (screen.width - width) / 2 - 5;
	var Top = (screen.height - height) / 2 - 29;
	var Scroll = typeof(arguments[3])=='undefined'?'no':arguments[3];
	shown=window.open(url,"","top="+Top+",left="+Left+",width="+width+",height="+height+",scrollbars="+Scroll+",status=no,resizable=yes,high");
	
	return false;
}

function blink_links()
{
	var i;
	var bid;
	for(i in blink_array)
	{
		bid = "online_game_" + i;
		l = layer(bid);
		if(blink_on)
		{
			l.css.color = '#FF0000';
		}
		else
		{
			l.css.color = '#FF6600';
		}
	}
	blink_on = !blink_on;
	tm['link_blinks'] = setTimeout('blink_links()', 1000);
}

function download_game(file, gamedir) { 
    var isIE = (window.navigator.userAgent.toUpperCase().indexOf('MSIE') != -1);
    var isOPERA = (window.navigator.userAgent.toUpperCase().indexOf('OPERA') != -1);   
    
    var dowurl = gamedir + 'download/';
    var dowfile = '/download/' + file + '?id=1660';

    if (isIE && !isOPERA)
    {
    	myDLWindow = window.open(dowfile,'_blank','toolbar=0,location=no,directories=0,status=0,scrollbars=no,resizable=0,width=0,height=0,top=0,left=0');
    	location.href = dowurl + '?aust=NO';
    }
    else
    {
    	location.href = dowurl;
    }
    return false;
}
function addBookmark(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;
  
  //Gecko
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  //IE4+
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  //Opera7+
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else 
  	return false;
  var href = location.href;
  var host = href.substr( 0, href.indexOf( '/', 9 ) );
  var link = host + "/bitrix/redirect.php?event1=addToFavorites&goto="
  location.href = link + location.href;
  
  return true;
}
function get_el(id) { return document.getElementById(id); }
function show(id) { get_el(id).style.display="block"; }
function hide(id) { get_el(id).style.display="none"; }


