// main javascript functions for Elysian films web site



/* ***********************************************************
Example 4-5 (DHTMLapi.js)
"Dynamic HTML:The Definitive Reference"
by Danny Goodman
Published by O'Reilly & Associates  ISBN 1-56592-494-0
http://www.oreilly.com
Copyright 1998 Danny Goodman.  All Rights Reserved.
************************************************************ */
// DHTMLapi.js custom API for cross-platform
// object positioning by Danny Goodman (http://www.dannyg.com)

// Global variables
var isNav, isIE
var coll = ""
var styleObj = ""
if (parseInt(navigator.appVersion) >= 4) {
  if (navigator.appName == "Netscape") {
    isNav = true
  } else {
    isIE = true
    coll = "all."
    styleObj = ".style"
  }
}

// Convert object name string or object reference
// into a valid object reference
function getObject(obj) {
  var theObj
  if (typeof obj == "string") {
    theObj = eval("document." + coll + obj + styleObj)
  } else {
    theObj = obj
  }
  return theObj
}

// Positioning an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.moveTo(x,y)
  } else {
    theObj.pixelLeft = x
    theObj.pixelTop = y
  }
}

// Moving an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.moveBy(deltaX, deltaY)
  } else {
    theObj.pixelLeft += deltaX
    theObj.pixelTop += deltaY
  }
}

// Setting the z-order of an object
function setZIndex(obj, zOrder) {
  var theObj = getObject(obj)
  theObj.zIndex = zOrder
}

// Setting the background color of an object
function setBGColor(obj, color) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.bgColor = color
  } else {
    theObj.backgroundColor = color
  }
}

// Setting the visibility of an object to visible
function show(obj) {
  var theObj = getObject(obj)
  theObj.visibility = "visible"
}

// Setting the visibility of an object to hidden
function hide(obj) {
  var theObj = getObject(obj)
  theObj.visibility = "hidden"
}

// Retrieving the x coordinate of a positionable object
function getObjectLeft(obj)  {
  var theObj = getObject(obj)
  if (isNav) {
    return theObj.left
  } else {
    return theObj.pixelLeft
  }
}

// Retrieving the y coordinate of a positionable object
function getObjectTop(obj)  {
  var theObj = getObject(obj)
  if (isNav) {
    return theObj.top
  } else {
    return theObj.pixelTop
  }
}

// Utility function returns the available content width space in browser window
function getInsideWindowWidth(){
  if (isNav) {
    return window.innerWidth
  } else {
    return document.body.clientWidth
  }
}
// Utility function returns the available content height space in browser window
function getInsideWindowHeight() {
  if (isNav) {
    return window.innerHeight
  } else {
    return document.body.clientHeight
  }
}


// mta stuff
function spacer(x,y){
  document.write("<img src='images/5x5.gif' width=" + x + " height=" + y + ">");
}
function spacer2(x,y){
  document.write("<img src='../images/5x5.gif' width=" + x + " height=" + y + ">");
}






/* *********************************************************** */
// MTA new stuff



// procs fo allow pages wrongly called outside of frames to reposition themselves

function BreakOutOfFrames(){
  if (window != top) top.location.href = location.href;
}






var ImageNames=new Array(
"pics/11.jpg",
"pics/13.jpg",
"pics/14.jpg",
"pics/15.jpg",
"pics/16.jpg",
"pics/17.jpg",
"pics/18.jpg",
"pics/19.jpg",
"pics/2.jpg",
"pics/20.jpg",
"pics/21.jpg",
"pics/22.jpg",
"pics/23.jpg",
"pics/24.jpg",
"pics/25.jpg",
"pics/26.jpg",
"pics/27.jpg",
"pics/3.jpg",
"pics/5x5.gif",
"pics/abraham.jpg",
"pics/abraham_burns_sandras_things.jpg",
"pics/abraham_confronts.jpg",
"pics/abraham_gun.jpg",
"pics/abraham_gun2.jpg",
"pics/abraham_sandra.jpg",
"pics/abraham_sandra2.jpg",
"pics/abraham_sannie_home_affairs.jpg",
"pics/abraham_search.jpg",
"pics/alicekrige.jpg",
"pics/alicekrige2.jpg",
"pics/bati1.jpg",
"pics/bati2.jpg",
"pics/bati3.jpg",
"pics/celia_and_rafi_in_flat_2.jpg",
"pics/damien_directing_3.jpg",
"pics/im484.jpg",
"pics/joe_and_rafi_shopped.jpg",
"pics/lara_taking_pic_1.jpg",
"pics/petrus-sandra-w",
"pics/samneill0.jpg",
"pics/samneill2.jpg",
"pics/sandra_and_parents.jpg",
"pics/sandra_and_sannie_reunite.jpg",
"pics/sandra_magistrate.jpg",
"pics/sandra_petrus.jpg",
"pics/sandra_petrus2.jpg",
"pics/sandra_rebuilding.jpg",
"pics/sandra_visits-tr.jpg",
"pics/sandra_visits.jpg",
"pics/sannie_and_adriaan_watch.jpg",
"pics/sannie_young_sandra.jpg",
"pics/sannie_young_sandra2.jpg",
"pics/scarred.jpg",
"pics/skin-tr.jpg",
"pics/skin-trio-pic-w",
"pics/skin10.jpg",
"pics/skin13-w80.jpg",
"pics/skin14-w90.jpg",
"pics/skin15-w105.jpg",
"pics/skin16.jpg",
"pics/skin3.jpg",
"pics/skin4.jpg",
"pics/skin5.jpg",
"pics/snow01.jpg",
"pics/snow02.jpg",
"pics/snow03.jpg",
"pics/snow04.jpg",
"pics/snow05.jpg",
"pics/snow06.jpg",
"pics/sophie_kaylim_fanisa-tall.jpg",
"pics/sophie_kaylim_fanisa.jpg",
"pics/sophieokonedo0.jpg",
"pics/sophieokonedo2.jpg",
"pics/sophie_baby.jpg",
"pics/sunday_lunch.jpg",
"pics/three_sandras.jpg",
"pics/tiger01.jpg",
"pics/tiger01b.jpg",
"pics/tiger02.jpg",
"pics/tiger03.jpg",
"pics/tiger04.jpg",
"pics/tiger05.jpg",
"pics/tonyfabian.jpg",
"pics/tonysm.jpg",
"pics/while03.jpg",
"pics/while05.jpg",
"pics/while06.jpg",
"pics/while08.jpg",
"pics/while09.jpg",
"pics/while12.jpg",
"pics/while15.jpg",
"pics/while17.jpg",
"pics/while21.jpg",
"pics/young_sandra_bullied.jpg");

var ImagesArray=new Array(ImageNames.length);
var LastImageLoaded;

function PreloadImages(time){
  var TimeNow=new Date();
  var EndTime=TimeNow.getSeconds()+time;
  LastImageLoaded=0;

  var lim=ImageNames.length;

  var NotTimedOut=1;

  for(i=0;(i<lim && NotTimedOut); i++){
   ImagesArray[i]=new Image();
   ImagesArray[i].src=ImageNames[i];
   TimeNow=new Date();
   if(TimeNow.getSeconds()>EndTime)NotTimedOut=0;
   LastImageLoaded++;
  }
}



var LongLim=100;
var ShortLim=60;

function onLoadProc(time){PreloadImages(time);}



// function to force very soft reloading of pages when browser resizes

function onResizeProc(){window.history.go(0);}







// function to get the width of an element by using its ID
// (e.g.   <div class=menu2 id=menuitem2> becomes getWidthOfID("menuitem2")

// function re-defined as IE sometimes returning 0, and getElementByID now standard

//function getWidthOfID(ID){
//  if(arguments.length!=1)alert("Wrong number of arguments to getWidthOfID()");
//  var ns6=document.getElementById&&!document.all
//  var ie=document.all
//
//  if((!ie)&&(!ns6)){
//    var AlertStr="Alert you appear to be running an outdated browser. ";
//    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
//    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
//    alert(AlertStr);
//  }
//
//  if(ns6){
//    return(document.getElementById(ID).offsetWidth);
//  }
//
//  if(ie){
//    return(eval("document.all." + ID + ".clientWidth"));
//  }
//
//  return(50);
//}

function getWidthOfID(ID){
  if(arguments.length!=1)alert("Wrong number of arguments to getWidthOfID()");
  var retval=document.getElementById(ID).offsetWidth;
  if(retval==0)alert("Width of " + ID + " returning as zero");
  return(retval);
}





// function to get the height of an element by using its ID
// (e.g.   <div class=menu2 id=menuitem2> becomes getHeightOfID("menuitem2")

// function re-defined as IE sometimes returning 0, and getElementByID now standard

//function getHeightOfID(ID){
//  if(arguments.length!=1)alert("Wrong number of arguments to getHeightOfID()");
//  var ns6=document.getElementById&&!document.all
//  var ie=document.all
//
//  if((!ie)&&(!ns6)){
//    var AlertStr="Alert you appear to be running an outdated browser. ";
//    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
//    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
//    alert(AlertStr);
//  }
//
//  if(ns6){
//    return(document.getElementById(ID).offsetHeight);
//  }
//
//  if(ie){
//    return(eval("document.all." + ID + ".clientHeight"));
//  }
//
//  return(50);
//}


function getHeightOfID(ID){
//alert("ID: " + ID);
  if(arguments.length!=1)alert("Wrong number of arguments to getHeightOfID()");
  var retval=document.getElementById(ID).offsetHeight;
  if(retval==0)alert("Height of " + ID + "returning as zero");
  return(retval);
}



// function to get the offsetLeft of an element by using its ID
// (e.g.   <div class=menu2 id=menuitem2> becomes getoffsetLeftOfID("menuitem2")

function getoffsetLeftOfID(ID){
  if(arguments.length!=1)alert("Wrong number of arguments to getoffsetLeftOfID()");
  var ns6=document.getElementById&&!document.all
  var ie=document.all

  if((!ie)&&(!ns6)){
    var AlertStr="Alert you appear to be running an outdated browser. ";
    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
    alert(AlertStr);
  }

  if(ns6){
    return(document.getElementById(ID).offsetLeft);
  }

  if(ie){
    return(eval("document.all." + ID + ".offsetLeft"));
  }

  return(50);
}



// function to get the offsetTop of an element by using its ID
// (e.g.   <div class=menu2 id=menuitem2> becomes getoffsetTopOfID("menuitem2")

function getoffsetTopOfID(ID){
  if(arguments.length!=1)alert("Wrong number of arguments to getoffsetTopOfID()");
  var ns6=document.getElementById&&!document.all
  var ie=document.all

  if((!ie)&&(!ns6)){
    var AlertStr="Alert you appear to be running an outdated browser. ";
    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
    alert(AlertStr);
  }

  if(ns6){
    return(document.getElementById(ID).offsetTop);
  }

  if(ie){
    return(eval("document.all." + ID + ".offsetTop"));
  }

  return(50);
}






function getInnerHTML(ID){
  if(arguments.length!=1)alert("getInnerHTML needs 1 argument");

  var ns6=document.getElementById&&!document.all
  var ie=document.all

  if(ie){
    return(eval("document.all." + ID + "innerHTML"));
    }
  else{
    if(ns6){
      return(document.getElementById(ID).innerHTML);
    }
  }
}



function skin_content(page){
  if(arguments.length!=1)alert("skin_content needs 1 argument");

  var ns6=document.getElementById&&!document.all
  var ie=document.all

  if(ie){
    document.all.col2.innerHTML=skincontent["p" + page + "col2"];
    document.all.col3.innerHTML=skincontent["p" + page + "col3"];
    }
  else{
    if(ns6){
      document.getElementById("col2").innerHTML=skincontent["p" + page + "col2"];
      document.getElementById("col3").innerHTML=skincontent["p" + page + "col3"];
    }
  }
}



function blat(classdesc){
  if(arguments.length==0)alert("blat must be called with a class descriptor or empty string argument");
  str="ton" + "y@e" + "lysia" + "nfil" + "ms." + "com";
  document.write("<A class=" + classdesc + " href='mailto:" + str + "'>" + str + "</a>");
}

function blatm(classdesc){
  if(arguments.length==0)alert("blat must be called with a class descriptor or empty string argument");
  str="marg" + "are" + "t@b" + "ardent" + "ertai" + "nment" + "s.c" + "o.uk";
  document.write("<A class=" + classdesc + " href='mailto:" + str + "'>" + str + "</a>");
}


function blatg(classdesc){
  if(arguments.length==0)alert("blat must be called with a class descriptor or empty string argument");
  str="Gen" + "eviev" + "e@m" + "oonl" + "ightin" + "g.c" + "o.za";
  document.write("<A class=" + classdesc + " href='mailto:" + str + "'>" + str + "</a>");
}


function blatl(classdesc){
  if(arguments.length==0)alert("blat must be called with a class descriptor or empty string argument");
  str="lst" + "ille" + "@p" + "aradi" + "gm-a" + "gency.c" + "om";
  document.write("<A class=" + classdesc + " href='mailto:" + str + "'>" + str + "</a>");
}



function blatgen(classdesc){
  if(arguments.length==0)alert("blat must be called with a class descriptor or empty string argument");
  var i;
  var str="";

  for(i=1;i<arguments.length;i++){
    str+=arguments[i];
  }
  document.write("<A class=" + classdesc + " href='mailto:" + str + "'>" + str + "</a>");
}





// function to turn visibility on and off for a given element
// syntax: setvisibility([element id] [visibility status (hidden|visible)]))

function setvisibility(element,status){
//alert("setvisibility: element " + element + ", status: " + status);
  if(arguments.length!=2)alert("two arguments needed: [element id] [visibility status (hidden|visible)]");
  var ns6=document.getElementById&&!document.all
  var ie=document.all
  var ele;

  if(ie){
    ele=(eval("document.all." + element));
    }
  else{
    if(ns6){
      ele=(document.getElementById(element));
    }
  }
  ele=ele.style;
  ele.visibility=status;
}


// function to set color for a given element
// syntax: setcolor ([element id] [color]

function setcolor(element,color){
//alert("setcolor: element " + element + ", color: " + color);
  if(arguments.length!=2)alert("two arguments needed: [element id] [color]");
  var ns6=document.getElementById&&!document.all
  var ie=document.all
  var ele;

  if(ie){
    ele=(eval("document.all." + element));
    }
  else{
    if(ns6){
      ele=(document.getElementById(element));
    }
  }
  ele=ele.style;
  ele.color=color;
}



// function to switch content for filmography
// if this has no arguments it selects the default (initial) text

var filmograph_array=new Array(
"film0",
"film1",
"skin",
"whilethe",
"prick",
"harmony",
"township",
"total",
"jean",
"candy",
"renee",
"angela",
"ilturco",
"pavarotti",
"christophe",
"cecilia",
"jeanyves",
"joshua",
"olli",
"bach");


// function to set the rhspacer image to be the same depth as the
// revealed text: so that the table scrolls properly

function SetRHspacefromID(ID){
  var height=getHeightOfID(ID);

  // this is a dirty hack to pick up depth of RH Skin cell
  //if(ID.indexOf("skin")==0)height=getHeightOfID("SkinInner");

  if(height<350)height=350; // to allow for main image on left at start

  var rhsp;

  var ns6=document.getElementById&&!document.all
  var ie=document.all

  if((!ie)&&(!ns6)){
    var AlertStr="Alert you appear to be running an outdated browser. ";
    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
    alert(AlertStr);
  }

  if(ns6){
    rhsp=document.getElementById("rhspacer");
  }

  if(ie){
    rhsp=eval("document.all." + "rhspacer");
  }
  rhsp.innerHTML="<img src='pics/5x5.gif' height=" + height + " width=1>"
}


// proc to set innerhtml of an element

//function SetInnerHTML(ID,str){
//
//  var ns6=document.getElementById&&!document.all
//  var ie=document.all
//  var objfound;
//
//  if((!ie)&&(!ns6)){
//    var AlertStr="Alert you appear to be running an outdated browser. ";
//    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
//    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
//    alert(AlertStr);
//  }
//
//  if(ns6){
//    objfound=document.getElementById("rhspacer");
//  }
//
//  if(ie){
//    objfound=eval("document.all." + "rhspacer");
//  }
//  objfound.innerHTML=str;
//}

function SetInnerHTML(ID,str){
  var objfound;
  objfound=document.getElementById(ID);
  objfound.innerHTML=str;
}



function film_content(){
  var i;
  for(i=0;i<filmograph_array.length;i++){
// alert("film_content, i: [" + i + "] filmograph_array[i]: [" +  filmograph_array[i] + "]");
    setvisibility(filmograph_array[i],"hidden");
  }
//  if(arguments.length>0){
//    location.search=arguments[0];
//    }
//  else{
//    location.search="";
//  }
  var searchstr="";
  if(arguments.length>0){
    searchstr=arguments[0];
  }
  location.replace(location.pathname + "?" + searchstr);
}


//function change_content(){          // doesn't work under IE/mac
//  if(arguments.length>0){
//    location.search=arguments[0];
//    }
//  else{
//    location.search="";
//  }
//}



function change_content(){
  var searchstr="";
  if(arguments.length>0){
    searchstr=arguments[0];
  }
   location.replace(location.pathname + "?" + searchstr);
}






// cookie stuff to save the filmography page we are on


function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}



function deleteCookie(name){

  var date = new Date();
  date.setTime(date.getTime()-(1*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();

  document.cookie = name+"=empty"+expires+"; path=/";
}


function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function filmog_onLoad(e) {
  var cookie = readCookie("filmpage");
  if((cookie!=null)&&(cookie!="")){
    film_content(cookie);
  }
}




//function to set vspacer to be the height of whichever is the greatest out of a set of ids
// (plus an extra amount as this is height of second row)

// arguments: <name of RHspacer> <id_1> <id_2>...

function SetRHSpacer(){
  var height=0;
  var tmpheight;
  var i;

  for(i=1;i<arguments.length;i++){
    tmpheight=getHeightOfID(arguments[i]);
    if(tmpheight>height)height=tmpheight;
  }
  SetInnerHTML(arguments[0],"<img src='pics/5x5.gif' height=" + height + " width=1>");
}




//function to set vspacer to be the highest of a series of numbers

// arguments: <name of RHspacer> <id_1> <id_2>...

function SetRHSpacerInt(){
  var height=0;
  var tmpheight;
  var i;
  for(i=1;i<arguments.length;i++){
    tmpheight=arguments[i];
    if(tmpheight>height)height=tmpheight;
  }
  height+=10; // deal with the fact that firefox sometimes seems to cut the numbers a bit fine

  SetInnerHTML(arguments[0],"<img src='pics/5x5.gif' height=" + height + " width=1>");
}




var clipwin=null;

function openclip(url,width,height){
  var openwidth=width+40;
  var openheight=height+90;
  var args="height=" + openheight + ",width=" + openwidth + ",screenX=0,screenY=0,location=no,left=0,top=0,resizable=yes,status=no,toolbar=no,scrollbars=yes";
  if(clipwin!=null)clipwin.close();
  clipwin=open(url,"clipwin",args);
}



// stuff to make hrefs change colour when their colour has been set
// from javascript



var basehrefcolor;

function hrefover(ID){
// alert("ID: " + document.getElementById(ID).style.color);
  var obj=document.getElementById(ID);
  basehrefcolor=obj.style.color;
  obj.style.color="#ff6600;"
}

function hrefout(ID){
  document.getElementById(ID).style.color=basehrefcolor;
}


function set_visible_relative(ID){
  sty=document.getElementById(ID).style;
  sty.visibility="visible";
  sty.position="relative";
}

function set_hidden_absolute(ID){
  sty=document.getElementById(ID).style;
  sty.visibility="hidden";
  sty.position="absolute";
}

