
/**
 * opens the media library in a new window, called from single button
 * @param obj, the clicked html object, usally 'this'
 * @param box String of id of form field to insert the item from library
 * @param url String url of media library to open in new window
 * @param type String special media type for library
 */
var slotCallObject = null;
function openMediaLib(obj, box, url, type)
{
  Element.extend(obj);
  slotCallObject = { name: obj.up('form').name, box: box };
  window.open(url+'?type='+type, 
              'medialib', 
              'width=600,height=400,left=200,top=0,scrollbars=yes,location=yes');
}


/**
 * opens the media library in a new window, called from textile toolbar
 * @param obj, the textile toolbar object Control.Texarea.Toolbar
 * @param url String url of media library to open in new window
 * @param type String special media type for library
 */
var toolbarCallObject = null;
function openMediaLibTextile(obj, url, type)
{
  toolbarCallObject = obj;
  window.open(url+'?type='+type+'&isToolbarCall=true', 
              'medialib', 
              'width=600,height=400,left=200,top=0,scrollbars=yes,location=yes');
}



/**
 * gets called by medialib/externalView to link an image from library to input field
 * @param String fileId db id of file
 * @param String fileName complete path+file of attached file
 */ 
function attachImageFromMediaLib(fileId, fileName)
{
  // medialib was opened by textile button -> hand over the image path to textile toolbar
  if(opener.toolbarCallObject) {
    opener.toolbarCallObject.insertAfterSelection('!'+fileName+'!');
  }
  // medialib opened the standard way -> attach image id to calling form field
  else if(opener.slotCallObject) {
    opener.document[opener.slotCallObject.name][opener.slotCallObject.box].value = fileId;
  }
  opener.toolbarCallObject = null;
  opener.slotCallObject = null;
  self.close();
}




/**
 * redirects the browser to the current site
 * used to break out of ajax requests on session timeouts
 */
function redirectLogin()
{
  var loc = document.location;
  document.location = loc;
}


/**
 * function to browse through actors 
 * for the carousel on home page
 */ 
function buttonStateHandler(button, enabled) 
{
  if (button == "prev-arrow") {
    $('prev-arrow').src = enabled ? "../images/layout/left3-enabled.gif" : "../images/layout/left3-disabled.gif";
  } else { 
    $('next-arrow').src = enabled ? "../images/layout/right3-enabled.gif" : "../images/layout/right3-disabled.gif";
  }
}


/**
 * function to browse through actors 
 * for the carousel on home page
 */  
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});
  }
}
