/* ############################################# */
/* #  MasterCard Payment Gateway               # */
/* #  IconNicholson / P.Gold - 07/07           # */
/* ############################################# */




/* ************* Top Nav script *************** */
/*  for IE only | not supported by ie5 Mac       */
/* ********************************************* */
var navRoot;
var menuNav = {
	addEvent: function(elm, evType, fn, useCapture) {
		// addEvent cross-browser event handling for IE5+, NS6+ and Mozzila/Gecko
		// By Scott Andrew
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}	
	},
	
	init: function() {
		var isMac = navigator.userAgent.toLowerCase().indexOf("mac") !=-1;
		if (document.all&&document.getElementById&&!isMac) {
			var lists = document.getElementsByTagName('ul');
			for (var i=0; i<lists.length; i++) { 
				if (lists[i].className.match('globalNav'))
					navRoot = lists[i];
			}
			if (navRoot) {
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							this.className+=" over";
							if( document.all ) {
                Site.HideSelect();
              }
						}
			 			node.onmouseout=function() {
			 				this.className=this.className.replace(" over", "");
			 				if( document.all ) {
                Site.ShowSelect();
              }
						}
					}
		 		}
		 	}
		}
	}
};

var Site = { 
  Init: function() {
    Site.InitExecutivesDropDown();
    Site.InitSlideShow();
  },
  HideSelect: function() {
    if( document.body.className == "" ) {
      document.body.className = "hideSelect";
    };
  },
  ShowSelect: function() {
    if( document.body.className == "hideSelect" ) {
      document.body.className = "";
    };
  },
  InitExecutivesDropDown: function() {
    var ele = document.getElementById('executivesDropDown');
    if( ele ) { 
      menuNav.addEvent(ele, 'change', function() {
        // alert( ele.value );
        if( this.value != "-1" ) { 
          location.href = ele.value;
        };
      }, false );
    }
  },
  InitSlideShow: function() { 
    var ele = document.getElementById('slideshow');
    if( ele ) {
      var mainImage = $('.slideshow .mainImage img' )[0];
      $('.slideshow .thumbs ul li a img').each(function(index,ele){
        $(ele).parent().attr( 'href', 'javascript:void(0);' );
        $(ele).click(function() {        
          var newImagePath = $(ele).attr('src').replace( '_thumb_', '_large_' );
          // $(mainImage).attr( 'src', newImagePath );
          var newimg = $("<img src='" + newImagePath + "' />");
          $(newimg).load(function() {
            $(mainImage).replaceWith(newimg);
            mainImage = newimg;
          });
        });
        
      });
    };
  }
};

// add to this object to create more popups /jsk
var popupIDs = {
	"mcsp" : {
		href : "",
		name : "popup",
		width : 800,
		height : 400,
		left : "20",
		top : "20",
		scroll : "yes"
	}
};

function makePopups() {
	for(var p in popupIDs) {
		var popupLink = document.getElementById(p);
		if(popupLink) {
			popupLink.onclick = function () {
				pInfo = popupIDs[this.id];
				window.open(this.href, pInfo.name, "width="+pInfo.width+",height="+pInfo.height+",left="+pInfo.left+",top="+pInfo.top+",scrollbars="+pInfo.scroll+",toolbar=yes,location=yes,resizeable=yes");
				return false;
			}
		}
	}
}

menuNav.addEvent(window, 'load', menuNav.init, false);
menuNav.addEvent(window, 'load', Site.Init, false);
menuNav.addEvent(window, 'load', makePopups, false);
