var lOriginalHeight = 0;
var lOriginalWidth = 0;
var bScaleImage = true;

window.onerror = window_error;

function window_error() {
	return true;
}

function ScrollTop() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement &&
      ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function ClientHeight() {
	var lClientHeight;

	if (is_ie) {
		lClientHeight = document.body.clientHeight;
		if (is_mac) {
			lClientHeight = lClientHeight - 4;
		}
	} else {
		lClientHeight = window.innerHeight - 4;
	}

	if (lClientHeight < 100) {
		lClientHeight = 100;
	}
	
	//if (document.body.childNodes[0].name == 'dvTitleBar') {
		return lClientHeight - 35;//(document.body.childNodes[0].offsetHeight) -4;
	//} else {
	//	return lClientHeight;
	//}
}

function ClientWidth() {
	var lClientWidth;

	if (is_ie) {
		lClientWidth = document.body.clientWidth;
		if (is_mac) {
			lClientWidth = lClientWidth - 4;
		}
	} else {
		// old height was 324, now 210
		if ((window.innerHeight + window.scrollMaxY) > 210) { 		
			lClientWidth = window.innerWidth - 35;
		} else {
			lClientWidth = window.innerWidth - 8;
		}
	}

	if (lClientWidth < 100) {
		lClientWidth = 100;
	}
	return lClientWidth;
}

function GetImageRatio() {
	var dHeightRatio = 0.0;
	var dWidthRatio = 0.0;
	var lClientHeight = 0;
	var lClientWidth = 0;

	dHeightRatio = lOriginalHeight / (ClientHeight() - 0);
	dWidthRatio = lOriginalWidth / (ClientWidth() - 0);

	return dWidthRatio > dHeightRatio ? dWidthRatio : dHeightRatio;
	//return dWidthRatio;
}

function window_resize() {
	var oImage = document.getElementById('oImage');
	var oContent = document.getElementById('oContent');
	
	if (oImage) {
		image_resize(oImage);
		return;
	}
	
	if (oContent) {
		content_resize(oContent);
		return;
	}
	

}
function content_resize(oContent) {
	var lHeight;
	var lWidth;
	var lTmp = 0;
	
	if (is_gecko) {
		oContent.parentNode.style.width = ClientWidth() + 'px';
	}

	lOriginalHeight = oContent.offsetHeight;
	lOriginalWidth = oContent.offsetWidth;
	
	lHeight = lOriginalHeight;
	lWidth = lOriginalWidth;
	//alert('nothing');
	//oContent.style.background='purple';
	//oContent.style.border='solid 4px green';
}

function image_resize(oImage) {
	if (lOriginalHeight == 0 || lOriginalWidth == 0) {
		lOriginalHeight = oImage.height;
		lOriginalWidth = oImage.width;
	}
	
	var lHeight = lOriginalHeight;
	var lWidth = lOriginalWidth;
	var dRatio = 0.0;

	if (is_gecko) {
		oImage.style.left = '-1000px';
		oImage.style.top = '-1000px';
	}

	if (bScaleImage) {
		dRatio = GetImageRatio();

		lHeight = Math.round(lOriginalHeight / dRatio);
		lWidth = Math.round(lOriginalWidth / dRatio);

		oImage.style.height = lHeight + 'px';
		oImage.style.width = lWidth + 'px';
	}

	oImage.style.left = (Math.floor((ClientWidth() - lWidth) / 2) + (is_gecko || is_opera || is_mac ? 4 : 0)) + 'px';
	var lTop = (Math.floor((ClientHeight() - lHeight) / 2) + (is_gecko || is_opera || is_mac ? 2 : 0))
	//oImage.style.top = (lTop < 16 ? 16 : lTop) + 'px';
	oImage.style.top = lTop + 'px';
}

function ImageError(oErrorImage) {
	oErrorImage.src = 'http://clipmarks.com/images/notfound.gif';
	oErrorImage.height = 68;
	oErrorImage.width = 264;
	lOriginalHeight = 68;
	lOriginalWidth = 264;
	bScaleImage = false;
	return false;
}


function BookmarkDelicious(sArgs) {
	window.open('http://del.icio.us/post?v=3&noui=yes&jump=close&' + sArgs,'delicious','toolbar=no,width=700,height=260');
}


