
var baloontimeout=false;
var baloons=new Array();
var baloon_exclusive=false;
var curbaloon=false;
var curbaloon_to=false;


function showmost(id, fast) {
	for (var i=0;i<2;i++) if (i!=id) {
		$('most'+i).hide();
		$('most_link'+i).removeClassName('current');
	}

	if (!fast) Effect.SlideDown('most'+id);
	else $('most'+id).show();
	$('most_link'+id).addClassName('current');
	return false;
}


function adjust_topnews() {
	if ($('topnews').getHeight()>190 && $('topnews_link2')) $('topnews_link2').hide();
	if ($('topnews').getHeight()>190 && $('topnews_link1')) $('topnews_link1').hide();
}


function showBaloon(el, offsetX, offsetY, contentelement, canclose, width, height, pause) {
	if (el.id && curbaloon==el.id) {
		clearTimeout(curbaloon_to);
		return;
	} else {
	}
	if (isNaN(offsetX)) offsetX=-100;
	if (isNaN(offsetY)) offsetY=30;
	if (isNaN(width) && width!='auto') width=340;
	if (isNaN(height)) height='auto';
	if (baloon_exclusive && !canclose) return;

	if (canclose) {
		$('baloon_close').show();
		baloon_exclusive=true;
	} else {
		$('baloon_close').hide();
	}
	if ($('baloon').style.display!='none' || curbaloon!=el.id) realyhide();
	if (typeof(contentelement)=='string') $('baloon_content').innerHTML=contentelement;
	else if (typeof(contentelement)=='object' && contentelement.innerHTML) $('baloon_content').innerHTML=contentelement.innerHTML;

	if (baloontimeout) clearTimeout(baloontimeout);
	baloontimeout=false;

	$('baloon').style.width=width;
	$('baloon').style.height=height;

	if (typeof(el)=='object') {
		var tmpleft=(Position.cumulativeOffset(el)[0] + offsetX);
		var tmpright=(Position.cumulativeOffset(el)[1] + offsetY);
		$('baloon').style.left = tmpleft<0 ? 0 : tmpleft;
		$('baloon').style.top = tmpright<0 ? 0 : tmpright;
		if (el.id) curbaloon=el.id;
	} else {
		Position.prepare();
		var wh=$('baloon').getDimensions();
		var tmpleft=Math.round((document.body.clientWidth/2)-(wh.width/2)) + Position.deltaX + offsetX;
		var tmpright=Math.round((document.body.clientHeight/2)-(wh.height/2)) + Position.deltaY + offsetY;
		$('baloon').style.left = tmpleft<0 ? 0 : tmpleft;
		$('baloon').style.top = tmpright<0 ? 0 : tmpright;
	}

	setTimeout("$('baloon').show()", pause!=null ? pause : 500);
}

function hideBaloon(pause) {
	//$('debug').innerHTML=$('debug').innerHTML+'hide, ';
	if (!baloon_exclusive) {
		if (pause==0) realyhide();
		else curbaloon_to=setTimeout("realyhide()", pause!=null ? pause : 500);
		//$('baloon').hide();
		//$('baloon_content').innerHTML='';
		//curbaloon=false;
	}
}

function realyhide() {
	baloon_exclusive=false;
	clearTimeout(curbaloon_to);
	$('baloon').hide();
	//$('baloon_content').innerHTML='';
	curbaloon=false;
	curbaloon_to=false;
}

function llog(msg, clear) {
	if (!$('debug')) return;
	if (clear) $('debug').innerHTML='Debug: '+msg;
	else $('debug').innerHTML+=msg+'<br>';
}

var calendar=new Array();
var calendar_distance=295;
var calendar_url='/includes/calendar.php';

function calendar_updatelinks(year, mon) {
	if (calendar[''+year+mon]) cur=calendar[''+year+mon]; else cur=calendar[calendar.length-1];

	//alert(cur.curtitle);
	if (cur.prevtitle) $('calendar_prevmonth').innerHTML='<a href="#" onclick="return calendar_move(\''+cur.prevyear+'\', \''+cur.prevmonth+'\', 1);" title="'+cur.prevtitle+'"><img src="/img/back.gif" width=6 height=9></a>';
	else $('calendar_prevmonth').innerHTML='&nbsp;';
	if (cur.nexttitle) $('calendar_nextmonth').innerHTML='<a href="#" onclick="return calendar_move(\''+cur.nextyear+'\', \''+cur.nextmonth+'\', -1);" title="'+cur.nexttitle+'"><img src="/img/forward.gif" width=6 height=9></a>';
	else $('calendar_nextmonth').innerHTML='&nbsp;';
	$('calendar_curmonth').innerHTML=cur.curtitle;
}


function calendar_move(year, mon, direction) {
	if (Effect.Queues.get('calendar').size()>0) return;
	if (!direction) direction=1;
	if (!calendar[''+year+mon]) getcalendar(year, mon, direction);
	else {
		//		if (direction>0) $('calendar').innerHTML=calendar[''+year+mon].calendar+$('calendar').innerHTML;
		//		else $('calendar').innerHTML+=calendar[''+year+mon].calendar
		calendar_updatelinks(year, mon);
		new Effect.Move('calendar', { x: direction*calendar_distance, mode: 'relative', queue: { scope: 'calendar' }});
	}
	return false;
}

function getcalendar(year, mon, direction) {
	if (!direction) direction=1;

	new Ajax.Request(calendar_url+'?year='+year+'&month='+mon+'&json=1', {
		onSuccess: function(transport) {
			calendar[''+year+mon]=transport.responseText.evalJSON();

			if (direction>0) {
				$('calendar').innerHTML=calendar[''+year+mon].calendar+$('calendar').innerHTML;
				$('calendar').style.left=-calendar_distance;
			} else $('calendar').innerHTML+=calendar[''+year+mon].calendar

			new Effect.Move('calendar', { x: direction*calendar_distance, mode: 'relative', queue: { scope: 'calendar' }});
			calendar_updatelinks(year, mon);

		}
	});

}


var tnews_timeout=10000;
var tnews_distance=272+70;
var curidx=0;
var tnews_lastsize=0;
var tnews_timer;

function forward_tnews() {
	clearTimeout(tnews_timer);
	switch_tnews(1);
	if (pp_btn.hasClassName('pause'))
	tnews_timer=setTimeout('forward_tnews()',tnews_timeout);
	return false;
}
function backward_tnews() {
	clearTimeout(tnews_timer);
	switch_tnews(-1);
	if (pp_btn.hasClassName('pause'))
	tnews_timer=setTimeout('forward_tnews()',tnews_timeout);
	return false;
}
function toggle_play_pause_tnews() {
	clearTimeout(tnews_timer);
	if (pp_btn.hasClassName('pause')) {
		pp_btn.down().title='play';
	} else {
		tnews_timer=setTimeout('forward_tnews()',tnews_timeout);
		pp_btn.down().title='pause';
	}
	pp_btn.toggleClassName('play');
	pp_btn.toggleClassName('pause');
	return false;
}

function switch_tnews(dir) {
	if (tnews_divs.length<2) {
		var d=$$('div.excl_scroll');
		if (d[0]) d[0].hide();
		return;
	}
	var newidx=0;
	if (dir>0) {
		newidx = curidx==tnews_divs.length-1 ? 0 : curidx+1;
		if (curidx==tnews_divs.length-1) $('excl_scroll_conent').style.left=tnews_distance;
		new Effect.Move('excl_scroll_conent', { x: -tnews_distance, mode: 'relative', queue: { scope: 'tnews', limit: 1 }});
	} else {
		newidx = curidx==0 ? tnews_divs.length-1 : curidx-1;
		if (curidx==0) $('excl_scroll_conent').style.left=-(tnews_divs.length)*tnews_distance;
		new Effect.Move('excl_scroll_conent', { x: tnews_distance, mode: 'relative', queue: { scope: 'tnews', limit: 1 }});
	}

	curidx=newidx;
}

function tnews_resize() {
	if (typeof(tnews_divs) == "undefined") return;
	if (tnews_divs.length<2) {
		var d=$$('div.excl_scroll');
		if (d[0]) d[0].hide();
	}
	if (!$('excl_scroll_probnik')) return;
	var queue=Effect.Queue;
	queue.each(function(effect) { effect.cancel(); });

	clearTimeout(tnews_timer);
	if (typeof(tnews_moving) === 'undefined' || tnews_moving=='1') tnews_timer=setTimeout('forward_tnews()',tnews_timeout);

	var width=$('width_checker').getWidth();
	if (!tnews_lastsize) {
		width=$('excl_scroll_probnik').getWidth()+26;
		tnews_lastsize=width;
	}
	$('excl_scroll_container').style.width=width-26;

	for(i=0;i<tnews_divs.length;i++) {
		tnews_divs[i].style.width=width-26;
	}

	tnews_distance=width-26+70;
	$('excl_scroll_conent').style.left=-curidx*tnews_distance;
}


var expanded_sector=false;
var main_sector=0;
var expanded_expire = 60*60*24*365;	// seconds
//var expanded_expire = 60;

function company_toggle(id) {

	if ($('company_div'+id).className=='expand2') {
		//	развернутая => сворачиваем
		new Effect.SlideUp('ref_sector'+id);
		$('company_div'+id).className='expand1';
		if (expanded_sector && expanded_sector==id) expanded_sector=false;
		expanded_sectors=expanded_sectors.without(id);
		if (expanded_sector) expanded_sectors=expanded_sectors.without(expanded_sector);
	} else {
		//	свёрнутая => разворачиваем и сворачиваем ту, которую разворачивали до этого...
		if (expanded_sector) {
			$('company_div'+expanded_sector).className='expand1';
			expanded_sectors=expanded_sectors.without(expanded_sector);
			new Effect.Parallel([
			new Effect.SlideUp($('ref_sector'+expanded_sector), { sync: true }),
			new Effect.SlideDown('ref_sector'+id, { sync: true })
			]);
		} else {
			Effect.SlideDown('ref_sector'+id);
		}
		expanded_sectors[expanded_sectors.length]=id;
		expanded_sector=id;
		$('company_div'+id).className='expand2';
	}
	save_expanded();
}

function save_expanded(main) {
	var ret='-';
	//	alert('test');
	for (var i=0;i<expanded_sectors.length;i++) ret+=expanded_sectors[i]+'-';

	if (main) main_sector=main;
	var cookie='main_'+main_sector+ret;
	//	Set_Cookie('companies_expand', cookie, expanded_expire, '/companies/');
	Set_Cookie('companies_expand',cookie,expanded_expire,'/');
	Set_Cookie('sector_id',main_sector,expanded_expire,'/');
	//	alert('set: '+main);
}

function set_my_branch(id,nocookie) {
	if (!id) {
		var sel=$('baloon').down('select');
		for (var i=0;i<sel.length;i++) {
			if (sel[i].selected) {
				id=sel[i].value;
				title=sel[i].innerHTML;
				break;
			}
		}
		baloon_exclusive=false; hideBaloon();
	} else {
		var sel=$('company_main_select');
		for (var i=0;i<sel.length;i++) {
			if (sel[i].value==id) {
				title=sel[i].innerHTML;
				break;
			}
		}
	}
	if (id && id!=0) {
		$('branch_choice_text').update(title);
		$($('branch_choice_text').parentNode).hide();
		//		$('company_div'+id).className='expand2';
		$('company_div'+id).hide();
		$('ref_sector'+id).show();
		$('my_branch_selected').show().innerHTML=$('sector_source'+id).innerHTML;
		$('sector_source'+id).innerHTML='';
		//		console.log(id);
		main_sector=id;
	}
	if (!nocookie) {
		save_expanded(id);
	}
}

function set_fp_branch() {
	var id=0;
	var sel=$('baloon').down('select');
	for (var i=0;i<sel.length;i++) {
		if (sel[i].selected) {
			id=sel[i].value;
			title=sel[i].innerHTML;
			break;
		}
	}
	baloon_exclusive=false; hideBaloon();

	if (id && id!=0) {
		new Ajax.Request('/newspaper/include/get_sector_articles.shtml?'+id, {
			method: 'get',
			onSuccess: function(transport) {
				Set_Cookie('companies_expand','main_'+id+'-0-1-2-16-26-5-',expanded_expire,'/');
				//				alert('main_'+id+'-0-1-2-16-26-5-');
				Set_Cookie('sector_id',id,expanded_expire,'/');
				//				alert(id);
				text=transport.responseText;
				if (text.match(/^[\s\r\n]+$/)) {
					text='<b>Статей в данной отрасли не найдено</b>';
				}
				$('fp_sector_articles').update(text);
			}
		});

	}
}

function set_my_vac_branch(id) {
	if (!id) {
		var sel=$('baloon').down('select');
		for (var i=0;i<sel.length;i++) {
			if (sel[i].selected) {
				id=sel[i].value;
				title=sel[i].innerHTML;
				break;
			}
		}
		baloon_exclusive=false; hideBaloon();
	} else {
		var sel=$('company_main_select');
		for (var i=0;i<sel.length;i++) {
			if (sel[i].value==id) {
				title=sel[i].innerHTML;
				break;
			}
		}
	}
	if (id && id!=0) {
		new Ajax.Request('/includes/dynamic/vacancies/branches/'+id+'.shtml', {
			method: 'get',
			onSuccess: function(transport) {
				Set_Cookie('my_vac_branch', id, expanded_expire, '/career/');
				$('branch_choice_text').update(title);
				text=transport.responseText;
				if (text.match(/^[\s\r\n]+$/)) {
					text='<li>У нас пока нет вакансий в этой специализации</li>';
				}
				$('vacancy_selected').update('<div class="plashka_red">'+title+'<span class="gt">&nbsp;&nbsp;&nbsp;</span></div><div class=career_vacan><ul>'+text+'</ul><div class="all_news"><a href="http://career.vedomosti.ru/vacancies/all.shtml"><span>все вакансии</span></a></div>');
				$('edu_div').hide();
			}
		});
	}
}







function sector_toggle(id) {

	if ($('sector_div'+id).className=='expand2') {
		//	развернутая => сворачиваем
		new Effect.SlideUp('ref_sector'+id);
		$('sector_div'+id).className='expand1';
	} else {
		//	свёрнутая => разворачиваем и сворачиваем ту, которую разворачивали до этого...
		Effect.SlideDown('ref_sector'+id);
		$('sector_div'+id).className='expand2';
	}
}




function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		//expires = expires * 1000 * 60 * 60 * 24;
		expires = expires * 1000;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function copyCB()
{
	var txt = $('txt');
	Copied = txt.createTextRange();
	Copied.execCommand("Copy");
}

function twitter(url, text)
{
  window.my_callback = function(response)
  {
    if(response.error_message) window.open('http://twitter.com/home/?status='+encodeURIComponent(text)+' '+url,this.target)
    else window.open('http://twitter.com/home/?status='+encodeURIComponent(text)+' '+response.short_url,this.target)
  };
  var s = document.createElement("script");
  s.src = "http://ggl-shortener.appspot.com/?url=" + encodeURIComponent(url) + "&jsonp=my_callback";
  document.body.appendChild(s);
  
  return false;
}

function facebook(url, text) {
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(text),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function vkontakte(url, text) {
	window.open('http://vkontakte.ru/share.php?url='+encodeURIComponent(url)+'&title='+encodeURIComponent(text)+'&image=http://www.vedomosti.ru/img/ved_logo3.gif','sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}





/* css_browser_selector.js */

function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);


/* pngfix.js */
function fixPNG(element) {if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
var src;
if (element.tagName=='IMG') {
        if (/\.png$/.test(element.src)) {
    src = element.src;
    element.src = "/img/px.gif"; }
        }
else {
        src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
        if (src) {
    src = src[1];
    element.runtimeStyle.backgroundImage="none";}
        }
if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')"; } }








/********** Adriver AsyncJS loader V1.1 *************/

function adriver (ph, prm, defer) {  
	try {
		this.ph = ph; 
		this.prm = {};
		for (var i in this.defaults) this.prm[i] = this.defaults[i];
		for (var i in prm) this.prm[i] = prm[i];
		for (var i in this.prm) this.req += i + "=" + this.prm[i] + "&";
		if(!adriver.items){ 
			adriver.items = {};
			this.addHandlers();
			this.checkFlash();
		}
		this.p = document.getElementById(ph);
		this.p.adriver = this;
		adriver.items[ph] = this;
		defer || this.load(); 
	}catch(e){}
}

adriver.prototype.ver = "1.1";
adriver.prototype.flashVer = [0];
adriver.prototype.domReady = false;
adriver.prototype.handlers = [];
adriver.prototype.defaults = {};
adriver.prototype.h = document.getElementsByTagName("head").item(0);
adriver.prototype.req = "http://ad.adriver.ru/cgi-bin/erle.cgi?";

		
adriver.prototype.loadScript = function(req, m){ //m - flag. set when loading from mirror
try {
		m || (req += "ph=" + this.ph + "&rnd=" + Math.round(Math.random()*10000));
		var s = document.createElement("script");
		s.setAttribute("type", "text/javascript");
		s.setAttribute("charset", "windows-1251");
		s.setAttribute("src", req);
		this.s = s;
		this.h.insertBefore(s, this.h.firstChild); 
	}catch(e){}
}

adriver.prototype.detachScript = function (){ try{ this.h.removeChild(this.s) }catch(e){}}

adriver.prototype.load = function (){	try{ this.loadScript(this.req) }catch(e){}}

adriver.prototype.onDomReady = function (f) {try{ this.domReady ? f() : this.handlers.push(f) }catch(e){}}


/************ dom ready state check **********************/

adriver.prototype.runHandlers = function(old_handler){
	try {
		if (old_handler){old_handler() }
		if (!this.domReady){
			adriver.prototype.domReady = true;
			var f; while (f = this.handlers.shift()) f();
		}
	}catch(e){}
}

adriver.prototype.addHandlers = function(){
	try {
		var d = document, t = this, safariTimeout;

		if (/WebKit/i.test(navigator.userAgent)) {
			safariTimeout = setInterval(function(){if (/loaded|complete/.test(d.readyState)) {clearInterval(safariTimeout); t.runHandlers() }}, 100);
		} else if (d.addEventListener) {
			d.addEventListener("DOMContentLoaded", function(){t.runHandlers()}, false);
		} else if (d.all && !window.opera) {
			var s = d.createElement("script");
			s.setAttribute("type", "text/javascript");
			s.setAttribute("src", "");			
			s.setAttribute("defer", "true");
			s.onreadystatechange = function(){if (this.readyState == "complete") t.runHandlers()} 
			this.h.insertBefore(s, this.h.firstChild); 
		}
		var old_handler = window.onload;
		window.onload = function(){t.runHandlers(old_handler)};
	} catch (e){}
}


adriver.prototype.checkFlash = function(req){
	try {
		if (req) return (this.flashVer[0] >= req);

		var d, n = navigator, m, f = 'Shockwave Flash';
		if((m = n.mimeTypes) && (m = m["application/x-shockwave-flash"]) && m.enabledPlugin && (n = n.plugins) && n[f]) {d = n[f].description}
		else if (window.ActiveXObject) { try { d = (new ActiveXObject((f+'.'+f).replace(/ /g,''))).GetVariable('$version');} catch (e) {}} 
		if (d) adriver.prototype.flashVer = d.replace(/\D+/,'').split(/\D+/);
	} catch (e){}
	return false;
}

//============optional components=================//

adriver.prototype.setAnchor = function (){this.anchor = this.addDiv(this.p, {position:"relative", float: "left"});}

adriver.prototype.addPanel = function (id, params, inner){ 
	var panel = null;
	try {
		if (!this.panels){
			this.panels = {};
		}
		panel = this.addDiv(this.anchor, params, inner)  
		this.panels[id] = panel;
	}catch(e){}
	return panel;
}

adriver.prototype.addDiv = function (o, params, inner){
	var n = null;
	try {
		n = document.createElement("DIV");
		for (var i in params){ n.style[i] = params[i] } 
		if (inner) n.innerHTML = inner;
		o.insertBefore(n, o.firstChild); 
	}catch(e){}
	return n;
}

function adriver_dispatcher(ph, panel, command, arg){
	try {
		var a = adriver.items[ph];
		if (a && a.dispatch) a.dispatch(panel, command, arg);
	} catch (e) {}
}

/********** Adriver AsyncJS loader V1.1 *************/

