/****************************
 * Picon theme for Gallery2
 * @author Dominic Search <code(a)photographicon.com>
 * $Revision: 1.1 $ $Date: 2006/01/29 00:37:27 $
 */

/**************
 * Returns an object reference to element 'id'.
 */
var ie4 = false; if(document.all) { ie4 = true; }
function getObject(id) { 
  if (ie4) { 
    return document.all[id]; 
  } else { 
    return document.getElementById(id); 
  } 
}

/*****************************
 * Text Block Hide/Show Routines by Dominic Search <code(a)photographicon.com>
 * Uses the "style.display" property to maintain hide/show state within a page,
 * and uses a session cookie to maintain hide/show state across the whole site.
 * Below is the basename for that cookie.
 */
var cnameroot = 'G2_picon_text';

/**************
 * Initialise the block on first display of page.
 * Parameters:
 *      divId        Element containing the text to show/hide,
 *      initval      Initial value (0 = hide , 1 = show) to use if no cookie exists.
 */
function text_init(divId,initval) { 
  /* try using cookie setting */
  var cval = getCookieValue(cnameroot+'_'+divId);
  if (cval == '1') { 
    text_on(divId);
  } else if (cval == '0') {
    text_off(divId);
  } else {
    /* no cookie exists, so use supplied initval */
    if (initval == '1') {
      text_on(divId);
    } else {
     text_off(divId);
    }
  } 
}

/**************
 * Toggle the block between hide/show.
 * Parameters:
 *      divId        Element containing the text to show/hide,
 */
function text_toggle(divId) { 
  var d = getObject(divId);
  if (d.style.display == 'none') { 
    text_on(divId);
  } else { 
    text_off(divId);
  } 
}

/**************
 * Show the block.
 * Parameters:
 *      divId        Element containing the text to show/hide,
 *                   note the corresponding divid'_link' element contains the descriptive link text.
 */
function text_on(divId) { 
  var d = getObject(divId);
  d.style.display="block";
  var zlink = divId+'_link';
  ui_sethtml(zlink, '[-] less information'); 
  writeSessionCookie(cnameroot+'_'+divId, '1');
}

/**************
 * Hide the block.
 * Parameters:
 *      divId        Element containing the text to show/hide,
 *                   note the corresponding divid'_link' element contains the descriptive link text.
 */
function text_off(divId) { 
  var d = getObject(divId);
  d.style.display="none";
  var zlink = divId+'_link';
  ui_sethtml(zlink, '[+] more information'); 
  writeSessionCookie(cnameroot+'_'+divId, '0');
}

/*****************************
 * Support routines for Text Block Hide/Show
 * Squirt 'html' into the page element 'id'.
 */
function ui_sethtml(id,html) {
  document.getElementById(id).innerHTML = html;
}

/*****************************
 * Routine to write a session cookie. (see www.braemoor.co.uk/software)
 *
 * Parameters:
 *      cookieName        Cookie name
 *      cookieValue       Cookie Value
 *
 *  Return value:
 *      true              Session cookie written successfullly
 *      false             Failed - persistent cookies are not enabled
 */
function writeSessionCookie (cookieName, cookieValue) {
  if (testSessionCookie()) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
  }
  else return false;
}

/*****************************
 * Routine to get the current value of a cookie. (see www.braemoor.co.uk/software)
 *
 * Parameters:
 *      cookieName        Cookie name
 *
 *  Return value:
 *      false             Failed - no such cookie
 *      value             Value of the retrieved cookie
 */
function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

/*****************************
 * Routine to see if session cookies are enabled. (see www.braemoor.co.uk/software)
 *
 *  Return value:
 *      true              Session cookies are enabled
 *      false             Session cookies are not enabled
 */
function testSessionCookie () {
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true 
  else
    return false;
}

/*****************************
 */
