var menu_array = Array(Array(Array("Windows","/games/"),
                             Array("Mac","/games/mac/"),
                             Array("Linux","/games/linux/"),
									  0,130,80),
                       Array(Array("Стрелялки","/online/shooters.shtml"),
							        Array("Классика","/online/classic.shtml"),
							        Array("Аркадные","/online/arcade.shtml"),
							        Array("Настольные","/online/board.shtml"),
							        Array("Карточные","/online/cards.shtml"),
							        Array("Логические","/online/puzzle.shtml"),
									  0,130,110),
                       Array(       Array("iPhone","/games/iphone/ibubbles/"),
                                    Array("Pocket","/games/pocket/"),
							        Array("Palm","/games/palm/"),
									  Array("Symbian","/games/symbian/"),
									  Array("Smartphone","/games/smartphone/"),
									  -5,130,105),
                       Array(0,0,0));
// caches all images used on each page
// images and highlighted captions for menu
var menu_cache_img = Array();
var menu_cache_img_on = Array();
menu_cache_img[1] = new Image();
menu_cache_img[1].src = "/i/but_mobile.gif";
menu_cache_img_on[1] = new Image();
menu_cache_img_on[1].src = "/i/but_mobile_on.gif";
menu_cache_img[2] = new Image();
menu_cache_img[2].src = "/i/but_online.gif";
menu_cache_img_on[2] = new Image();
menu_cache_img_on[2].src = "/i/but_online_on.gif";
menu_cache_img[3] = new Image();
menu_cache_img[3].src = "/i/but_games.gif";
menu_cache_img_on[3] = new Image();
menu_cache_img_on[3].src = "/i/but_games_on.gif";
menu_cache_img[4] = new Image();
menu_cache_img[4].src = "/i/but_support.gif";
menu_cache_img_on[4] = new Image();
menu_cache_img_on[4].src = "/i/but_support_on.gif";
// tabs for all platforms
var tab_cache_img = Array();
var tab_cache_img_on = Array();
tab_cache_img[1] = new Image();
tab_cache_img[1].src = "/i/tab_w.gif";
tab_cache_img_on[1] = new Image();
tab_cache_img_on[1].src = "/i/tab_w_on.gif";
tab_cache_img[2] = new Image();
tab_cache_img[2].src = "/i/tab_p.gif";
tab_cache_img_on[2] = new Image();
tab_cache_img_on[2].src = "/i/tab_p_on.gif";
tab_cache_img[3] = new Image();
tab_cache_img[3].src = "/i/tab_c.gif";
tab_cache_img_on[3] = new Image();
tab_cache_img_on[3].src = "/i/tab_c_on.gif";
tab_cache_img[4] = new Image();
tab_cache_img[4].src = "/i/tab_s.gif";
tab_cache_img_on[4] = new Image();
tab_cache_img_on[4].src = "/i/tab_s_on.gif";
tab_cache_img[5] = new Image();
tab_cache_img[5].src = "/i/tab_l.gif";
tab_cache_img_on[5] = new Image();
tab_cache_img_on[5].src = "/i/tab_l_on.gif";
// images for download link
var dld_cache_img = new Image();
dld_cache_img.src = "/i/b_down.gif";
var dld_cache_img_on = new Image();
dld_cache_img_on.src = "/i/b_down_on.gif";
// images for regiser link
var reg_cache_img = new Image();
reg_cache_img.src = "/i/b_reg.gif";
var reg_cache_img_on = new Image();
reg_cache_img_on.src = "/i/b_reg_on.gif";
var old_menu = "";
// images for subscription submit button
var sub_cache_img = new Image();
sub_cache_img.src = "/i/but_sub.gif";
var sub_cache_img_on = new Image();
sub_cache_img_on.src = "/i/but_sub_on.gif";
// retrieves browser type
var AgntUsr = navigator.userAgent.toLowerCase();
var NavYes = AgntUsr.indexOf('mozilla') != -1 && AgntUsr.indexOf('compatible') == -1 ? 1 : 0;
var ExpYes=AgntUsr.indexOf('msie') != -1 ? 1 : 0;
// if the browser supports the Document Object Model
var dom = (document.getElementById) ? true : false;
// if the browser is Internet Explorer 4
var ie4 = (document.all && !dom) ? true : false;

var old_menu_num = 0;
var old_caption = "";
var old_parent = "";

// sets the position of menu's image which is highlighted (caption)
function set_menu_caption_pos(caption,elemIdParent) {
	var posX = relPosX(elemIdParent);
	var posY = relPosY(elemIdParent);
	if (dom) {
		document.getElementById(caption).style.left = posX;
	} else if (ie4) {
		document.all[caption].style.left = posX;
	}
}
// sets the position of the menu in order of current active
// (highlighted) menu image
// elemId - id of menu
// elemIdParent - id of menu active image
// caption - id of image contains highlighted menu caption only
// offsetX - menu offset by X defined in the array (menu_def.js)
function setPosition(elemId,elemIdParent,caption,offsetX) {
	var posX = relPosX(elemIdParent);
	var posY = relPosY(elemIdParent);
	set_menu_caption_pos(caption,elemIdParent);
	if (dom) {
		document.getElementById(elemId).style.left = posX + offsetX + "px";
		document.getElementById(elemId).style.top = posY;
	} 	else if (ie4) {
		if (NavYes) {
			document.all[elemId].style.left = (posX - 415) * 1.8 + offsetX;
			document.all[elemId].style.top = posY;
		} else {
			document.all[elemId].style.left = posX + offsetX;
			document.all[elemId].style.top = posY;
		}
	}
}
// shows appropriate menu and highlighted image with menu caption
// for current menu item
function showElem(menu_num,elemIdParent,caption) {
   if (!menu_num)
       menu_num = old_menu_num;
   if (!caption)
       caption = old_caption;
   if (!elemIdParent)
       elemIdParent = old_parent;
   old_menu_num = menu_num;
   old_caption = caption;
   old_parent = elemIdParent;
   var offsetX = menu_array[menu_num-1][menu_array[menu_num-1].length-3];
	setPosition("menu",elemIdParent,caption,offsetX);
	if (dom) {
		document.getElementById("menu").style.visibility = "visible";
		document.getElementById(caption).style.visibility = "visible";
		old_menu = "menu";
	} else if (ie4) {
		if (old_menu && (old_menu != "menu"))
         document.all[old_menu].style.visibility = "hidden";
		document.all["menu"].style.visibility = "visible";
		document.all[caption].style.visibility = "visible";
		old_menu = "menu";
	}
}
// hides menu and highlighted image with menu caption
function hideElem(caption) {
   if (!caption)
      caption = old_caption;
	if (dom) {
		var elem = document.getElementById("menu");
		if (elem)
			elem.style.visibility = "hidden";
		var vcaption = document.getElementById(caption);
        if (vcaption)
            vcaption.style.visibility = "hidden";
   } else if (ie4) {
      document.all["menu"].style.visibility = "hidden";
		document.all[caption].style.visibility = "hidden";
   }
}
// returns the absolute X position of element (id) which is transfered
// as parameter
function relPosX(which) {
    	var elem = (dom) ? document.getElementById(which) : document.all[which];
    	var pos = elem.offsetLeft;
    	while (elem.offsetParent != null) {
      		elem = elem.offsetParent;
      		pos += elem.offsetLeft;
      		if (elem.tagName == 'BODY')
				   break;
    	}
		return pos;
}
// returns the absolute Y position of element (id) which is transfered
// as parameter
function relPosY(which) {
    	var elem = (dom) ? document.getElementById(which) : document.all[which];
    	var pos = elem.offsetTop;
    	while (elem.offsetParent != null) {
      		elem = elem.offsetParent;
      		pos += elem.offsetTop;
      		if (elem.tagName == 'BODY')
				   break;
    	}
		return pos;
}
// changes src for image "obj" (is id) image to "img_src"
function change_image(obj,img_src) {
	if (dom)
		document.getElementById(obj).src = img_src;
	else if (ie4)
		document.all[obj].src = img_src;
}
// writes "Enter your e-mail" into subscription field if no value was
// entered into this field after onBlur event happend
function check_subscribe() {
	var subs_field = (dom) ? document.getElementById("email") : document.all["email"];
	if (subs_field.value == "")
	   subs_field.value = "Enter your e-mail";
	else if (subs_field.value == "Enter your e-mail")
	   subs_field.value = "";
}
// fills menu by items in order of menu_num
// all menu items are defined in the menu_def.js file
function fill_popup(menu_num) {
    // retrieves menu objects by their ids
    if (dom) {
        var menu = document.getElementById("menu");
        var popup = document.getElementById("popup");
    } else {
        var menu = document.all["menu"];
        var popup = document.all["popup"];
    }
    // hides DIV block (id=="menu") which contains the table (id=="popup")
    menu.style.visibility = "hidden";
    // clears content of the table which describes menu content
    popup.innerHTML = "";
    // forms menu content for current highlighted menu item
    // menu_array defined in the menu_def.js file
    var HTML = '<table width="'+menu_array[menu_num-1][menu_array[menu_num-1].length-2]+'" height="10" cellspacing="0" cellpadding="0" bgcolor="#e2f8fe" class="popup"><tr><td width="1" bgcolor="#c9dde4"><img src="/i/sp.gif" width="1"></td><td colspan="2"><img src="/i/sp.gif" height="'+menu_array[menu_num-1][menu_array[menu_num-1].length-1]+'"></td><td width="1" bgcolor="#c9dde4"><img src="/i/sp.gif" width="1"></td></tr>';
    for (var i = 0; i < menu_array[menu_num-1].length-3; i++) {
        HTML += '<tr style="cursor: hand" onclick="document.location='+"'";
        HTML += menu_array[menu_num-1][i][1];
        HTML += "'";
        HTML += '" onmouseover="bgColor=';
        HTML += "'#a9dfe1'";
        HTML += '" onmouseout="bgColor=';
        HTML += "'#e2f8fe'";
        HTML += '"><td width="1" bgcolor="#c9dde4"><img src="/i/sp.gif" width="1"></td><td><img src="/i/bullet.gif" width="20" height="14"></td><td>';
        HTML += menu_array[menu_num-1][i][0];
        HTML += '</td><td width="1" bgcolor="#c9dde4"><img src="/i/sp.gif" width="1"></td></tr>';
    }
    popup.innerHTML = HTML + "</table>";
}
function jump() {
    if (dom) {
        var quick = document.getElementById("quick");
    } else {
        var quick = document.all["quick"];
    }
    if (quick.options[quick.selectedIndex].value) {
	    document.location = quick.options[quick.selectedIndex].value;
    }
}

