/* ############################################# */
/* #  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);

myC = {
	c: null,
	cookieLife: 24,
	//This is used for checking if the intro of homepage.swf should play
	manage: function(){
		var _this = this;
		//If there is no cookie, set one caled 'skip' that will expire in 30 days
		//Set flashVar to false
		if(_this.read('skip') == '' || _this.read('skip') == null){
			_this.create('skip', 'true', _this.cookieLife);
			_this.c = myC.read('skip');
			_this.c  = 'false';
		}else{
			_this.c = 'true';
			//myC.erase('skip');
		}
	},
	create: function(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		} 
		else var expires = ""; 
		document.cookie = name+"="+value+expires+"; path=/";
	},
	read: function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},
	erase: function(name) {
		myC.create(name,"",-1);
	}
}
