window.isContent = true;


function getPageSize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}


Event.observe(window, 'resize', function(){
	
	var head = getPageSize()[0];
	
	if(isContent)
	{
		var wid = getPageSize()[0]-$('sidebar').getWidth()-10;
		var cont_width;
		if(wid < (980-$('sidebar').getWidth()))
		{
			cont_width = 980-$('sidebar').getWidth();
			$('content').style.width = cont_width+'px';
			$('header').style.width = '980px';
			$('footer').style.width = '980px';
			
		}
		else
		{
			cont_width = wid;
			$('content').style.width = wid+'px';
			$('header').style.width = head+'px';
			$('footer').style.width = head+'px';
			
		}
		
		if($('newsblock')) $('newsblock').style.width = $('content').getWidth() - 350 + 'px';
	}
	else
	{
		if(head < 980)
		{
			$('header').style.width = '980px';
			$('footer').style.width = '980px';
		}
		else
		{
			$('header').style.width = head+'px';
			$('footer').style.width = head+'px';
			
		}

	}
	
	if($$('.header_search form select')[0]) $$('.header_search form select')[0].style.width = (cont_width-270)*0.3 + 'px';
	if($$('.header_search form .txtfield')[0]) $$('.header_search form .txtfield')[0].style.width = (cont_width-285)*0.65 + 'px';
	
});

function setCookie (name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}


Event.observe(window, 'load', function(){
	
	
	
var head = getPageSize()[0];
	
	if(isContent)
	{
		var wid = getPageSize()[0]-$('sidebar').getWidth()-10;
		var cont_width;
		if(wid < (980-$('sidebar').getWidth()))
		{
			cont_width = 980-$('sidebar').getWidth();
			$('content').style.width = cont_width+'px';
			$('header').style.width = '980px';
			$('footer').style.width = '980px';
			
		}
		else
		{
			cont_width = wid;
			$('content').style.width = wid+'px';
			$('header').style.width = head+'px';
			$('footer').style.width = head+'px';
			
		}
		
		if($('newsblock')) $('newsblock').style.width = $('content').getWidth() - 350 + 'px';
	}
	else
	{
		if(head < 980)
		{
			$('header').style.width = '980px';
			$('footer').style.width = '980px';
		}
		else
		{
			$('header').style.width = head+'px';
			$('footer').style.width = head+'px';
			
		}

	}
	
	if($$('.header_search form select')[0]) $$('.header_search form select')[0].style.width = (cont_width-270)*0.3 + 'px';
	if($$('.header_search form .txtfield')[0]) $$('.header_search form .txtfield')[0].style.width = (cont_width-285)*0.65 + 'px';
	
	$$('.parent').each(function (it){
		Event.observe(it, 'click', function(){
			$$('.menu_content').each(function (it){
				it.style.display = 'none';
				
				setCookie(it.id, "collapsed", "Mon, 01-Jan-2020 00:00:00 GMT", "/");
			});

			it.next().style.display = 'block';
		});
	});
	
	$$('.menu_toggle').each(function (it){
		Event.observe(it, 'click', function(){
			
			$$('.menu_content').each(function (it){
				setCookie(it.id, "collapsed", "Mon, 01-Jan-2020 00:00:00 GMT", "/");
			});
		});
	});
	
	$$('.menu_content li a').each(function (it){
		Event.observe(it, 'click', function(){
			
			setCookie(it.up(1).id, "expanded", "Mon, 01-Jan-2020 00:00:00 GMT", "/");
		});
	});
	
	$$('.menu_content').each(function (it){
		
		if(getCookie(it.id) == 'expanded') it.style.display = 'block';
	});
	
	
	
	
	$$('.menu_footer').each(function (it){
		Event.observe(it, 'mouseover', function(){	
			clearTimeout(window.cl);
		});	
		Event.observe(it, 'mouseout', function(){	
			window.cl = setTimeout(function(){
					$$('.menu_footer').each(function(it){
						it.up().removeClassName('act');
						it.hide();
					});
			},1000);
			
		});	
	});
	
	$$('.footerNavLnk').each(function (it){
		Event.observe(it, 'mouseover', function(ev){
			Event.element(ev).up().addClassName('act');
			
			$$('.menu_footer').each(function(it){
				it.up().removeClassName('act');
				it.hide();
			});
			
		});	
		
		Event.observe(it, 'mouseout', function(ev){
			Event.element(ev).up().removeClassName('act');
		});	
	});
	
	$$('.footerNav').each(function (it){
		Event.observe(it, 'mouseover', function(){
			if(window.cl) clearTimeout(window.cl);
			$$('.menu_footer').each(function(it){
				it.up().removeClassName('act');
				it.hide();
			});
			
			$(this).next().show();
			$(this).up().addClassName('act');
			
		});	
		
		Event.observe(it, 'mouseout', function(){
			
			window.cl = setTimeout(function(){
					$$('.menu_footer').each(function(it){
						it.up().removeClassName('act');
						it.hide();
					});
			},1000);
						
		});	
	});
	
});