//=== christies.com javascript API, compiled 9 March 2007 by Tyler Peterson

//add an onload event without overwriting existing onload events
function addOnLoadEvent(onloadToAdd){
	var prevOnLoad = window.onload;	
	if(typeof window.onload != 'function'){
		window.onload = onloadToAdd;
	} else {
		window.onload = function(){
		if(prevOnLoad){
			prevOnLoad();
		}
		onloadToAdd();
		}
	}

}

//add indexOf for arrays for clients without javascript 3 support
if(!Array.indexOf){
	Array.prototype.indexOf = function(obj, start){
	for(var i=(start||0); i<this.length; i++){
		if(this[i]==obj){
			return i;
		}
	}
	}
}

// Global variables
var isCSS, isW3C, isIE4, isNN4, isIE6CSS;

// initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
    }
}
addOnLoadEvent(initDHTMLAPI);

// Convert object name string or object reference into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}

// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0;
            theObj.left = x + units;
            theObj.top = y + units;
        } else if (isNN4) {
            theObj.moveTo(x,y)
        }
    }
}

// Move an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0;
            theObj.left = getObjectLeft(obj) + deltaX + units;
            theObj.top = getObjectTop(obj) + deltaY + units;
        } else if (isNN4) {
            theObj.moveBy(deltaX, deltaY);
        }
    }
}

// Set the z-order of an object
function setZIndex(obj, zOrder) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.zIndex = zOrder;
    }
}

// Set the visibility of an object to visible
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "visible";
    }
}

// Set the visibility of an object to hidden
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    } 
}

// Set the visibility of an object to hidden
function hide2(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.display = "none";
    } 
}

// Set the display type of an object to hidden
function set_display(obj,disp) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.display = disp;
    } 
}

// Retrieve the x coordinate of a positionable object
function getObjectLeft(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView && document.defaultView.getComputedStyle) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    } else if (elem.style) {
        result = elem.style.left;
    } else if (isNN4) {
        result = elem.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
function getObjectTop(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView && document.defaultView.getComputedStyle) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    } else if (elem.style) {
        result = elem.style.top;
    } else if (isNN4) {
        result = elem.top;
    }
    return parseInt(result);
}

// Retrieve the x coordinate of an object, works better than getObjectLeft but doesn't degrade as well
function findPosX(obj)  {
	var elem = getRawObject(obj);
    var curleft = 0;
    if(elem.offsetParent)
        while(1) 
        {
          curleft += elem.offsetLeft;
          if(!elem.offsetParent)
            break;
          elem = elem.offsetParent;
        }
    else if(elem.x)
        curleft += elem.x;
    return parseInt(curleft);
}

// Retrieve the y coordinate of an object, works better than getObjectLeft but doesn't degrade as well
function findPosY(obj)  {
	var elem = getRawObject(obj);
    var curtop = 0;
    if(elem.offsetParent)
        while(1)
        {
          curtop += elem.offsetTop;
          if(!elem.offsetParent)
            break;
          elem = elem.offsetParent;
        }
    else if(elem.y)
        curtop += elem.y;
    return parseInt(curtop);
}

// Retrieve the rendered width of an element
function getObjectWidth(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetWidth) {
		result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

// Retrieve the rendered height of an element
function getObjectHeight(obj){
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}

// Return the available content width space in browser window
function getInsideWindowWidth() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (isIE6CSS) {
        // measure the html element's clientWidth
        return document.body.parentElement.clientWidth;
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;
}


// Return the available content height space in browser window
function getInsideWindowHeight() {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (isIE6CSS) {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight;
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}

//returns the opacity of a given element
function getOpacity(e){
	var o
	e = getRawObject(e);
	//e = document.getElementById(e);
 	if (e.style.opacity){ // CSS3
		o = parseFloat(e.style.opacity);
	} else if (e.style.filter){ // IE5.5+
		o = e.filters.alpha.opacity / 100;
	} else if (e.style.MozOpacity){ // Gecko before CSS3 support
		o = parseFloat(e.style.MozOpacity);
	} else if (e.style.KhtmlOpacity){ // Konquerer and Safari
		o = parseFloat(e.style.KhtmlOpacity);
	}
	return isNaN(o) ? 100 : o*100;
}

var agt = navigator.userAgent.toLowerCase();


/*
//get the position (x,y) of the mouse
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}

Global variables
xMousePos 		= 0; // Horizontal position of the mouse on the screen
yMousePos 		= 0; // Vertical position of the mouse on the screen

function captureMousePosition(e) {
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}
*/



//extraneous presentational scripts...

//+++++ FADE SCRIPT ++++++, best used on div's rather than text elements because of crappy IE support - may make text appear bold
// initiate fade by calling initImage( IDofElement, endOpacity )

//get the image, and set opacity to zero
var opacity_step 	= 10;  // interval opacity increases by per fadeIn call
var opacity_speed 	= 25; // speed of fadeIn function

function fadeDIV(fade_element, end_op, src_el) {
	if(!document.getElementById) return false;	
		fadeElem = document.getElementById(fade_element);
		
		if(fadeElem){
			//explicitly set width and eight of element to fade to fix IE opacity bug... er, "feature"
			//fadeElem.style.width = getObjectWidth(fadeElem);
			//fadeElem.style.height = getObjectHeight(fadeElem);
			
			//set opacity to 0, then begin iterative fadeIn function
			//if(getOpacity(fadeElem) != 0){
				if (agt.indexOf("safari") != -1){
					fadeElem.style.visibility = 'visible';
					setOpacity(fadeElem, end_op);
				} else {
					
					fadeElem.style.visibility = 'visible';
					setOpacity(fadeElem, 0);
					fadeIn(fade_element,0,end_op);
				}
			//}
		}
}



function shout(source,element){
	var posY = findPosY(source);
	var posX = findPosX(source);
	var feat_height = getObjectHeight(element);
	//shiftTo(element, posX, posY);
	//65
	var new_hgt = 275-feat_height;
	shiftTo(element, 1, new_hgt);
	//alert(posX+', '+posY);
}

function shout2(source,element){
	var posY = findPosY(source);
	var posX = findPosX(source);
	var feat_height = getObjectHeight(element);
	shiftTo(element, posX+40, posY - feat_height);
	//shiftTo(element, posX+40, posY);
	//alert(posX+', '+posY);
}

function showDIV(fade_element, end_op, src_el) {
	if(!document.getElementById) return false;	
		fadeElem = document.getElementById(fade_element);
		
		if(fadeElem){
						
			fadeElem.style.display = 'block';
			
		}
}

function disableSelection() {
	var element = new Array();
	element = document.getElementsByTagName("div");
	
	for(var i=0; i<element.length; i++){
		if(element[i].getAttribute('rel') == 'caption'){
			element[i].onselectstart = function() { return false; };
		    element[i].unselectable = "on";
		    element[i].style.MozUserSelect = "none";
		    element[i].style.cursor = "default";
   		}
	}
}

//iterator to call setOpacity
function fadeIn(objId,opacity,end_op) {
	if(!document.getElementById) return false;
    obj = document.getElementById(objId);
	
	if(obj){
		if (opacity <= end_op) {
			setOpacity(obj, opacity);							
				
				//iterate through the childNodes to resolve childNodes from not inheriting updated opacity in IE
				for (var i=0; i<obj.childNodes.length; i++){
					if(obj.childNodes[i].nodeType == 1){			
						setOpacity(obj.childNodes[i], opacity);
					}
				}
		
			opacity += opacity_step;				
			window.setTimeout("fadeIn('"+objId+"',"+opacity+","+end_op+")", opacity_speed);
		}
		
	}
}

//set opacity
function setOpacity(obj, opacity) {
	opacity = (opacity >= 100)?99.999:opacity;
	
	obj.style.filter = "alpha(opacity:"+opacity+")"; 	// IE/Win
	obj.style.KHTMLOpacity = opacity/100; 				// Safari<1.2, Konqueror
	obj.style.MozOpacity = opacity/100;					// Older Mozilla and Firefox
	obj.style.opacity = opacity/100; 					// Safari 1.2, newer Firefox and Mozilla, CSS3
}
