
function toggleSearchFolder(tgt, path)
{
	if (hasChildren(tgt)) {
		if (tgt.style.display == 'none') {
			tgt.style.display = 'block';
		} else {
			tgt.style.display = 'none';
		}
	} else {
		requestContentOnce(tgt.getAttribute('id'), 'LBXAgency', path);
	}
}

function toggleSubCat(catID)
{
	var id = 'subcat'+catID;
  	if (document.getElementById(id).style.display != 'block' || document.getElementById(id).childNodes.length == 0) {
  		requestContentOnce(id, 'LBXSearch', 'Category-'+catID, 'targetNodeID='+id);
  	} else {
  		hideById(id);
  	}
}

function diashow(type, id, pictureID, paused, offset, number)
{
	var nodeID = 'diashow_' + type.replace('/', '_') + '_'+id;
	
	if ($(nodeID)) {
		$(nodeID).parentNode.removeChild($(nodeID));
	}
	
	var diashow = document.createElement('div');
	diashow.setAttribute('id', nodeID);
	diashow.setAttribute('class', 'diashow');
	
	document.body.appendChild(diashow);
	
	if (paused) {
		document.diashow_stop = true;
	} else {
		document.diashow_stop = false;
	}	
	
	var path = 'Diashow-'+nodeID+'/'+type+'-'+id;
	if (pictureID) {
		path = path + '/Picture-'+pictureID+'/';
	}
	requestContent('LBXMain', path, 'offset='+offset+'&number='+number);
	
	presentElement(nodeID, 725, 725, true);
}

function diashow_next(type, id, pictureID, currentImage)
{	
	if (document.diashow_stop) {
		return;
	}
	var nodeID = 'diashow_' + type.replace('/', '_') + '_'+id;
	var path = 'Diashow-'+nodeID+'/'+type+'-'+id;
	if (pictureID) {
		path = path + '/Picture-'+pictureID+'/';
	}
	
	requestContent('LBXMain', path);
}

function setImageSrc(id, src)
{
 var img = new Image();
 img.src = src;
 document.getElementById(id).src = src;
}

/* Carousel */
// Enable/Disable next/previous buttons
function buttonStateHandler(button, enabled) {
 if (button == "prev-arrow")
   $('prev-arrow').src = enabled ? "/Modules/LBXMain/UI/images/carousel_left.png" : "/Modules/LBXMain/UI/images/carousel_empty.png"
 else 
   $('next-arrow').src = enabled ? "/Modules/LBXMain/UI/images/carousel_right.png" : "/Modules/LBXMain/UI/images/carousel_empty.png"
}

// Anim effects before and after scrolling
function animHandler(carouselID, status, direction) {
  var region = $(carouselID).down(".carousel-clip-region")
  if (status == "before") {
    Effect.Fade(region, {to: 0.3, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  }
  if (status == "after") {
    Effect.Fade(region, {to: 1, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  }
}

// Show/hide "loading" overlay before and after ajax request
function ajaxHandler(carousel, status) {
  var overlay = $('overlay');
  if (status == "before") {
    if (overlay) {
      overlay.setOpacity(0);
      overlay.show();
      Effect.Fade(overlay, {from: 0, to: 0.8, duration: 0.2})
    }
  }
  else 
    Effect.Fade(overlay, {from: 0.8, to: 0.0, duration: 0.2})
}