function coll_addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
}


function openclose(elem) {
	if ((el = document.getElementById(elem)) != null) {
		el.style.display = el.style.display=='none'? "" : 'none';
	}
}


function coll_gotourl(obj,country) {
	if (obj.value != 0) {
		path = '/countries/'+country+'/redirector.'+obj.value+'.html';
		window.location = path
	}
}


function loadJs(src){
    var head = document.getElementsByTagName("head")[0];
    script=document.createElement('script');
    script.setAttribute('type','text/javascript');
    script.setAttribute('src',src);
    head.appendChild(script);
   }

function fixateTable() {
	tables = $$("#center table");
	
	tables.each(function(table){
		
		if (table.getWidth() > $('center').getWidth()) {
			linkus = new Element('span');
			linkus.addClassName('show-table');
			linkus.update("Показать таблицу");
			vr = new Element('div');
			Insertion.Before(table,vr);
			Insertion.Before(vr,linkus);
			$(table).setStyle({backgroundColor: 'white'});
			//vr.appendChild(table.cloneNode(true));
			table.hide();
			
			Event.observe(linkus,'click',showWrapperAll.bindAsEventListener(null,vr,table,linkus));
		}
	});
	
	
}

function showWrapperAll(event,wrapper,table,link) {
	
	if (table.hasClassName('nowshow')) {
		wrapper.setStyle({height:0});
		table.hide();
		table.removeClassName('nowshow');
		link.update('Показать таблицу');
		return;
	}
	
	//wrapper.absolutize();
	table.show();
	table.absolutize();
	table.setStyle({left: 'auto'});
	table.addClassName('nowshow');
	wrapper.setStyle({height:table.getHeight()+'px'});
	link.update('Скрыть таблицу');
	
}



   
   
function activateAjax() {
	//loadJs('/admin/js/lib/prototype.js');
}

coll_addLoadEvent(fixateTable);