ijs.category_thumbs = {
	
	
	'actions': {},
	'rel_cateogry_id': 'rel_cateogry',
	'worker_interval_id': 0,
	'actions_length': 0,
	'worker_step': 0, 
	
	'init': function(){
		
		this.init_rel_category();
		
		},
	
	'init_rel_category': function(){
		
		var rel_cateogry = document.getElementById(this.rel_cateogry_id);
		
		if(rel_cateogry){
			
			var _as = rel_cateogry.getElementsByTagName('a');
			var as = new Array;
			for(var i = 0 , c = _as.length; i < c; ++i)
				as.push(_as[i]);
			
			
			var title_wrapper = rel_cateogry.getElementsByTagName('h2')[0];
			var title = title_wrapper.getElementsByTagName('a')[0];
			title._top = 0;
			title._v = 0;
			
			rel_cateogry._title = title;
			title._init_titile = title.innerHTML;
			rel_cateogry._title = title;
			rel_cateogry.onmouseout = function(ev){
			
				ev = ev || window.event;
				var mouse_coords = ijs.position.mouse_coords(ev);
				if(mouse_coords.y <= this.offsetTop || mouse_coords.y >= this.offsetTop + this.offsetHeight)
					ijs.category_thumbs.add_work('text_main', ijs.category_thumbs.show_main_text, this._title, 1);
				
				}
			
			this.rel_cateogry_height = title.offsetHeight;
			
			
			var a;
			for(var i = 0 , c = as.length; i < c; ++i){
				
				a = as[i];
				if(!a.title){
					
					var img = a.getElementsByTagName('img')[0];
					
					img._title_obj = document.createElement('a');
					img._title_obj.href = a.href;
					img._title_obj.innerHTML = img.alt;
					img._title_obj.style.top = '100%';
					img._title_obj._top = 100;
					img._title_obj._v = 0;
					
					
					title_wrapper.appendChild(img._title_obj);
					
					
					img._timeout = 0;
					img._current_img_offset = 0;
					img._title = title;
					img._id = 'rel_img_' + i;
					img._odd = 0;
					img.onmouseover = function(){
						ijs.category_thumbs.add_work(this._id, ijs.category_thumbs.show_border, this, 1);
						ijs.category_thumbs.add_work(this._id+'_text', ijs.category_thumbs.show_text, this._title_obj, 1);
						ijs.category_thumbs.add_work('text_main', ijs.category_thumbs.hide_main_text, this._title, 1);
						}
					
					img.onmouseout = function(){
						ijs.category_thumbs.add_work(this._id, ijs.category_thumbs.hide_border, this, 5);
						ijs.category_thumbs.add_work(this._id+'_text', ijs.category_thumbs.hide_text, this._title_obj, 1);
						ijs.category_thumbs.add_work('text_main', ijs.category_thumbs.show_main_text, this._title, 2);
						}
					
					}
				}
			}
		},
	
	'hide_main_text': function(){
		
		this._v += 0.5 ;
		
		if(this._top - this._v > -100){
			this._top -= this._v;
			this.style.top = parseInt(this._top) + '%';
			ijs.css.set_opacity(this, 100 - (-1) *parseInt( this._top));
			return true;
			}
		else{
			this.style.top = '-100%';
			ijs.css.set_opacity(this, 0);
			this._v = 0;
			return false;
			}
		
		},
		
	'show_main_text': function(){
		
		//var t = this._top
		
		if(this._top + 10 < 0){
			this._top += 10;
			this.style.top = this._top + '%';
			ijs.css.set_opacity(this, 100 - (-1) * this._top);
			
			return true;
			}
		else{
			this.style.top = '0%';
			ijs.css.set_opacity(this, 100);
			return false;
			}
		
		},
	
	'show_text': function(){
		
		var t = this._top / 2;
		
		if(this._top - t > 0){
			this._top -= t;
			this.style.top = this._top + '%';
			ijs.css.set_opacity(this, 100-this._top);
			return true;
			}
		else{
			this.style.top = '0%';
			ijs.css.set_opacity(this, 100);
			return false;
			}
		
		},
		
		
	'hide_text': function(){
		
		this._v += 0.5 ;
		
		if(this._top + this._v < 100){
			this._top += this._v;
			this.style.top = parseInt(this._top) + '%';
			ijs.css.set_opacity(this, parseInt(100 - this._top));
			return true;
			}
		else{
			this.style.top = '100%';
			ijs.css.set_opacity(this, 0);
			this._v = 0;
			return false;
			}
		
		},
	
	'hide_border': function(){
		
		this._current_img_offset -= 54;
		
		if(this._current_img_offset < 0){
			this._current_img_offset = 0;
			return false;
			}
		
		this.style.backgroundPosition = '0px -'+ this._current_img_offset +'px';
		
		return true;
		
		},
	
	
	'show_border': function(){
		
		this._current_img_offset += 54;
		
		if(this._current_img_offset > 486){
			this._current_img_offset = 486;
			return false;
			}
		
		this.style.backgroundPosition = '0px -'+ this._current_img_offset +'px';
		
		return true;
		
		},
	
	
	
	'add_work': function(id, callback, context, odd){
		
		if(!this.actions[id])
			++this.actions_length;
		
		this.actions[id] = {
			'callback': callback,
			'context': context ? context : this,
			'id': id,
			'odd': odd ? odd : 1
			};
		
		
		
		if(!this.worker_interval_id){
			this.worker_step = 0;
			this.worker_interval_id = setInterval(function(){ ijs.category_thumbs.work(); } , 10);
			}
		
		},
	
	'work': function(){
		
		/*
		switch(this._odd){
			case 0: this._d.innerHTML = '-';break;
			case 1: this._d.innerHTML = '/';break;
			case 2: this._d.innerHTML = '|';break;
			case 3: this._d.innerHTML = '\\';this._odd = -1;break;
			}
		this._d.innerHTML += ' ' + this.actions_length +' ' + this.worker_step;
		++this._odd;
		*/
		
		if(!this.actions_length){
			clearInterval(this.worker_interval_id);
			this.worker_interval_id = null;
			}
		else{
			var action;
			for(var id in this.actions){
				action = this.actions[id];
				if(action && this.worker_step % action.odd == 0){
					if(action.callback.call(action.context) !== true){
						this.actions[id] = false;
						--this.actions_length;
						}
					}
				}
			++this.worker_step;
			}
		}
	
	}


	
	

ijs.onload(function(){ijs.category_thumbs.init()});

