//from jennifermadden.com
function getObjectStyle(el,styleProp)
{
    var x = $(el);
    if (x.currentStyle) {
        var y = x.currentStyle[styleProp];
    }
    else if (window.getComputedStyle) {
        var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
    }
    if (!y) {
        // for IE - another way perhaps darryl?
       y = x.style.clip;
    }
    return y;
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && (
        document.documentElement.scrollLeft ||
        document.documentElement.scrollTop )
        ) {
        //IE6 standards compliant
        //mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}

// from quirkmodes.org
function getWindowDimensions() {
    if (self.innerHeight) {
        winwidth = self.innerWidth;
        winheight = self.innerHeight;
        docwidth = document.width;
        docheight = document.height;
        winwidth = winwidth > docwidth ? docwidth : winwidth;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        winwidth = document.documentElement.clientWidth;
        winheight = document.documentElement.clientHeight;
    } else if (document.body) {
        winwidth = document.body.clientWidth;
        winheight = document.body.clientHeight;
    }
    return {'width':winwidth,'height':winheight};
}

// Replace title with image
// intiation of title image elsewhere
// image replacement for h2 page titles - general idea from quirksmode
// not using this as the titles are now on body background.
function titleInitialize() {
    title = document.getElementsByClassName('title')[0];
}

function contentInitialize() {
    // this an attempt to get content div to expand to entire page
    // so that the bg image on bio and materials is correctly positioned
    // with IE
    //alert('content init');
    var cont = $('content');
    var doccont = $('document-content');
    dim = getWindowDimensions();
    //cont.setStyle({'width': dim.width, 'height': dim.height});
    if (typeof fh == 'undefined') {
        fh = dim.height;
        h = dim.height;
    }
    var foot = $('footer');
    var ptest = $('hold'); // photofolder identifier
    if (typeof foot != 'undefined' && typeof ptest == 'undefined') {
        hold = $('holder');
        if (typeof(hold) != 'undefined') {
            if (cont.offsetHeight >= fh) {
                foot.remove(); // calls parent reoveChild
                foothtml = '<div id="footer">'+foot.innerHTML+'</div>';
                //hold.innerHTML = foothtml;
                new Insertion.Top(hold, foothtml);
                foot = $('footer');
                /**foot.setStyle({'position': 'relative', 'text-align':'right'
                               });**/
            }
        }
    }
    //foot.setStyle({'visibility': 'visible'});
}
Event.observe(window, 'load', contentInitialize, false);
Event.observe(window, 'resize', contentInitialize, false );

// helper to collect parameters from query string
function getParameter ( queryString, parameterName ) {
   var parameterName = parameterName + "=";
   if ( queryString.length > 0 ) {
      begin = queryString.indexOf ( parameterName );
      if ( begin != -1 ) {
         begin += parameterName.length;
         end = queryString.indexOf ( "&" , begin );
      if ( end == -1 ) {
         end = queryString.length
      }
      return unescape ( queryString.substring ( begin, end ) );
   }
   return "null";
   }
}

var DisplayWin=null;
function openDisplay(src,w,h) {
    var l=3;
    var t=3;
	if (window.screen) {
		l=screen.width - w - 30;
	}
    src += '/full.html';
	DisplayWin=null;
	prefs="left="+l+","+"top="+t+","+"screenX="+l+","+"screenY="+t+","+"width="+(w+16)+","+"height="+h+","+"innerWidth="+(w+16)+","+"innerHeight="+h+","+"toolbar=no,"+"location=no,"+"directories=no,"+"status=yes,"+"menubar=no,"+"scrollbars=yes,"+"resizable=yes";
	DisplayWin=window.open(src,("display"),prefs);
	DisplayWin.focus();
}
var loaderHtml = '<div id="loader"><p><img src="https://payments.ebizsecure.co.nz/secure/registration/img_cache.asp?url=http://www.barryrosssmith.co.nz/templates/images/loading.gif" /></p>'+
                 '<p>Contacting server, please be patient.</p></div>';
var errorHtml = '<div id="loader"><p>A error has occurred contacting the server.'+
                 ' Please try again later.</p></div>';
// Validation errors
var errorStartTag = '<div class="error">';
var errorEndTag = '</div>';
var errorEmpty = 'This is a required field!';
var errorEmail = 'Please enter a valid email address!';
//Validation routines
isEmpty = function(v) {
    return  ((v == null) || (v.length == 0)); // || /^\s+$/.test(v));
}
validateEmail = function(v) {
    return /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)
}

// make all external links open in new window
externalLinks = function() {
  if ($('document-content')) {
      links = $A($('document-content').getElementsByTagName('a'));
      loc = window.top.location.hostname;
      links.each(function(link) {
        if (link.href.indexOf(loc) == -1) {
            link.setAttribute("target", "_blank");
        }
     });
  }
}
Event.observe(window, 'load', externalLinks, false);
