document.domain = "forumavia.ru";
plus_minus = function (el) {
	var change_ul = function(headlines){

	for (var i = 0; i < headlines.length; i++) {
			switch (el.className) {
					case 'add' :
						if (i == headlines.length - 1) {
							after_update = function() {make_inactive(el,'add-inactive');}
						}
						if (!headlines[i].visible()) {
							headlines[i].show();
							setCookie(uniquepageid+"-c-"+headlines[i].up(2).id, i + 1, 14);
							collapse_animation.get(name.id).adjust();
							make_inactive(el.up('.control').down('.remove-inactive'),'remove');
							if (anim) anim.setStyle({height:anim.getHeight() + 'px'});
							return;
						}
						break;
					case 'remove' :
						if (i == headlines.length - 1) {
							headlines[i].hide();
							collapse_animation.get(name.id).adjust();
							make_inactive(el.up('.control').down('.add-inactive'),'add');
							if (anim) anim.setStyle({height:anim.getHeight() + 'px'});
							return;
						}
						if (!can_hide_all && !i) continue;
						if (!headlines[i+1].visible()) {
							headlines[i].hide();
							setCookie(uniquepageid+"-c-"+headlines[i].up(2).id, i, 14);
							collapse_animation.get(name.id).adjust();
							if (!i || i == 1 && !can_hide_all) {
								after_update = function() {make_inactive(el,'remove-inactive')}
							}
							if (anim) anim.setStyle({height:anim.getHeight() + 'px'});
							return;
						}
					break;
		}
	}
	}
	var name = el.up('.drug-drop').down('.content');
	var anim = name.down('.anim');
	var can_hide_all = name.down('.topic-top');
	var after_update = null;
	var largelist = name.down('.largelist');
	if (largelist) {
		var k = 0;
		var ul = null;
		while (ul = name.down('ul',k++)) {
			anim = ul;
			ul.setStyle({height:'auto'});
			change_ul(ul.childElements());
		};
	} else {
		var ul = (can_hide_all ? name.down('ul',1) : name.down('ul'));
		if (!ul) return;
		if (anim){
			anim.setStyle({height:'auto'});
		}
		change_ul(ul.childElements());
	}
	if (after_update && !largelist) after_update();
}
initList =  function (name,n) {
			if (!name) return;
			$(name).setStyle({overflow:'hidden'});
			var anim = name.down('.anim');
			if (anim){
				anim.setStyle({height:'auto'});
			} else {
				make_inactive(name.up('.drug-drop').down('.add-inactive'),'add');
				if (name.down('.largelist')) return;
				var headlines = (name.down('div.topic-top') ? name.down('ul',1) : name.down('ul'));
				if (headlines){
				 	headlines = headlines.childElements();
					for (var i = n; i < headlines.length;i++){
						headlines[i].hide();
					}
				}
			}
}
adjust = function (ctl){
	var name = ctl.up('.drug-drop').down('.content');
	var headlines = (name.down('div.topic-top') ? name.down('ul',1) : name.down('ul'));
	if (!headlines) return;
	headlines = headlines.childElements();
	var cnt_visible = 0;
	headlines.each( function(s) {if (s.visible()) ++cnt_visible;});
	if (cnt_visible == headlines.length) {
		make_inactive(ctl.down('.add'),'add-inactive');
	} else if (cnt_visible == 1) {
		make_inactive(ctl.down('.remove'),'remove-inactive');
	}
}
make_inactive = function(el,newClassName){
	if (!el) return;
	el.removeClassName(el.className);
	el.addClassName(newClassName);
}
var collapse_animation = new Hash();
collapse = function (el) {
	var name = el.up('.drug-drop').down('.content').id;
	collapse_animation.get(name).adjust();
	collapse_animation.get(name).slideit();
	if (el.up('.control')) {
		if (collapse_animation.get(name).isExpanded == "no") {
			make_inactive(el.up('.control').down('.collapsed'),'collapse');
			make_inactive(el.up('.control').down('.add-inactive'),'add');
			make_inactive(el.up('.control').down('.remove-inactive'),'remove');
		} else {
			make_inactive(el.up('.control').down('.collapse'),'collapsed');
			make_inactive(el.up('.control').down('.add'),'add-inactive');
			make_inactive(el.up('.control').down('.remove'),'remove-inactive');
		}
	adjust(el.up('.control'))
	}
}
function animated (el_id) {
	var prev_im = null;
	var im1 = null;
	var im2 = null;
	this._init_anim(el_id);
	var last_anim = null;
	var clr = 0;
}
animated.prototype._load_animation = function(im){
	var time = 500;
	var ul = im.up('ul').childElements();
	if ($('expanding')) $('expanding').removeAttribute('id');
	if (this.prev_im == im) {
		if (im.up('li') == ul[0] && !im.hasClassName('active')) {
			im.setAttribute('id','expanding');
			this.im2 = new animatedcollapse('expanding',time,false,'contract');
			this.im2.isExpanded = 'no';
			this.im2.update(ul[ul.length-1].down('img').getHeight());
			this.im2.slidedown();
			im.up('li').addClassName('active');
		}
		return;
	}
	this.prev_im.setAttribute('id','collapsing');
	im.setAttribute('id','expanding');
	ul.each( function (s) {
		s.removeClassName('active')}
	);
	$('expanding').up('li').addClassName('active');
	this.im1 = new animatedcollapse('expanding', time, false, 'contract', 'collapsing');
	this.im1.isExpanded = 'no';
	this.im1.update(im.down('img').getHeight());
	this.im1.slidedown();
	this.prev_im.removeAttribute('id');
}

animated.prototype._init_anim = function(el){
	var li_all = $(el).childElements();
	this.prev_im = li_all[0].down('.img-cont');
}
animated.prototype.animate = function (el){
	if (this.clr) clearTimeout(this.clr);
	var thisobj = this;
	this.last_anim = function () {
		thisobj._load_animation(el);
		thisobj.prev_im = el;
	};
	this.clr = setTimeout (this.last_anim,450);
}
animated.prototype.reset = function(){
	if (this.clr) clearTimeout(this.clr);
	this.last_anim = null;
}
var rollovers = new Hash();
make_active = function (el){
	var all_elms = el.up().childElements();
	all_elms.each( function (s) {
		s.removeClassName('active')}
	);
	el.addClassName('active');
}
highLht = function(el) {
		var toggle = function(tag,attrs){
			var gross = el.up('div').down(tag);
			var kleine = el.down(tag);
			if (!gross || !kleine) return;
			while (attrs.length) {
				var attr = attrs.shift();
				gross.setAttribute(attr, kleine.readAttribute(attr));
			}
		}
		if (!el || el.hasClassName('active')) return false;
		if (el.up().hasClassName('anim') && el.down('.img-cont')) {
			rollovers.get(el.up().id).animate(el.down('.img-cont'));
		} else {
			make_active(el);
			toggle('img',['src','alt']);
			toggle('a',['href']);
		}
}
stopAnim = function(event,ul){
	var n1 = event.relatedTarget || event.toElement;
	if (!n1 || n1.tagName != 'IMG' && n1.tagName != 'DIV') return;
	rollovers.get(ul.id).reset();
}

displayHeadline = function() {
	if ($('headline-link')) {
		link = $('headline-link').href;

		if (escape(link) != getCookie('headline')) {
			$('headline').style.display='block';
		} else {
			$('headline').style.display='none';
		}
	}
}

switchHeadline = function() {
	$('headline').style.display='none';
	setCookie('headline', $('headline-link').href, 365);
}

getCookie=function(Name){
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function show_hide (el){
	if ($(el).getStyle('display') != 'none') $(el).setStyle({display:'none'});
	else  $(el).setStyle({display:'block'});
	return false;
}

function dump(arr,level) {
  var dumped_text = "";
  if(!level) level = 0;
  //The padding given at the beginning of the line.
  var level_padding = "";
  for(var j=0;j<level+1;j++) level_padding += "    ";
  if(typeof(arr) == 'object') { //Array/Hashes/Objects
    for(var item in arr) {
      var value = arr[item];
      if(typeof(value) == 'object') { //If it is an array,
        dumped_text += level_padding + "'" + item + "' ...\n";
        //dumped_text += dump(value,level+1);
      } else {
        dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
      }
    }
  } else { //Stings/Chars/Numbers etc.
    dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
  }
  return dumped_text;
};





Event.observe(window, 'load', function() {
	if ($('one') && $('two')) {
		var vis = Math.round(Math.random());
		(vis ? $('one') : $('two')).setStyle({display:'block'});
		(vis ? $('two') : $('one')).remove();
	}
	displayHeadline();
	var controls = $$('div.control');
	controls.each( function (s) {
		if (!s.up('.image') && !s.up('#video')) {
			s.observe('mouseup', function (event) {
				plus_minus(Event.findElement(event,'div') );
			} );
			var dnd = s.up('.drug-drop');
			if (dnd) {
				var headlines = dnd.down('.content');
				if((headlines.up().id=='dd-style4') && (headlines.up().id=='dd-style1') )
					{rowcount = 7}
				else
					{rowcount = 3};
				initList(headlines, getCookie(uniquepageid+"-c-"+headlines.up().id) == ''? rowcount : getCookie(uniquepageid+"-c-"+headlines.up().id));
			}
		}
		//adjust(s)
	} );
	var rollovrs = $$('div.topic-top');
	rollovrs.each( function (s) {
		if (s.down('ul')) s.down('ul').observe('mouseover', function (event) {
			highLht(Event.findElement(event,'li'));
		} );
	} );
	if ($('hot-news') && !$('description')) $('hot-news').observe('mouseover', function(event) {
			highLht(Event.findElement(event,'H1'));
		}
	);
	if ($('hot-news2') && !$('description')) $('hot-news2').observe('mouseover', function(event) {
			highLht(Event.findElement(event,'H1'));
		}
	);
	if ($('hot-newsZ') && !$('description')) $('hot-newsZ').observe('mouseover', function(event) {
			highLht(Event.findElement(event,'H1'));
		}
	);
	$$('ul.anim').each( function (s) {
			if (s.empty()) return;
			var first = s.childElements()[0];
			first.addClassName('active');
			first.down('.img-cont').setStyle({height:'auto'});
			if ($('polit-page')) {
				first.removeClassName('active');
				first.down('.img-cont').setStyle({height:'0pt'});
			}
			if (s.hasClassName('dormouse')) return;
			s.setAttribute('id','a_' + s.up('.drug-drop').id);
			rollovers.set (s.id, new animated(s.id));
			s.observe('mouseover', function(event) {
				highLht(Event.findElement(event,'li'));
			} )
			s.up('.content').observe('mouseout', function(event) {
				stopAnim(event,s);
			} )
		}
	);
	var collapses = $$('div.collapse');
	collapses.each( function (s) {
		var slider = s.up('.drug-drop').down('.content');
		slider.setAttribute('id','c_' + s.up('.drug-drop').id);
		slider.setStyle({zoom:1});
		collapse_animation.set (slider.id, new animatedcollapse(slider.id, 400, true));
		s.observe('mouseup', function (event) {
			collapse(Event.findElement(event,'div') );
		} );
		if (collapse_animation.get(slider.id).isExpanded == 'no'){
			s.removeClassName('collapse');
			s.addClassName('collapsed');
		}
	} );


 	if ($('sidebarOne')) $('sidebarOne').setStyle({display:'block'});
 	if ($('sidebarTwo')) $('sidebarTwo').setStyle({display:'block'});
 	if ($('sidebarThree')) $('sidebarThree').setStyle({display:'block'});
	setTimeout(load_adverts,100);
	var i = 0;
	$$('div.ad-body').each(function(s){
		var a = s.down('iframe');
		if (a) {
			a.setAttribute('id','resz' + i++);
			Event.observe(a, 'load', function() {
				resize_frame(a.id);
			});
		}
	});
} );
resize_frame= function(frameid){
	var resize = function(){
		var frame=$(frameid);
		if (frame) {
			if ( frame.contentDocument ) {
				if (frame.contentDocument.body.offsetHeight)
					frame.height = frame.contentDocument.body.offsetHeight;
				if (Prototype.Browser.Opera == true)
					frame.height = frame.contentDocument.body.scrollHeight;
			} else {
				if (frame.Document)
					frame.height = frame.Document.body.scrollHeight;
			}
		} else {}
	};
	setTimeout(resize,500);
}

var advert = new Array();
load_adverts = function(){
 	if (advert.length) {
 		advert.each(function(s){s(); });
 	}
}
create_iframe = function(div_id,_src,w,h){
	var div = $(div_id);
	if (!div) return;
	var ifr = document.createElement('iframe');
	ifr.frameBorder = 'no';
	ifr.width = w;
	if (h) ifr.height = h;
	ifr.scrolling = 'no';
	ifr.src = _src.toString();

    setTimeout(function () { div.appendChild(ifr);  }, 0);
    //div.insert(ifr);
}
//choice image
choiceImage = function( id ){
	var imgs = document.getElementById( "images" ).getElementsByTagName( "img" );
	for(i = 0; i < imgs.length; i++) {
 		imgs[i].style.display = "none";
	}
	document.getElementById( id ).style.display = "";
	document.getElementById( "alt" ).innerHTML = document.getElementById( id ).alt;
}

