
// FUNCTION TO PRELOAD IMAGES
function imgPreload () {
	for (i = 0; i < arguments.length; i ++) {
		preloader = new Image();
		preloader.src = "images/" + arguments[i];
	}
}

// CALL TO IMAGE PRELOAD FUNCTION
imgPreload (
	"MO_next_image_arrow.gif",
	"MO_previous_image_arrow.gif",
	"MO_to_start_arrow.gif",
	"MO_to_end_arrow.gif"
);


//  FUNCTION TO INSERT mailto: LINK HREF (onmouseover)
function mm(mmlink) {
	mm_dex = "com";
	mm_dom = mm_uzr = "mofaha";
	mm_dot = ".";
	mm_at = "@";
	mmlink.href = "mailto:" + mm_uzr + mm_at + mm_dom + mm_dot  + mm_dex;
}

//  FUNCTION TO TOGGLE margin OF sobo_icon CLASS (onmouseover)
function sobo_mo (theElement) {
	theImage = theElement.firstChild;
	if ( theImage.style.width == "16px" || theImage.style.width == 0 ) {
		theImage.style.width = theImage.style.height = "18px";
		theImage.style.margin = " 0px 1px 0px 1px";
	} else {
		theImage.style.width = theImage.style.height = "16px";	
		theImage.style.margin = " 2px 2px 0px 2px";
	}
}

//  FUNCTION TO SET EXTERNAL LINKS TO target=_blank (onload)		
function externalLinks() {  
	var anchors = document.getElementsByTagName("a");  
	for (var i=0; i<anchors.length; i++) {  
		var anchor = anchors[i]; 
		if ( ( anchor.getAttribute("href") && anchor.getAttribute("rel") ) && anchor.getAttribute("rel").indexOf("external") > -1 ) {
			anchor.target = "_blank";
		}
	}  
}  

//  FUNCTION TO SET CURRENT PAGE NAV LINK PROPERTIES
function  selectLink () {
	if ( document.location.pathname !== "/" && document.location.pathname !== "/index.php"  ) {
		listElementArray = document.getElementsByTagName("LI");
		var is_blog_page = document.location.pathname.indexOf("blog") + 1;
		for ( i = 0; i < listElementArray.length; i ++ ) {
			var is_blog_link = listElementArray[i].firstChild.pathname.indexOf("blog") + 1;
			if ( listElementArray[i].firstChild.pathname === document.location.pathname || "/" + listElementArray[i].firstChild.pathname === document.location.pathname || ( is_blog_link && is_blog_page ) ) {
				accordionIndex = listElementArray[i].parentNode.getAttribute("id").substr(5) - 1;
				$("#nav_container").accordion( "activate" , accordionIndex );
				if ( accordionIndex === 0 ) {
					listElementArray[i].firstChild.style.color = "#707070";
				} else if ( accordionIndex === 1 ) {
					listElementArray[i].firstChild.style.color = "#e0e0e0";	
				} else {
					listElementArray[i].firstChild.style.color = "#909090";					
				}
				i = listElementArray.length;
			}
		}
	}
}

// WINDOW ONLOAD
window.onload = function () {
	externalLinks();
	selectLink();
	if ( typeof fadeinpane === "function" ) {
		fadeinpane();
	}
}
