
inAni = false;
current = new Hash();
current.set('adv', 'off');
current.set('loc', 'off');
current.set('sidebar-contents', 'off');
current.set('directory', 'off');


toggleGrow = function(el){
	if(inAni == false){
		inAni = true;
		if(current.get(el) == 'off'){
	//			$('search-'+el+'-content').style.display="block";
			toggleSearchBtn(el, 'on');
			Effect.Grow('search-'+el+'-content', {direction:'top',duration:'0.5', afterFinish: function(){
				inAni = false;
				current.set(el, 'on');
			}, afterUpdate: function(){
	//			$('search-'+el+'-inner').style.width=$('search-'+el+'-content').style.width;
	//			$('search-'+el+'-inner').style.height=$('search-'+el+'-content').style.height;
			}});
			//Effect.Appear('search-'+el+'-close', {duration:'0.5'});
		}
		else{
	//			$('search-'+el+'-content').style.display="none";
			Effect.Shrink('search-'+el+'-content', {direction:'top',duration:'0.5', afterFinish: function(){
				inAni = false;
				$('search-'+el+'-content').style.display="none";
				current.set(el, 'off');
				toggleSearchBtn(el, 'off');
	//			$('search-'+el+'-inner').style.width='';
			}, afterUpdate: function(){
	//			$('search-'+el+'-inner').style.width=$('search-'+el+'-content').style.width;
	//			$('search-'+el+'-inner').style.height=$('search-'+el+'-content').style.height;
			}});
			//Effect.Fade('search-'+el+'-close', {duration:'0.5'});
		}
	}
}

toggleSearchBtn = function(el, state){
	if(current.get(el) != 'on' || (state == 'on' && current.get(el) == 'on')){
		if(state=='on') $('search-'+el+'-arr').src='/images/acc_arrow-down.png';
		else if(state=='off') $('search-'+el+'-arr').src='/images/acc_arrow-right.png';
	}
}

toggleSidebar = function(el){
	if(inAni == false){
		inAni = true;
		if(current.get(el) == 'off'){
			Effect.Grow(el, {direction:'top',duration:'0.5',
			beforeStart: function(){
				$(el).style.width='0px';
			},
			afterFinish: function(){
				inAni = false;
				current.set(el, 'on');
			}, afterUpdate: function(){
				$(el+'-td').style.width=$(el).style.width;
			}});
		}
		else{
			Effect.Shrink(el, {direction:'top',duration:'0.5',
			afterFinish: function(){
				inAni = false;
				$(el).style.display="none";
				current.set(el, 'off');
			}, afterUpdate: function(){
				$(el+'-td').style.width=$(el).style.width;
			}});
		}
	}
}


toggleArr = function(el){
	var img = $(el+'-arr');
	if(img.className == 'arr-on'){
		img.src='/images/acc_arrow-right.png';
		img.className='arr-off';
	}else{
		img.src='/images/acc_arrow-down.png';
		img.className='arr-on';
	}
}


//    .:$:.  switch tabs and content divs  .:$:.

function toggleTabs(pFix, tNum, n)
{
	for(i=1; i<=n; i++)
	{
		var targetTab = $(pFix+"tBtn"+i);
		targetTab.className = "tab off";	
		var targetLayer = $(pFix+"tab"+i);
		targetLayer.style.display = "none";
	}
	var tTab = $(pFix+"tBtn"+tNum);
	tTab.className = "tab on";
	var tTab = $(pFix+"tab"+tNum);
	tTab.style.display = "block";
}



function toggleDisplay(div){
	var tdiv = $(div); 
	if(tdiv.style.display=='none') tdiv.show();
	else tdiv.hide();
}


// ----- protaculous request

function get(target, url, callback, show, params){
	try{ 
		var t = $(target);
		t.innerHTML = "<div class='p10'><img src='/images/loading.gif'></div>";
		new Ajax.Updater(
			t, 
			url, 
			{
				onComplete:callback(show),
				onFailure:function(err){
					alert('Error ' + err.status + ' -- ' + err.statusText);
				},
				asynchronous:true, 
				evalScripts:true,
				method:'POST',
				parameters:params
			}
		);
	}catch(err){	
		alert('Error ' + err.status + ' -- ' + err.statusText);
	}
}


// ------- protaculous submit form

function send(target, url, form, callback, show) {
	form = $(form);
	var params=form.serialize(true);
	if(!show) var show = target;
	try{
		get(target, url, callback, show, params);
	}catch(err){
		alert('Error: ' + err);
	}
	return false;	
}





	


