/* common function */
function toggleBlock(id, link, animate, t_class, animate_param, opened_text, closed_text){
	if(!animate_param){
		animate_param = 'height';
	}
	//alert(animate_param);
	var res = 1;
	if(t_class){
		$(link).toggleClass(t_class);
	}
	if($('#'+id).css('display') == 'none'){

		if(animate){
			if(animate_param == 'height')
				$('#'+id).animate({'height': 'show'}, 'fast');
			else
				$('#'+id).animate({'width': 'show'}, 'fast');
		}else
			$('#'+id).show();
		
		if(opened_text && link){
			link.innerHTML = closed_text;
		}
			
	}else{
		if(animate){
			if(animate_param == 'height')
				$('#'+id).animate({'height': 'hide'}, 'fast');
			else
				$('#'+id).animate({'width': 'hide'}, 'fast');
		}else
			$('#'+id).hide();
			
		if(closed_text && link){
			link.innerHTML = opened_text;
		}
	}
	if(link)
		link.blur();
	return false;
}

function copyPreviousElement(lnk){
	lnk.blur();
	var new_el = $(lnk).prev().clone();
	$(new_el).insertBefore(lnk);
	/* clear inputs */
	$(':input', new_el).attr('value', '');
}

function scrollItems(bid, dir, lnk){
	
	lnk.blur();
	
	var content = document.getElementById('scroll_content_' + bid);
	if(content){

		var t_container = $(content).parent();
		var container = t_container[0];
		var cnt_width = container.offsetWidth;
		var photos_width = content.offsetWidth;
		var cur_pos = content.offsetLeft;
		var new_pos = null;
		
		/*
		if(dir == 0){
			if(cur_pos < 0){			
				new_pos = cur_pos+cnt_width;
				if(new_pos > 0)
					new_pos = 0;
			}
		}else{
			if(photos_width + cur_pos - cnt_width > 0){			
				new_pos = cur_pos-cnt_width;
			}
		}
		*/
		if(dir == 0){
			if(cur_pos < 0){			
				new_pos = cur_pos+164;
				if(new_pos > 0)
					new_pos = 0;
			}
		}else{
			if(cur_pos + photos_width > cnt_width){			
				new_pos = cur_pos-164;
			}
		}		
		
		if(new_pos != null){
			
			if(new_pos == 0)
				$('#scroll_control_left_' + bid + ' img').addClass('inactive').attr({'src': '/img/scroll_left_inactive.png'});
			else
				$('#scroll_control_left_' + bid + ' img').removeClass('inactive').attr({'src': '/img/scroll_left.png'});
			
				
			if(new_pos+photos_width <= cnt_width)
				$('#scroll_control_right_' + bid + ' img').addClass('inactive').attr({'src': '/img/scroll_right_inactive.png'});
			else
				$('#scroll_control_right_' + bid + ' img').removeClass('inactive').attr({'src': '/img/scroll_right.png'});
			
			/*
			if(new_pos+photos_width <= 164)
				$('#scroll_control_right_' + bid + ' img').addClass('inactive').attr({'src': '/img/scroll_right_inactive.png'});
			else
				$('#scroll_control_right_' + bid + ' img').removeClass('inactive').attr({'src': '/img/scroll_right.png'});
			*/
				
			$(content).animate({'left': new_pos + 'px'});
		}
		
	}
	
}

function makeEnding(num, word, end1, end2, end3){
		var postfix = '';
		if(num%100 > 10 && num%100 < 21 || num%10 >= 5 && num%10 <= 9 || num%10 == 0)
			postfix = end3;
		else{
			if(num%10 >= 2 && num%10 <= 4)		
				postfix = end2;
			else
				postfix = end1;
		}
		return word+postfix;
}
