var hsupdate = 0;
var timeouts = [];

function printLinks(){
	$("#content").append('<a href="#" class="chstyle" id="s_print">версия для печати</a> <a href="#" class="chstyle" id="s_default">обычная версия</a>');

	$(".chstyle").click(function(){
		var style = $("#defstyle").attr('href');
		if (style == '/i/style.css'){
			$("#defstyle").attr('href','/i/print.css');
			$("#s_print").hide();
			$("#s_default_holder").show();
			$("#s_default").show();
		} else {
			$("#defstyle").attr('href','/i/style.css');
			$("#s_print").show();
			$("#s_default").hide();
		}
		return false;
	});
}

function getAbsolutePosition(element) {
  var r = { x: element.offsetLeft, y: element.offsetTop };
  if (element.offsetParent) {
    var tmp = getAbsolutePosition(element.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
};

function bind_ajax_poll() {
	$("#poll p a").click(function() {
		$("#pollcontent").load('/ajax/'+$(this).attr('id'),$("form#poll").serializeArray());
		return false;
	});	
}

function update_hotstuff() {
/*
	var rnd = Math.random()*1000000;
	rnd = rnd.toString();
	$("#hotstuff_holder").load('/ajax/hotstuff/?rnd='+rnd, null, function() {
		setTimeout('update_hotstuff()',5000);
	});
*/
}

function init_menu() {
	$(".menuitem").mouseover(function(){
		var mname = $(this).attr('id');
		var position = getAbsolutePosition(this);
		$("#sub"+mname).show().css({'left':(position.x),'top':(-16-$("#sub"+mname).height())});
	}).mouseout(function(){
		var mname = $(this).attr('id');
		timeouts["sub"+mname] = setTimeout('$("#sub'+mname+'").hide();', 300);
	});
		
	$(".submenuitem").mouseover(function(){
		clearTimeout(timeouts[$(this).attr('id')]);
	}).mouseout(function(){
		var mname = $(this).attr('id');
		timeouts[mname] = setTimeout('$("#'+mname+'").hide();', 300);
	});
}
