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);


marqueeText = Class.create();
marqueeText.prototype = {
    initialize: function(obj,text,params) {
        /**Настраиваемые параметры*/
        this.textspeed = 80;
        this.period = 10;

        this.speed=this.textspeed

        this.obj = $(obj); //объект, (в котором все движется)
        $(text).style.display='none';
        this.ow = this.obj.offsetWidth; //ширина объекта
        this.text = $(text); //то что движется
        /**накладываем стили и делаем объект релативным*/
        this.obj.style.overflow="hidden";
        this.obj.style.height = '2em';
        this.obj.style.position='relative';

        /**накладываем стили и делаем текст абсолютным*/
        this.text.style.whiteSpace='nowrap';
        this.text.show();
        this.tw = this.text.offsetWidth;
        //alert(this.tw);
        this.text.style.display='block';
        this.text.style.position='absolute';

        /**сдвигаем текст почти в самый конец объекта*/
        this.ctl = this.ow-100;
        this.text.style.left=this.ctl+'px';
        this.isrun=false;
    },

    stoper: function() {
        this.speed = 0;

    },

    positioned: function(pe) {
        this.pe=pe;
        this.ctl = this.ctl-this.speed*(this.period/1000);
        if (this.ctl<-this.tw) {
            this.ctl=this.ow;
        }
        this.text.style.left=this.ctl+'px';
    },

    run: function(pe) {
        this.speed = this.textspeed;
        if (this.isrun) {
            return;
        }
        this.isrun = true;
        new PeriodicalExecuter(this.positioned.bind(this),this.period/1000);

    }

}

