function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function imageSwap()
{
	var entry_thumb = getElementsByClassName("entry_wrap");
	for(var i=0; i < entry_thumb.length; i++)
	{
		entry_thumb[i].onmouseover = function()
		{
			var photo = this.getElementsByTagName("img")[0];
			photo.className = "nopic";
		}
		entry_thumb[i].onmouseout = function()
		{
			var photo = this.getElementsByTagName("img")[0];
			photo.className = "showpic";
		}
	}
}

function showText() {

	if (document.getElementById("moretext")) {
		var textLink = document.getElementById("moretextlink");
		var moreText = document.getElementById("moretext");
		var moreTextOuter = document.getElementById("moretextouter");
	
		this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body; //create reference to common "body" across doctypes
		var scrollbarwidth = 16;
		var ie = document.all && !window.opera;
		var dom = document.getElementById;
		var scroll_top = (ie)? this.standardbody.scrollTop : window.pageYOffset;
		var scroll_left = (ie)? this.standardbody.scrollLeft : window.pageXOffset;
		var docwidth = (ie)? this.standardbody.clientWidth : window.innerWidth-scrollbarwidth;
		var docheight = (ie)? this.standardbody.clientHeight: window.innerHeight;
		var docheightcomplete = (this.standardbody.offsetHeight>this.standardbody.scrollHeight)? this.standardbody.offsetHeight : this.standardbody.scrollHeight; //Full scroll height of document
		var objwidth = moreText.offsetWidth; //width of div element
		var objheight = moreText.offsetHeight; //height of div element
		var topposition = (docheight>objheight)? scroll_top+docheight/2-objheight/2+"px" : scroll_top+0+"px"; //Vertical position of div element: Either centered, or if element height larger than viewpoint height, 10px from top of viewpoint
	
		textLink.onclick = function() {
			moreTextOuter.style.visibility = "visible";
			moreText.style.visibility = "visible";
			moreText.style.left = docwidth/2-objwidth/2+"px" //Center div element horizontally
			moreText.style.top = Math.floor(parseInt(topposition))+"px"
			return false;
		}
	
		moreTextOuter.onclick = function() {
			moreText.style.visibility = "hidden";
			moreTextOuter.style.visibility = "hidden";
		}
	}
}

addLoadEvent(imageSwap);
addLoadEvent(showText);

// Use (window).load instead of document.(ready) to make the function fire in WebKit browsers.
// Waits for all images to load, unlike document.(ready).
jQuery(window).load(function() {
	var width = 0;
	jQuery('#homeimagewrap img').each(function() {
		width += jQuery(this).outerWidth( true );
	});
	width = Math.ceil(width * 1.001);
	jQuery('#homeimagewrap').css('width', width);
	var rightPosition = jQuery('#homeimagewrap').css('right');
/*	jQuery('#homeimagewrap img').each(function() {
		width += 0.966 * Math.ceil((jQuery(this).outerWidth( true )));
	});
	width = Math.ceil(width * 1.001);
	var wrapHeight = jQuery('#homeimagewrap').height();
	var newRight = -0.8 * wrapHeight;
	newRight += 'px';
	jQuery('#homeimagewrap').css({'width' : width, 'right' : newRight});
*/

/*	var aspect = jQuery(window).width() / jQuery(window).height();
	if (aspect < 1.33) {
		width = width * 1.001;
	}
	else if (aspect >= 1.35 && aspect < 2.00) {
		width = width * 0.983;
	}
	else if (aspect >= 2.00 && aspect < 2.50) {
		width = width * 0.979;
	}
	else if (aspect >= 2.50) {
		width = width * 0.975;
	}
	width = Math.ceil(width);
	jQuery('#homeimagewrap').css('width', width); */
});

jQuery(window).resize(function() {
	var width = 0;
	jQuery('#homeimagewrap img').each(function() {
		width += jQuery(this).outerWidth( true );
	});
	width = Math.ceil(width * 1.001);
	jQuery('#homeimagewrap').css('width', width);
});
