//класс который запускает при загрузке люьой код
function todo(){
	this.action=new Array();
	this.execute=function(){
	    for(var i in this.action){
		try{todo.action[i]();} catch(er){alert('todo >> "'+er.message+'" in "'+er.fileName+'" on "'+er.lineNumber+'"');
	    }
	}};
	var onLoadAction=function(o){return function(){o.execute();}}(this);
	if(typeof document.attachEvent!='undefined')window.attachEvent('onload',onLoadAction);
	else window.addEventListener('load',onLoadAction,false);
};

todo.prototype.onload=function(func){this.action[this.action.length]=func;};
todo=new todo();


function viewBigImage(href, path, width, height){
FLS=window.open(path+"view_big_image.php?img="+href, 'viewImage', "width="+width+", height="+height+" scrollbars=no , resizable=no"); 
FLS.focus();
return false;
}


function tokenSelect(obj, ajax_obj){

    var ths = obj.parentNode.parentNode.getElementsByTagName('th');
    for(th in ths){
	if(ths[th].className == 'sel'){
	    ths[th].className = '';
	    break;
	}
    }
    obj.className = 'sel';
    ajax_obj.loadModule();

    return false;
}

function viewLoginForm(){
    $("#loginBlockForm").animate(
		    {width:"100%"},
		    {duration : 500, easing: 'easeOutCubic'})
    return false;
}


/* --------- листалка ----------------------------*/
function leafwork(body_block_id, width){

	this.width = width;
	this.body_block_id = body_block_id;
	this.slide = false;
	this.active = 0;
	this.count = 0;
	this.interval = false;
}

leafwork.prototype.initialize = function(){
	this.slide = $('#'+this.body_block_id+ ' > div');
	this.count = this.slide.length;
	for(i=0; i<this.count; i++){
		$(this.slide[i]).css('z-index', '100'+(this.count-i));
	}
	this.slideshow();
}

leafwork.prototype.slideshow = function(){
	var obj = {global_obj : this};
	this.interval = window.setInterval(function () {obj.global_obj.next()}, 10000);
}

leafwork.prototype.action = function(action){
	if(this.interval)
		window.clearInterval(this.interval);
	
	if(action == 'prev'){
		this.prev();
	} else
		this.next();

	return false;
}

leafwork.prototype.next = function(){
	if(this.slide){
		if(this.active >= (this.count-1)){
			this.setDefault('+');
			this.active = 0;
			return false;
		}
		
		$(this.slide[this.active]).animate({
					     left : '-='+this.width+'px',
					  	}, 500);
 		this.active++;
 	}

	return false;
}

leafwork.prototype.prev = function(){
	if(this.slide){
		
		if(this.active <= 0){
			this.setDefault('-');
			this.active = this.count;
		}
		
		this.active--;
		$(this.slide[this.active]).animate({
					     left : '+='+this.width+'px',
					  	}, 500);
 	}
	return false;
}

leafwork.prototype.setDefault = function(act){
	if(this.slide){
		for(i=0; i<this.count; i++){
			$(this.slide[i]).animate({
					     left : (act == '+' ? '0px' : '-'+this.width+'px'),
					  	}, 500);
		}
	}
}
