// ==|JS Common Lib |=================================================== //
// ==|Author : Tom Wilson|============================================== //
// ~~|Inital Functions|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //

// ++|FUNCTIONS IN LIB|+++++++++++++++++++++++++++++++++++++++++++++++++ //

// >>|unObJS()|========================================================= //
// ~~|Desc: This boy appends JS to HTML unobtrusivly, No messy JS.|~~~~~ //

// ++|END: FUNCTIONS IN LIB|++++++++++++++++++++++++++++++++++++++++++++ //




// ~~|UnObtrusive Check|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// ~~|This function allows you appened Javascript to Elements without |~ //
// ~~|_going into HTML|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //

function unObJS() {
  //makes sure there is tags around.
  if (!document.getElementsByTagName) return false;
  
  //Puts all Link tags into an Array
  var links=document.getElementsByTagName("a");
  
  //Loop for Rollover Class
  //Loops through the array to find
  for (var i=0; i < links.length; i++) {
  	
  //Search for A tags with a specific Class name
	if (links[i].className.match("rollover")) {
  
  // If the link is there, creates a function on that element.
  // The Function.
  		//Pre Loads the Images
		var varImgPath = links[i].firstChild.src;
		var strImg = varImgPath.substring(varImgPath.lastIndexOf('/') + 1);
		var fileExt = strImg.substring(strImg.lastIndexOf('.'));
		var fileName = strImg.replace(fileExt, '');
  		ImagePre = new Image(1,1)
		ImagePre.src = "http://blog.sharedreviews.com/wp-content/themes/shared-reviews/images/" + fileName + "_ovr" + fileExt;
		
		//Creates Rollover Function to Swap Images
	  links[i].onmouseover=function() {
			var varImgPath = this.firstChild.src;
			var strImg = varImgPath.substring(varImgPath.lastIndexOf('/') + 1);
			var fileExt = strImg.substring(strImg.lastIndexOf('.'));
			var fileName = strImg.replace(fileExt, '');
			this.firstChild.src = "http://blog.sharedreviews.com/wp-content/themes/shared-reviews/images/" + fileName + "_ovr" + fileExt;
			return false;
      }
		
		//Creates Rollover Function to Swap Images Back
	  links[i].onmouseout=function() {
			var varImgPath = this.firstChild.src;
			var strImg = varImgPath.substring(varImgPath.lastIndexOf('/') + 1);
			var fileExt = strImg.substring(strImg.lastIndexOf('.'));
			var fileName = strImg.replace("_ovr" + fileExt, '');
			this.firstChild.src = "http://blog.sharedreviews.com/wp-content/themes/shared-reviews/images/" + fileName + fileExt;
			return false;
      }
    }
  }

  
  //Loop for Popups at the bottom
  var popups=document.getElementsByTagName("LI");
  //Loops through the array to find
  for (var i=0; i < popups.length; i++) {
  //Search for A tags with a specific Class name
	if (popups[i].className.match("PopHere")) {
  // If the link is there, creates a function on that element.
  // The Function.
	   popups[i].onmouseover=function() {
			divBlock = this.getElementsByTagName("div")
			divBlock[0].style.display = "block";
			return false;
      }
	   popups[i].onmouseout=function() {
			divBlock = this.getElementsByTagName("div")
			divBlock[0].style.display = "none";
			return false;
      }
    
	 }
  }
}

// OnLoad Call to start the JS appending.
window.onload=unObJS;


