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

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


function ajaxLoadContent(url, content_id, params){
	$('#' + content_id).html('<div class="ajax_loader"><img src="/img/ajax-loader.gif"/></div>');
	$.get(url, params, 
		function(response){
			onAjaxContentLoaded(response, content_id);
		}
	);
}

function onAjaxContentLoaded(text, content_id){
	$('#' + content_id).html(text);
}

function toggleSections(sct, lnk){
	lnk.blur();
	if(!$('#' + sct).hasClass('ch_vis')){
		$('#catalog_sections div.ch_vis').animate({'height': 'hide'}, 'fast').removeClass('ch_vis').prev().removeClass('op');
		$('#' + sct).animate({'height': 'show'}, 'fast').addClass('ch_vis').prev().addClass('op');
	}else{
		$('#' + sct).animate({'height': 'hide'}, 'fast').removeClass('ch_vis').prev().removeClass('op');
	}
}

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;
		
		//cnt_width = 885;
		
		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(new_pos != null){
			if(new_pos == 0)
				$('#scroll_control_left_' + bid + ' img').addClass('inactive');//attr({'src': '/img/scroll_left_inactive.gif'});
			else
				$('#scroll_control_left_' + bid + ' img').removeClass('inactive');//attr({'src': '/img/scroll_left.gif'});
				
			if(new_pos+photos_width <= cnt_width)
				$('#scroll_control_right_' + bid + ' img').addClass('inactive');//.attr({'src': '/img/scroll_right_inactive.gif'});
			else
				$('#scroll_control_right_' + bid + ' img').removeClass('inactive');//.attr({'src': '/img/scroll_right.gif'});
				
			$(content).animate({'left': new_pos + 'px'});
		}
		
	}
	
}
