
		/*
		 * Copyright (c) 2006 Wazap AG, Germany -- all rights reserved.
		 */
		var cookieDomain = 'i.games.tom.com';
		var cookiename = 's_hide';
		var boxIds = 'cloud,coverslider,catalog,games,news,articles,cheats';
		var HIDEMASK_DEFAULT = 992;
		var HIDEMASK = HIDEMASK_DEFAULT;
		var HIDEMASK_ONLOAD = HIDEMASK_DEFAULT;
		var boxes = Array();
		initSwitcher();

		function initSwitcher() {
		 	if (cookiename != null) {
			  var ck = getCookie(cookiename);
			  if (ck != null && ck != '') {
					var ckint = parseInt(getCookie(cookiename));
					if (ckint != NaN) {
						HIDEMASK = ckint;
						HIDEMASK_ONLOAD = HIDEMASK;
					}
				}
			}
				addBox('cloud', '游戏互动', 0);
			
				addBox('coverslider', '热门游戏', 1);
			
				addBox('catalog', '游戏百科', 2);
			
				addBox('games', '热门游戏', 3);
			
				addBox('news', '游戏新闻', 4);
			
				addBox('articles', '其它信息', 5);
			
				addBox('cheats', '游戏攻略', 6);
			
		}

		// --- end init ---

		function Box (id, displayname, bit) {
		  this.id = id;
		  this.displayname = displayname;
		  this.bit = bit;
		  this.height = 0;
		}

		function addBox(id, displayname, bit) {
			var box = new Box(id, displayname, bit);
			if (boxes[id] == null) {
				boxes[id] = box;
				//alert('added: '+box.displayname);
			}
		}

		function isHidden(boxId, isloaded) {
			if (boxId != null && boxId != '') {
				var box = boxes[boxId];
				if (box != null) {
					var cmp = Math.pow(2, box.bit);
					var ck = (isloaded ? HIDEMASK_ONLOAD : HIDEMASK);
					return ((ck & cmp) == cmp);
				}
			}

			return false;
		}

		function isActive(boxId) {
			return !isHidden(boxId, false);
		}

		function isLoaded(boxId) {
			return !isHidden(boxId, true);
		}

		function toggle (boxId) {
			if (boxId != null && boxId != '') {
				var box = boxes[boxId];
				if (box != null) {
					var state = isActive(boxId);
					HIDEMASK ^= Math.pow(2, box.bit);
					updateCookie();
					if (isLoaded(boxId)) {
						toggleDisplay(boxId);
						updateInactiveLinks();
					}
					else
						window.location.reload();
				}
			}

		}

		function toggleDisplay (boxId) {
			var box = document.getElementById(boxId);
			if (box != null) {
				if (box.style.display == 'none')
					showLayer(boxId);
				else
					hideLayer(boxId);
			}
		}

		function updateCookie () {
			if (cookiename != null) {
				var expires = new Date();
				expires.setTime(expires.getTime()+(5*365*24*60*60*1000));
				if (getCookie(cookiename) && HIDEMASK == HIDEMASK_DEFAULT)
					delCookie(cookiename);
				else
					setCookie(cookiename, HIDEMASK, expires, "/", cookieDomain, false);
			}
		}

		function updateInactiveLinks () {
			var elem = null;
			var last = null;
			var count = 0;
			for (var id in boxes) {
				var box = boxes[id];
				elem = document.getElementById('show'+id);
				if (box != null && elem != null) {
					if ((HIDEMASK & Math.pow(2, box.bit)) == 0) {
						elem.style.display = 'none';
					} else {
						last = elem;
						elem.style.display = '';
						elem.style.padding = '0px 0.5em';
						elem.style.borderRight = '1px solid black';
						count++;
					}
				}
			}

			if (last != null) {
				last.style.paddingRight = '0px';
				last.style.borderRight = '0px';
			}

			var boxdiv = document.getElementById('switch');
			if (boxdiv != null) {
				if(document.getElementById('home_cnt') != null)
					boxdiv.style.visibility = (count>0 ? 'visible' : 'hidden');
				else
					boxdiv.style.display = (count>0 ? 'block' : 'none');

			}
		}

		function showOptions(root,e){
			hideAllOptions(e);
          	myOptions = document.getElementById(root.id + "_options");
          	if(myOptions)
            	myOptions.style.display="block";

        }


		function hideOptions(root,e){
        	myOptions = document.getElementById(root.id + "_options");
			if(myOptions)
				myOptions.style.display="none";
        }

		function hideAllOptions(e){
			for(i=0; i< boxes.length; i++){
				myOptions = document.getElementById(boxes[i].id + "_options");
				if(myOptions){
					myOptions.style.display="none";
				}
			}
        }

		function toggleOptions (root) {
			var elems = getElementsByClassName('opt', root);

			for (var i=0; i<elems.length; i++) {
				var ishidden = !(elems[i].style.display == 'block');
				//alert('test:'+elems[i].style.display);
				elems[i].style.display = (ishidden ? 'block' : 'none');
			}
		}

		function writeLinks () {
			for (var id in boxes) {
				var box = boxes[id];
				if (box != null) {
					document.write('<a id=\"show' + id + '\" href=\"javascript:toggle(\''+id+'\');\">' + box.displayname + '</a>');
				}
			}
		}

		// cookie functions
		function setCookie(name, value, expires, path, domain, secure) {
			if (domain == null)
				domain = cookieDomain;
		  var curCookie = name + "=" + escape(value) +
		      ((expires) ? "; expires=" + expires.toGMTString() : "") +
		      ((path) ? "; path=" + path : "") +
		      ((domain) ? "; domain=" + domain : "") +
		      ((secure) ? "; secure" : "");
		  document.cookie = curCookie;
		  // alert(curCookie);
		}

		function getCookie(name) {
		  var dc = document.cookie;
		  var prefix = name + "=";
		  var begin = dc.indexOf("; " + prefix);
		  if (begin == -1) {
		    begin = dc.indexOf(prefix);
		    if (begin != 0) return null;
		  } else
		    begin += 2;
		  var end = document.cookie.indexOf(";", begin);
		  if (end == -1)
		    end = dc.length;
		  return unescape(dc.substring(begin + prefix.length, end));
		}

		function delCookie(name) {
			if (getCookie(name)) {
				document.cookie = name + "=" +
				";path=/" +
				";domain=" + cookieDomain +
				";expires=Thu, 01-Jan-1970 00:00:01 GMT";
			}
		}

		