//v2.33
// --- HomePage
HomePageURL = 'http://itnews.com.ua/';
HomePageTxt = 'ITnews » Главная';
function setHomePage() {
	Try.these(
		function() { $('hpTest').setHomePage(HomePageURL) },
		function() { window.netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite"); navigator.preference("browser.startup.homepage", HomePageURL); },
		function() { window.sidebar.addPanel(HomePageTxt, HomePageURL, '') }
	);
}
// --- Ajax
function inputVerify(mode, objid, minlength) {
	this.obj = $(objid);
	this.mode = mode;
	this.minlength = minlength || 3;
	this.obj.setAttribute("autocomplete", "off");
	this.timeout = null;
	var iV = this;

	this.get_text = function() {
		this.fragment = new String(this.obj.value).strip();
	}

	this.key_event_handler = function(e) {
		this.get_text();
		clearTimeout(this.timeout);
		if (this.fragment.length >= this.minlength) this.timeout = setTimeout(this.name_verify.bind(this), 500);
	}

	this.name_verify = function() {
		var el = $('mess_err'), a = new Ajax({method: 'get'});

		function _verify_OK(tr) {
			var t = tr.responseText;
			if (el && (t != '')) {
				el.innerHTML = t;
				setShow(el);
			} else setHide(el);
		}
		function _verify_NO() { setHide(el); }

		if (!a.request("/inc/checkInput.cx", {
			parameters: 'mode=' + this.mode + '&input=' + encodeURIComponent(this.fragment) + '&rand=' + Math.random(),
			onSuccess: _verify_OK, onFailure: _verify_NO
		} )) return false;
		return true;
	}

	this.obj.onblur = function(e) { iV.get_text(); return iV.name_verify(); };
	this.obj.onkeyup = function(e) { return iV.key_event_handler(e); };
}

// --- Search
function initSearch() {
	var e=$('navbar_search');
	if (!e) return false;
	addEvent(e, "click", openSearch);
}
function openSearch(obj) {
	var e=$('navbar_search'), m=$('navbar_search_menu');
	if (!e || !m) return false;
	if (getStyle(m, 'display')!='none') return true;
	addEvent(document, "mousedown", closeSearch);
	var lt = getLT(e), wh = getWH(e), whm = getWH(m);
	m.style.top = (lt.t+wh.h) + 'px';
	m.style.left = (lt.l+wh.w-whm.w-2) + 'px';
	setShow(m);
}
function closeSearch(event) {
	var e = $(event.target || event.srcElement), e1 = $('navbar_search'), e2 = $('navbar_search_menu'), el;
	el = e; do { if (el == e1) return true; } while (el && (el = el.parentNode));
 	el = e; do { if (el == e2) return true; } while (el && (el = el.parentNode));
	setHide('navbar_search_menu');
	removeEvent(document, "mousedown", closeRoom);
}

// --- MyRoom
function startLoginOpenID(sbm) {
	removeEvent(document, "mousedown", closeRoom);
	$('div_room_openid').style.visibility = 'hidden';
	$('div_room_mess').style.display = '';
	$('i_openid_ret').value = window.location.href;
	var i = $('i_openid_ident').value, l = $('i_openid_login').value || '{ui}';
	$('i_openid_login').value = l.replace(/{ui}/, i);
	if (!sbm) $('openid_form').submit();
	return true;
}
function startLogin() {
	removeEvent(document, "mousedown", closeRoom);
	$('div_room_login').style.visibility = 'hidden';
	$('div_room_mess').style.display = '';
	$('i_ret').value = window.location.href;
	$('login_form').submit();
	return true;
}

var providers = {
	google: {
		title: "Google",
		url: 'https://www.google.com/accounts/o8/id'
	},
	mailru: {
		title: "Mail.Ru",
		label: 'Логин на Mail.Ru:',
		url: 'http://{ui}.id.mail.ru/'
	},
	rambler: {
		title: "Рамблер",
		url: 'http://rambler.ru'
	},
	lj: {
		title: "LiveJournal",
		label: 'Имя в Livejournal:',
		url: 'http://{ui}.livejournal.com/'
	},
	yandex: {
		title: "Яндекс",
		url: "http://openid.yandex.ru"
	},
	yahoo: {
		title: "Yahoo!",
		url: 'http://yahoo.com'
	},
	myopenid: {
		title: "myOpenID",
		url: 'https://myopenid.com'
	},
	flickr: {
		title: "Flickr",
		url: 'http://flickr.com'
	},
	wordpress: {
		title: "Wordpress",
		label: 'Логин на Wordpress:',
		url: 'http://{ui}.wordpress.com/'
	},
	technorati: {
		title: "Technorati",
		label: 'Логин в Technorati:',
		url: 'http://technorati.com/people/technorati/{ui}/'
	},
	claimid: {
		title: "ClaimID",
		label: 'ClaimID-идентификатор:',
		url: 'http://claimid.com/{ui}'
	},
	openid: {
		title: "OpenID",
		label: 'Адрес OpenID:'
	}
};
function initRoom() {
	var cnt = 0, htm = '';
	for (var id in providers) {
		if (cnt == 3) {
			htm += '<dt id="add_id"><span class="pseudo" onClick="openAddID()" title="Еще...">еще</span></dt>';
		}
		htm += '<dt '+((cnt>=3)?'style="display:none" ':'')+'id="'+id+'_id"><a class="ico_btn" href="javascript: Openid(\''+id+'\')" title="'+providers[id]["title"]+'"><b class="ico '+id+'"></b></a></dt>';
		cnt+=1;
	}
	$('openid_services').innerHTML = htm;
}
function openRoom(obj) {
	var e=$('div_room');
	if (!e) {
		obj.href="#";
		return false;
	}
	if (getStyle(e, 'display')!='none') return true;
	if ($('openid_services').getElementsByTagName('dt').length < 3) { initRoom(); }
	var lt = getLT('div_room_title');
	var wh = getWH('div_room_title');
	var who = getWH('div_room');
	e.style.top = (lt.t+wh.h) + 'px'; 
	e.style.left = (lt.l+wh.w-who.w) + 'px'; 
	setShow(e);
	addEvent(document, "mousedown", closeRoom);
}
function closeRoom(event) {
	var e = $(event.target || event.srcElement), e1 = $('div_room'), e2 = $('div_room_title'), el;
	el = e; do { if (el == e1) return true; } while (el && (el = el.parentNode));
 	el = e; do { if (el == e2) return true; } while (el && (el = el.parentNode));
	removeEvent(document, "mousedown", closeRoom);
	closeAddID();
	setHide('div_room');
}
function openAddID() {
	setTimeout(function() {
		var ar=$('openid_services').getElementsByTagName('dt');
		for(var i=0,l=ar.length;i<l;i++){
			(ar[i].id!='add_id')?setShow(ar[i]):setHide(ar[i]);
		}
	}, 300);
}
function closeAddID() {
	setHide('openid_url');
	var t=false, ar=$('openid_services').getElementsByTagName('dt');
	for(var i=0,l=ar.length;i<l;i++){
		t?setHide(ar[i]):setShow(ar[i]);
		if (ar[i].id=='add_id') { t=true; }
	}
}

function Openid(srv) {
	var t_label = '', t_url = '', el = $('openid_url');
	setHide(el);
	for (var id in providers) {
		if (id == srv) {
			if (typeof(providers[id]["label"]) != 'undefined') {
				t_label = providers[id]["label"];
			}
			if (typeof(providers[id]["url"]) != 'undefined') {
				t_url = providers[id]["url"];
			}
		}
        }

	$('i_openid_srv').value = srv;
	$('i_openid_ident').value = (srv == 'openid') ? 'http://' : '';
	$('i_openid_login').value = t_url;
	if (t_label != '') {
		el.getElementsByTagName('b')[0].className = 'ico ' + srv;
		el.getElementsByTagName('span')[0].innerHTML = t_label;
		setShow(el);
		setTimeout(function(){try{$('i_openid_ident').focus();}catch(e){}}, 100);
	}
	if (t_url && !/{ui}/.test(t_url)) startLoginOpenID();
}
function openLogin() {
	setHide('div_room_openid');
	setShow('div_room_login');
	setTimeout(function(){try{$('i_login').focus();}catch(e){}}, 100);
}
function closeLogin() {
	setHide('div_room_login');
	setShow('div_room_openid');
}

// --- ChoiceBar
function flyChoiceItem(en, eo, f) {
	var hn = parseFloat(en._c.style.height || 0), ho = eo ? parseFloat(eo._c.style.height || 0) : 0;
	
	if (f) {
		if (en == ChoiceItems[ChoiceItems.length-1]) hn -= 5;
		checkBottom();
	}
	if (ho == 0) {
		if (eo) { removeClassName(eo, "open"); removeClassName(eo._b, "open"); }
		checkBottom();
		en._c.style.height = en._c._h + "px";
	} else {
		ho -= 50; hn += 50;
		if ((ho < 0) || (hn > en._c._h)) { ho = 0; hn = en._c._h; }
		eo._c.style.height = ho + "px";
		en._c.style.height = hn + "px";
		setTimeout(function() { flyChoiceItem(en, eo, 0) }, 10);
	}
}

function setChoiceItem(e) {
	if (hasClassName(e, "open"))return;

	var eo = null;
	for (var i=0,l=ChoiceItems.length; i<l; i++) {
		if (hasClassName(ChoiceItems[i], "open")) eo = ChoiceItems[i];
	}

	e._c.style.height = "0px";
	addClassName(e, "open"); addClassName(e._b, "open");
	flyChoiceItem(e, eo, 1);
	setCookie('ci',e.id,null,'/');
}

function activateChoiceItem(event) {
	var e = $(event.target || event.srcElement);
	while (e.parentNode && (!hasClassName(e, "item"))) e = e.parentNode;
	if (hasClassName(e, "item")) {
		addEvent(document, "mousemove", deActivateChoiceItem);
		if (mTimerCB) { window.clearTimeout(mTimerCB); mTimerCB=null;};
		if (event.type=="click")setChoiceItem(e);
		else mTimerCB = window.setTimeout(function(){setChoiceItem(e)}, mTimerCBDelay);
	}
}

function deActivateChoiceItem(event) {
	var e = $(event.target || event.srcElement);
	while (e.parentNode && (!hasClassName(e, "item"))) e = e.parentNode;
	if (!hasClassName(e, "item")) {
		removeEvent(document, "mousemove", deActivateChoiceItem);
		if (mTimerCB) { window.clearTimeout(mTimerCB); mTimerCB=null;};
	}
}

function checkBottom() {
	var b = ChoiceItems[ChoiceItems.length-1];
	if (hasClassName(b, "open")) {
		b._end.style.display = '';
		removeClassName(b, "bottom");
	} else {
		b._end.style.display = 'none';
		addClassName(b, "bottom");
	}
}

// --- TopNews
function activateTN(event) {
	var e = $(event.target || event.srcElement);
	addEvent(document, "mousemove", deActivateTN);
	if (mTimerTN) window.clearTimeout(mTimerTN); mTimerTN=null;
	if (event.type=="click")setTN(e);
	else mTimerTN = window.setTimeout(function(){setTN(e)}, mTimerTNDelay);
}

function deActivateTN(event) {
	var e = $(event.target || event.srcElement);
	while (e.parentNode && (!hasClassName(e.parentNode, "nav"))) e = e.parentNode;
	if (!hasClassName(e.parentNode, "nav")) {
		removeEvent(document, "mousemove", deActivateTN);
		if (mTimerTN) { window.clearTimeout(mTimerTN); mTimerTN=null;};
	}
}

function flyTN(b,e,d) {
	mFlyTN = true;
	var w = parseFloat(e.style.width);
	if (d>0 && w>=210) {
		b.lastChild.parentNode.removeChild(b.lastChild);
		mFlyTN = false;
		return;
	}
	if (d<0 && w<=0) {
		b.firstChild.parentNode.removeChild(b.firstChild);
		mFlyTN = false;
		return;
	}
	e.style.width = (w+d)+'px';
	setTimeout(function() { flyTN(b,e,d) }, 10);
}

function setTN(e) {
	var ndx, b;
	if (!mFlyTN && (b = $('block_motion'))) {
		if (hasClassName(e, 'l')) {
			ndx=TN.pop();
			TN.unshift(ndx);
			addTN(TN[0], true, false);
		} else {
			ndx=TN.shift();
			TN[TN.length]=ndx;
			addTN(TN[cntTN-1], false, false);
		}
	}
	if (mTimerTN) window.clearTimeout(mTimerTN);
	mTimerTN = window.setTimeout(function(){setTN(e)}, mTimerTNDelay*4);
};
function addTN(item, first, init) {
	var b=$('block_motion'),e=document.createElement('li');
	var t='<div class="item"><img src="http://i.itnews.com.ua/n/' + item.i + '"><div><a href="/' + item.l + '.html">' + item.a.replace(/\-([^\s])/g,'-<i> </i>$1') + '</a></div></div>';
	if (b) {
		if (first) {
			e.style.width=0;
			b.insertBefore(e, b.firstChild);
			if (!init) flyTN(b,e,5);
		}
		else {
			e.style.width='210px';
			b.appendChild(e);
			if (!init) flyTN(b,b.firstChild,-5);
		}
		e.innerHTML = t;
	}
}

// --- SimilarNews
function flySN(b,e,d) {
	mFlySN = true;
	var w = parseFloat(e.style.width);
	if (d>0 && w>=230) {
		var LI = b.getElementsByTagName('li'), l_Child = LI[LI.length-1];
		l_Child.parentNode.removeChild(l_Child);
		mFlySN = false;
		return;
	}
	if (d<0 && w<=0) {
		var LI = b.getElementsByTagName('li'), f_Child = LI[0];
		f_Child.parentNode.removeChild(f_Child);
		mFlySN = false;
		return;
	}
	e.style.width = (w+d)+'px';
	setTimeout(function() { flySN(b,e,d) }, 10);
}
function activateSN(event) {
	var e = $(event.target || event.srcElement), b, LI, l=document.createElement('li');
	if (!mFlySN && (b = $('similar_motion'))) {
		LI = b.getElementsByTagName('li');
		if (hasClassName(e, 'l')) {
			l.innerHTML=LI[LI.length-1].innerHTML;
			l.style.width=0;
			b.insertBefore(l, LI[0]);
			flySN(b,l,5);
		} else {
			l.innerHTML=LI[0].innerHTML;
			l.style.width='230px';
			b.appendChild(l);
			flySN(b,LI[0],-5);
		}
	}
}

// --- Rating
function activateR(event) {
	var e = $(event.target || event.srcElement), r=$('rating'), s=r.getElementsByTagName('span')[0], b=r.getElementsByTagName('b')[0];
	addEvent(document, "mousemove", deActivateR);
	setHide(s);
	b.innerHTML=e.title;
	setShow(b);
}

function deActivateR(event) {
	var e = $(event.target || event.srcElement), r=$('rating'), s=r.getElementsByTagName('span')[0], b=r.getElementsByTagName('b')[0];
	while (e.parentNode && (e.id != "rating") && (!hasClassName(e, "descr"))) e = e.parentNode;
	if ((e.id != "rating") || (hasClassName(e, "descr"))) {
		removeEvent(document, "mousemove", deActivateR);
		setHide(b);
		setShow(s);
	}
}

function clickR(event) {
	var e = $(event.target || event.srcElement), r=$('rating');
	if (e._c != 'contests') e.href=e._href;

	try {

	removeClassName(r,'r\\d{2}');addClassName(r,'r'+e._v);
	if (e._c == 'contests' && e._a[0] == 'photo') {
		var c=getCookie('cp'+e._n)||'';
		if (c) c += ".";
		c += e._a[1] + '-' + e._v;
		var ipv = $('viewGalleryPreview_' + e._n + '-' + e._a[1]);
		if (ipv) {
			ipv.setAttribute('ratedone', e._v);
			ipv.setAttribute('ratecnt', ipv.getAttribute('ratecnt')+1);
		}
		setCookie('cp'+e._n,c,r.ce,'/','.itnews.com.ua');
	}
	var ar=r.getElementsByTagName('li');
	for(var i=0,l=ar.length-1;i<l;i++){
		removeEvent(ar[0], "mousemove", activateR);
		ar[0].parentNode.removeChild(ar[0]);
	}
	removeEvent(document, "mousemove", deActivateR);
	var a = new Ajax({method: 'post'});
	if (!a.request( '/inc/rate.cx', {parameters: e._href + '&rand=' + Math.random() } )) return false;
	stopEvent(event);
	}catch(e){}
	if (e._c == 'contests') return false;
	return true;
}

// -----------------------
// --- MainNews
var currentSelCatMainNews = 'all';
function setMainNews(obj, cat) {
	if (currentSelCatMainNews == cat) return false;
	var nl = $('news_list'), nb_cur = $('news_block_' + currentSelCatMainNews), nb_new = $('news_block_' + cat), nb_mask = $('news_block_mask');
	var obj_old = getElementsByClass(nl, 'active')[0];

	function _getH(obj) {
		var h = getWH(obj).h;
		if (h == 0) {
			var li = obj.getElementsByTagName('li');
			for (var i=0,l=li.length; i<l; i++) {
				var h_li = getWH(li[i]).h;
				if (h < h_li) h = h_li;
			}
		}
		return h;
	}
	var h_cur = _getH(nb_cur);

	function _swapTab(t1, t2) {
		removeClassName(t1, 'active');
		addClassName(t2, 'active');
	}
	function _swapBl(b1, b2) {
		setHide(b1);
		setShow(b2);
	}
	function _OK(tr) {
		nb_new.innerHTML = tr.responseText;
		_setData();
	}
	function _NO() {
		_swapTab(obj, obj_old);
		_swapBl(nb_mask, nb_cur);
	}
	function _setData() {
		var h_new = _getH(nb_new);
		if (h_new < h_cur) h_new = h_cur;
		nb_new.style.height = h_new + 'px';

		_swapBl(nb_mask, nb_new);
		currentSelCatMainNews = cat;
	}

	nb_mask.style.height = h_cur + 'px';
	_swapTab(obj_old, obj);
	_swapBl(nb_cur, nb_mask);

	if (!nb_new.innerHTML || nb_new.innerHTML == '') {
		var a = new Ajax({method: 'get'});
		if (!a.request('/inc/getMainNews.cx', {parameters: 'cat=' + cat, onSuccess: _OK, onFailure: _NO})) return false;
	} else _setData();
}

// -----------------------
// --- Mask
function createMask() {
	var m=$('imgViewMask');
	if (m)return m;
	var ViewMask = createElementWithStyle('div', 'imgViewMask', { zIndex: '999990', display: 'none', position: 'absolute', left: '0', top: '0', background: '#000000' }, '');
	ViewMask.className = 'mask';
	document.body.appendChild(ViewMask);
	addEvent(window, 'resize', resizeMask);
	return ViewMask;
}
function _resizeMask() {
	var ps = getPageSize();
	$('imgViewMask').style.width = ps.w + 'px';
	$('imgViewMask').style.height = ps.h + 'px';
}
function resizeMask() { setTimeout(_resizeMask,50); }
function hideObj() {
	function _sV(n) {n.style.visibility='hidden'};
	for(var e=document.getElementsByTagName('select'),l=e.length,i=0;i<l;i++){_sV(e[i])}
	for(var e=document.getElementsByTagName('iframe'),l=e.length,i=0;i<l;i++){_sV(e[i])}
	for(var e=document.getElementsByTagName('object'),l=e.length,i=0;i<l;i++){_sV(e[i])}
	for(var e=document.getElementsByTagName('embed'),l=e.length,i=0;i<l;i++){_sV(e[i])}
}
function reloadIframe() { showObj(true,true); }
function showObj(rld,fl) {
	function _sV(n) {n.style.visibility='visible'};
	var b = document.body, w = document.documentElement;
	var sl = window.scrollX? window.scrollX : w.scrollLeft ? w.scrollLeft : b.scrollLeft, st = window.scrollY ? window.scrollY : w.scrollTop ? w.scrollTop : b.scrollTop;
	var cw = (document.compatMode=='CSS1Compat' && !window.opera) ? w.clientWidth : b.clientWidth, ch = (document.compatMode=='CSS1Compat' && !window.opera) ? w.clientHeight : b.clientHeight;
	function _oP(n) {
		var dLT = getLT(n), dWH = getWH(n), x = dLT.l + dWH.w / 2, y = dLT.t + dWH.h / 2;
		return (((x >= sl + cw) || (x <= sl)) || ((y >= st + ch) || (y <= st)));
	};
	function _rL(n) {if(rld && !_oP(n))n.src=n.src};
	if (!fl) for(var e=document.getElementsByTagName('embed'),l=e.length,i=0;i<l;i++){_sV(e[i]);}
	if (!fl) for(var e=document.getElementsByTagName('object'),l=e.length,i=0;i<l;i++){_sV(e[i]);}
	for(var e=document.getElementsByTagName('iframe'),l=e.length,i=0;i<l;i++){_rL(e[i]);if(!fl)_sV(e[i]);}
	if (!fl) for(var e=document.getElementsByTagName('select'),l=e.length,i=0;i<l;i++){_sV(e[i]);}
}
// -----------------------
// --- IMG preview
var imgViewArray = new Array();
function create_imgView() {
	var ViewMask = createMask();
	var ViewBox=createElementWithStyle('div', 'imgViewBox', { zIndex: '999991', border: '1px solid #FFFFFF', display: 'none', position: 'absolute', left: '0', top: '0', backgroundColor: '#000000', padding: '4px', textAlign: 'center', verticalAlign: 'middle' }, '');
	ViewBox.className = 'bl_wait_big2';
	ViewBox.appendChild(createElementWithStyle('img', 'imgViewBoxImage', { zIndex: '999992' }, ''));
	ViewBox.appendChild(createElementWithStyle('div', 'imgViewBoxClose', { zIndex: '999993', border: '1px solid #FFFFFF', position: 'absolute', background: '#000000', padding: '0 6px', right: '4px', top: '-12px', cursor: 'pointer', font: 'bold 14px Arial', color: '#FFFFFF' }, 'x'));
	document.body.appendChild(ViewBox);

	addEvent(document, 'click', close_imgView);
	addEvent(ViewMask, 'click', close_imgView);
	addEvent(window, 'scroll', close_imgView);
	addEvent(window, 'keydown', close_imgView);
}
function open_imgView(event) {
	if (!$('imgViewBox')) create_imgView();
	setHide('imgViewBoxImage');
	var el = event.target || event.srcElement;
	while (!hasClassName(el,'imgPreView') && el.parentNode && (el = el.parentNode)){;}
//	while (el.src && el.parentNode && (el = el.parentNode) && !el.href){;}
	var activeImage = el.num;

	hideObj();
	resizeMask();
	setShow('imgViewMask');

	resize_imgView(250, 200);
	setShow('imgViewBox');

	var imgPreloader = new Image(), img = $('imgViewBoxImage');
	imgPreloader.onload = (function(){
		img.src = imgViewArray[activeImage][0];
		var ns = resize_imgView(imgPreloader.width, imgPreloader.height);
		img._w = imgPreloader.width;
		img._h = imgPreloader.height;
		img.style.width = ns.w + 'px';
		img.style.height = ns.h + 'px';
		setShow(img);
	});
	imgPreloader.src = imgViewArray[activeImage][0];
	addEvent(window, 'resize', resize_imgViewAll);
	return stopEvent(event);
}
function close_imgView(event) {
	if ((!$('imgViewBox')) || ($('imgViewBox').style.display == 'none'))return false;
	removeEvent(window, 'resize', resize_imgViewAll);
	setHide('imgViewBox');
	setHide('imgViewMask');
	showObj(true,false);
}
function resize_imgViewAll() { setTimeout(_resize_imgViewAll,100); }
function _resize_imgViewAll() {
	var img = $('imgViewBoxImage'), ns = resize_imgView(img._w, img._h);
	img.style.width = ns.w + 'px';
	img.style.height = ns.h + 'px';
}
function resize_imgView(w,h) {
	var e = $('imgViewBox');
	var ps = getPageSize();
	if ((w > ps.winw*.8) || (h > ps.winh*.8)) {
		var d = (h/w > ps.winh/ps.winw) ? ps.winh/h : ps.winw/w;
		w = d*w*.8;
		h = d*h*.8;
	}
	var l = (window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft) + (ps.winw-w)/2;
	var t = (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop) + (ps.winh-h)/2;

	e.style.left = parseInt(l) + 'px';
	e.style.top = parseInt(t) + 'px';
	e.style.width = parseInt(w) + 'px';
	e.style.height = parseInt(h) + 'px';
	return {w:w,h:h};
}


// --- init
function initHomePage() {
	var t = false, hpEl = $('hpTest');
	try {
		if (hpEl && hpEl.addBehavior) {
			hpEl.addBehavior('#default#homePage');
			if (hpEl.isHomePage(HomePageURL)) { t = true; }
		}
	}catch(e){}
	if (!t) { setShow('homepage'); }
}
function initChoiceBar() {
	if (!$('choicebar'))return;
	var ci = getElementsByClass('choicebar','item');
	maxH = 0;
	for (var i=0,b,c,h,l=ci.length; i<l; i++) {
		b = getElementsByClass(ci[i], "btn")[0]; ci[i]._b = b;
		c = getElementsByClass(ci[i], "content")[0]; ci[i]._c = c;
		h = getWH(c).h; ci[i]._h = h;
//		if (h > maxH) maxH = h;
		if (!maxH) maxH = h;
		ChoiceItems[ChoiceItems.length] = ci[i];
		addEvent(ci[i], "click", activateChoiceItem);
		addEvent(ci[i], "mousemove", activateChoiceItem);
	}
	var CIopen = getCookie('ci');
	for (var i=0,l=ChoiceItems.length; i<l; i++) {
		ChoiceItems[i]._c._h = maxH;
		if (CIopen && CIopen != null && CIopen == ChoiceItems[i].id) CIopen = ChoiceItems[i];
	}
	if (!CIopen || CIopen == null || typeof(CIopen)=='string') CIopen = ChoiceItems[0];
	addClassName(ChoiceItems[0], "top");

	var endItem = document.createElement('div');
	endItem.className = 'end';
	endItem.style.display = 'none';
	endItem.innerHTML = '<div class="l"></div><div class="r"></div>';
	$('choicebar').appendChild(endItem);
	ChoiceItems[ChoiceItems.length-1]._end = endItem;
	ChoiceItems[ChoiceItems.length-1]._c._h -= 5;

	setChoiceItem(CIopen);
}

function initTopNews() {
	var tl=TopNews.length,r=Math.floor(Math.random()*tl),b=$('block_motion'),cl,cr;
	for (var i=0; i<tl; i++) {
		while (TN.exists(r)) r=Math.floor(Math.random()*tl);
		TN[TN.length] = r;
	}
	for (var i=0,l=TN.length; i<l; i++) TN[i] = TopNews[TN[i]];
	if (b) b.innerHTML = '';
	for (var i=0; i<cntTN; i++) addTN(TN[i], false, true);

	cl = getElementsByClass('news_top','l')[0];
	addEvent(cl, "click", activateTN);
	addEvent(cl, "mousemove", activateTN);
	cr = getElementsByClass('news_top','r')[0];
	addEvent(cr, "click", activateTN);
	addEvent(cr, "mousemove", activateTN);
}

function initRating() {
	var ar,r=$('rating'),n=window.location.pathname.match(/\/([a-z]+)\/(\d+)/),v='',a=new Array();
	if (!r || !isArray(n) || n.length < 3)return;
	if (n[1] == 'contests') {
		var m = window.location.pathname.match(/([a-z]+)\.html/);
		if (isArray(m) && m.length > 1 && m[1] == 'photo') {
			var h = window.location.hash.match(/\d+-(\d+)/);
			if (isArray(h) && h.length > 1) {
				a[0] = m[1];
				a[1] = h[1];
			}
		}
	}

	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime() + 1000*60*60*24*3); // 3d
	r.ce = expires; // cookie expires

	ar=r.getElementsByTagName('a');
	for (var i=0,l=ar.length; i<l; i++) {
		addEvent(ar[i], "mousemove", activateR);
		v=ar[i].href.match(/(\d)/)[1];
		ar[i]._href = 'c=' + n[1] + '&n=' + n[2] + '&r=' + v + '&a=' + a[0] + "-" + a[1];
		ar[i]._c=n[1];
		ar[i]._n=n[2];
		ar[i]._v=v;
		ar[i]._a=a;
		addEvent(ar[i], "click", clickR);
	}
}

function initSimilarNews() {
	var ns = $('news_similar'), cl, cr;
	if (ns) {
		if ($('similar_motion').getElementsByTagName('li').length > 0) {
			cl = getElementsByClass(ns,'l')[0];
			cr = getElementsByClass(ns,'r')[0];
			if (cl) addEvent(cl, "click", activateSN);
			if (cr) addEvent(cr, "click", activateSN);
			setShow('similar');
		}
	}
}

function init_imgView() {
	var ar = getElementsByClass(document,'imgPreView'), l=ar.length;
	if (l==0) return;

	for(var i=0;i<l;i++){
		ar[i].num = imgViewArray.length;
		imgViewArray.push([ar[i].href, ar[i].title]);
		addEvent(ar[i], "click", open_imgView);
	}
}

/* init #menu_top Link */
function initMTLink() {
	return false;
	var a=$('menu_top').getElementsByTagName('a'),h=window.location.href;
	for (var i=1,l=a.length; i<l; i++) {
		if (h.indexOf(a[i].href) != -1){
			addClassName(a[i],"curr");
			return true;
		}
	}
	addClassName(a[0],"curr");
}

var ChoiceItems=[], TopNews=[], TN=[], cntTN=6;
var mFlyCB=false, mTimerCB=null, mTimerCBDelay=300;
var mFlyTN=false, mTimerTN=null, mTimerTNDelay=400;
var mFlySN=false;

function readyDOM() {
	if (readyDOM.done)return;
	readyDOM.done = true;
	for (var i=0,l=document.iFn.length; i<l; i++) {
		var f=document.iFn[i];
		if(typeof f == "function")try{f()}catch(e){}
	}
}
function addInit(f) {
	if (readyDOM.done){try{f()}catch(e){};return true;}
	if (!document.iFn)document.iFn=[];
	document.iFn.push(f);
}
function loadDOM() {
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", function(){
			document.removeEventListener("DOMContentLoaded", arguments.callee, false);
			readyDOM();
		}, false);
		window.addEventListener("load", readyDOM, false);
	} else if (document.attachEvent) {
		document.attachEvent("onreadystatechange", function(){
			if (document.readyState === "complete") {
				document.detachEvent("onreadystatechange", arguments.callee);
				readyDOM();
			}
		});
		if (document.documentElement.doScroll && window == window.top) (function(){
			if (readyDOM.done) return;
			try {
				document.documentElement.doScroll("left");
			} catch(error) {
				setTimeout(arguments.callee, 10);
				return;
			}
			readyDOM();
		})();
		window.attachEvent("onload", readyDOM);
	} else window.onload = readyDOM();
}
addInit(initSearch);
addInit(initMTLink);
addInit(initHomePage);
addInit(initTopNews);
addInit(initChoiceBar);
addInit(init_imgView)
addInit(initRating);
addInit(initSimilarNews);
loadDOM();
/* ==================================== */
function createElementWithStyle(t,n,s,h) {
	var e=(document.createElementNS)?document.createElementNS("http://www.w3.org/1999/xhtml", t):document.createElement(t);
	e.id = n;
	for (var i in s) { e.style[i] = s[i]; }
	if (h && h !='') {
		var c = document.createTextNode(h);
		e.appendChild(c);
	}
	return e;
}
function getPageSize() {
	var xS, yS;
	if (window.innerHeight && window.scrollMaxY) {
		xS = window.innerWidth + window.scrollMaxX;
		yS = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xS = document.body.scrollWidth;
		yS = document.body.scrollHeight;
	} else {
		xS = document.body.offsetWidth;
		yS = document.body.offsetHeight;
	}

	var wW, wH;
	if (document.documentElement && document.documentElement.clientHeight) {
		wW = document.documentElement.clientWidth;
		wH = document.documentElement.clientHeight;
	} else if (document.body) {
		wW = document.body.clientWidth;
		wH = document.body.clientHeight;
	} else if (window.innerHeight) {
		wW = window.innerWidth;
		wH = window.innerHeight;
	}

	var pWidth = (xS < wW) ? xS : wW;
	var pHeight = (yS < wH) ? wH : yS;
	return {w:pWidth,h:pHeight,winw:wW,winh:wH};
}

// 
/* ==================================== */
/* comments */
function _addEditorMask() {
	var maskWait = document.createElement('div'), lt = getLT('EditorForm'), wh = getWH('EditorForm');
	maskWait.style.background = '#F7F7F7 url("/images/wait.gif") center no-repeat';
	maskWait.style.position = 'absolute';
	maskWait.style.zIndex = '1000000';
	maskWait.style.left = (lt.l-2) + 'px';
	maskWait.style.top = (lt.t+2) + 'px';
	maskWait.style.width = (wh.w+4) + 'px';
	maskWait.style.height = (wh.h) + 'px';
	try { maskWait.style.display = 'table-cell'; } catch (e) {};
	maskWait.style.textAlign = 'center';
	maskWait.style.verticalAlign = 'middle';

	initEditor.maskWait = maskWait;
	document.body.appendChild(maskWait);
}
function _delEditorMask() {
	initEditor.maskWait.parentNode.removeChild(initEditor.maskWait);
}

function initEditor() {
	if (typeof(window.TextEditor) != 'undefined') {
		new window.TextEditor('editor', {
			default_document: "/inc/blank.htm",
			setupcontent_callback: _delEditorMask
		});
	} else {
		if (initEditor._cnt == 0) {
			_addEditorMask();
			var el = document.createElementNS ? document.createElementNS('http://www.w3.org/1999/xhtml', 'script') : document.createElement('script');
			el.language = 'javascript';
			el.type = 'text/javascript';
			el.src = '/i/js/editor.js';
			document.getElementsByTagName("head")[0].appendChild(el);
		}
		if (initEditor._cnt++ > 100) return;
		window.setTimeout(initEditor, 100);
	}
}
initEditor._cnt = 0;

function openTE(e) {
	while (e.parentNode && !hasClassName(e, "comment")) e = e.parentNode;
	if (hasClassName(e, "comment")) {
		var f = $('EditorForm');
		setShow(f);
		if (initEditor._cnt == 0) initEditor();
	}
	return false;
}

function addMess() {
	alert('add mess');
	return false;
}

