/* SiteScripts by ZFDesign.net &copy; 2009
Function "largeImages" Replaces content -mobi images with ones for desktop
1. Place the two images in the same folder 
2. Name the mobile version "imagename-mobi" using matching "imagename" for the desktop version 
3. Assign ID attribute to the image container 
Notes: Both images should have matching type file extention. Some image file types may not be suitable for all mobile devices. The Script assumes the existence of a desktop version image.

Function "popupLinks" adds Target attribute to links with Rel attribute value "blank"
The reason: Currently many mobile devices do not support more than one window and DOM Scripting
*/
function addOnloadEvent(fnc){
  if (typeof window.addEventListener != "undefined") window.addEventListener("load", fnc, false);
  else if (typeof window.attachEvent != "undefined") {window.attachEvent("onload", fnc);}
  else {
    if (window.onload != null) {
      var oldOnload = window.onload;
      window.onload = function(e) {
        oldOnload(e);
        window[fnc]();
      };
    }
    else
      window.onload = fnc;
  }
}
// Popup links
function popupLinks() {
	if (!document.getElementsByTagName) return false;
	var popupLinks = document.getElementsByTagName('a');
	var allLinks = popupLinks.length;
	if (allLinks < 0) return false;
	for (var i = 0; i < allLinks; i++) {
		if(popupLinks[i].getAttribute('rel') == 'blank') popupLinks[i].setAttribute('target', '_blank');
	}// for
}
addOnloadEvent(popupLinks);

function largeImages(){
	if (!document.getElementById) return false;
	else if (document.getElementById('main-content')) {var contentID = document.getElementById('main-content');} // images container ID
	else {return false;} 
	if (!contentID.getElementsByTagName('img')) return false;
	var Imgs = contentID.getElementsByTagName('img'); 
	var allImgs = Imgs.length;
	for (var j = 0; j < allImgs; j++) {
		if (Imgs[j].src.indexOf('-mobi.') != -1) {
			if (Imgs[j].getAttribute('width')) Imgs[j].setAttribute('width', ''); 
			if (Imgs[j].getAttribute('height')) Imgs[j].setAttribute('height', '' ); 
			Imgs[j].src = Imgs[j].src.replace('\-mobi\.', '.');
		}
	}// Mobi images End
}
addOnloadEvent(largeImages);