var absmaxheight = 250;
var absminheight = 100;

function att_showmore(catID, blnanimate){
	var lists = YAHOO.util.Dom.getElementsBy( function (el) {return el.id=='attributes_lists';}, 'div', document.getElementById('attributes_lists_group'));
	
	var maxheight = 0;
	for (var i=0; i<=lists.length; i++){
		var region = YAHOO.util.Dom.getRegion(lists[i]);
		height = region.bottom-region.top;
		if (height > maxheight)
			maxheight = region.bottom-region.top;
	}
	if (maxheight > absmaxheight)
		maxheight = absmaxheight;
	
    var att_height  = {height: { to: maxheight }};
    var anim_height = new YAHOO.util.Anim('attributes_lists_group', att_height, 0.5, YAHOO.util.Easing.easeOut);

	if (document.getElementById('attributes_seemore')) 	document.getElementById('attributes_seemore').style.display = 'none';
	if (document.getElementById('attributes_minimise'))	document.getElementById('attributes_minimise').style.display = 'block';
	anim_height.animate();

	scrollLists(true, blnanimate);
	//anim_height.onComplete.subscribe(function() { scrollLists(true, true) } );
	
	if (document.getElementById('attributes_seemore')) 	YAHOO.util.Cookie.set("meta_cat", catID+"");
}

function att_minimise(catID){
    var att_height  = {height: { to: absminheight }};
    var anim_height = new YAHOO.util.Anim('attributes_lists_group', att_height, 0.5, YAHOO.util.Easing.easeOut);

	if (document.getElementById('attributes_lists_group')) 	document.getElementById('attributes_lists_group').style.overflow = 'hidden';
	if (document.getElementById('attributes_minimise')) 	document.getElementById('attributes_minimise').style.display = 'none';
	if (document.getElementById('attributes_seemore')) 		document.getElementById('attributes_seemore').style.display = 'block';
	anim_height.animate();
	
	scrollLists(false, true)
	//anim_height.onComplete.subscribe(function() { } );
	
	YAHOO.util.Cookie.remove("meta_cat");
}

function scrollLists(blnscroll, blnanimate){
	var lists = YAHOO.util.Dom.getElementsBy( function (el) {return el.id=='attributes_lists';}, 'div', document.getElementById('attributes_lists_group'));
	
	for (var i=0; i<=lists.length; i++){ 
		var region = YAHOO.util.Dom.getRegion(lists[i]);
		height = region.bottom-region.top;
		
		if (height > absmaxheight && blnscroll){
			YAHOO.util.Dom.addClass(lists[i], 'scroll');
		}
		if (! blnscroll)
			YAHOO.util.Dom.removeClass(lists[i], 'scroll');
			
		if (YAHOO.util.Dom.hasClass(lists[i], 'scroll')){
			
			var selected = YAHOO.util.Dom.getElementsBy( function (el) {return el.id=='attributes_list' && YAHOO.util.Dom.hasClass(el, 'selected'); }, 'div', lists[i]);
			
			var position = 0;
			for (j=0; j<selected.length; j++){
				if (position == 0) {
					var region = YAHOO.util.Dom.getRegion(selected[j]);
					position = region.top;
				}
			}
			// take off parent's top position
			var region = YAHOO.util.Dom.getRegion(lists[i]);
			position = position - region.top - 5;
			
			if (blnanimate) {
				var myAnim = new YAHOO.util.Scroll(lists[i], { scroll: { to: [0, position] } }, 0.5, YAHOO.util.Easing.easeOut);
				myAnim.animate();  
			} else {
				var myAnim = new YAHOO.util.Scroll(lists[i], { scroll: { to: [0, position] } }, 0);
				myAnim.animate();  
			}
		}
	}
}

function att_setstate(catID){
	if (YAHOO.util.Cookie.get("meta_cat") == catID+""){
		scrollLists(true, false);
		att_showmore(catID, false);
	} else {
		//att_minimise(catID)
	}
}