
/*
Extends String: to parse a class attribute and return the value
*/

String.implement({
	parseCssString: function(value, divider){
		if(this.indexOf(value+divider) > -1)  {
			var cssArray;
			cssArray = this.split(' ');
			cssArrayLength = cssArray.length;
			for (z=0;z<cssArrayLength;z++) {
				if(cssArray[z].indexOf(value+divider) > -1)  {
					var cssSelectorArray;
					cssSelectorArray = cssArray[z].split(divider);
					if(cssSelectorArray[0] == value) { return	cssSelectorArray[1];}
				}
			}
		} else {
			return null;
		}
	}
});


/*
Class: PageInfo
	Creates a new class holding page info -- its initialize method will fire upon class instantiation.

Arguments:
	options - name value pairs to set this.options properties

Public Properies:
	PageInfo.options.filePath = array of the url
	PageInfo.options.fullUrl = string of the url
	PageInfo.options.folderNames = array of folders   
	PageInfo.options.fileName = string of the filename  - test.html
	PageInfo.options.pageName = string of the pagename  - test
	PageInfo.options.qArray = querystring array
	PageInfo.options.qString = a temp string for the querystring
	PageInfo.options.isPages = bool is in the pages folder
	PageInfo.options.geo = geo code
	PageInfo.options.country = full country name (string)
	PageInfo.options.zone = 1st level folder (products)
	PageInfo.options.zoneIndex =  bool is index page in a zone folder
	PageInfo.options.isIndex =  bool is index page
	PageInfo.options.isGeo =  bool is geo page
	PageInfo.options.isHome = bool is main home page	
	PageInfo.options.isZoneHome =  bool is zone home page
*/

var PageInfo = {
	initialize: function(options){			
			this.options = Object.extend({
				// GLOBAL PROPERTYS
				defaultIndex:      'index',
				defaultExtension:  'html',
				defaultFileName:  'index.html',

				// URL INFO
				domain:        [],
				subdomain:     null,
				filePath:        [],
				fullUrl:       null,
				folderNames:     [],
				fileName:      null,
				pageName:      null,
				pageNameShort: null,
				extension:     null,
				qArray:          [],
				qString:       null,
				isPages:       false,
				
				// PAGE META DATA
				geo:           null,
				country:       null,
				zone:          null,
				zoneIndex:     null,

				// BOOLS
				isIndex:       false,
				isGeo:         false,
				isHome:        false,	
				isProduction:  false,
				isZoneHome:    false				
			}, options || {});
			
			//PageInfo.options.filePath.toString()
			
			this.tempArray = [];
			this.urlArray = window.location.href.split("//");
			
			this.options.fullUrl = this.urlArray[1];
			
			this.urlArray = this.urlArray[1].split("/");
			this.tempArray = "";
			
			this.options.domain = this.urlArray[0];
			this.options.subdomain = this.urlArray[0].split('.')[0];
									
			this.urlArray = this.urlArray.splice(1, this.urlArray.length);
			this.qString = [];
			
			if(this.urlArray[(this.urlArray.length - 1)].indexOf("?") > -1) {
				this.tempArray = this.urlArray[(this.urlArray.length - 1)].split("?");
				this.options.fileName = this.tempArray[0];
				if(this.options.fileName == "" ) {this.options.fileName = this.options.defaultFileName;}
			} else {
				this.options.fileName = this.urlArray[(this.urlArray.length - 1)];
				if(this.options.fileName == "" ) {this.options.fileName = this.options.defaultFileName;}
			}
			
			this.options.filePath = this.urlArray.splice(0, this.urlArray.length-1);
						
			if(this.options.filePath.length == 0) {
					this.options.isHome = true;
					this.options.filePath.push('index.html');
			} 
			
			for (i=0;i<this.options.filePath.length;i++) {
				this.options.folderNames[i] = this.options.filePath[i].replace(/-/g, " ");
				this.options.folderNames[i] = this.options.folderNames[i].replace(/_/g, " ");
				this.options.folderNames[i] = this.options.folderNames[i].replace(/ and /gi, " &amp; ");
			}
			
			this.tempArray = "";
			this.tempArray = this.options.fileName.split(".");
			this.options.pageName = this.tempArray[0].replace(/-/g, " ");
			this.options.pageName = this.options.pageName.replace(/_/g, " ");
			this.options.pageName = this.options.pageName.replace(/ and /g, " &amp; ");
			this.options.extension = this.tempArray[1];     
			this.tempArray = "";
			
				if(this.options.filePath[0].toLowerCase() == 'pages') {
					this.options.isPages = true;
				}
			
			if(this.options.filePath[0] == "geo") {
				this.options.isGeo = true;

				if(this.options.filePath.length > 2) {
					if(this.options.filePath[2].toLowerCase() == 'pages') {	this.options.isPages = true;}
				}
				if(this.options.filePath.length > 1) {
					if(this.options.filePath[1].length == 2) {this.options.geo = this.options.filePath[1].toLowerCase();} 
					else {this.options.geo = "us"	}
				}
				
				if     (this.options.geo == "au") {this.options.country = "Australia"}
				else if(this.options.geo == "ap") {this.options.country = "Albania"}
				else if(this.options.geo == "au") {this.options.country = "Australia"}
				else if(this.options.geo == "at") {this.options.country = "Austria"}
				else if(this.options.geo == "be") {this.options.country = "Belgium"}
				else if(this.options.geo == "ca") {this.options.country = "Canada"}
				else if(this.options.geo == "ch") {this.options.country = "Switzerland"}
				else if(this.options.geo == "cn") {this.options.country = "China"}
				else if(this.options.geo == "de") {this.options.country = "Germany"}
				else if(this.options.geo == "dk") {this.options.country = "Denmark"}
				else if(this.options.geo == "en") {this.options.country = "English"}
				else if(this.options.geo == "fi") {this.options.country = "Finish"}
				else if(this.options.geo == "fr") {this.options.country = "France"}
				else if(this.options.geo == "in") {this.options.country = "India"}
				else if(this.options.geo == "it") {this.options.country = "Italy"}
				else if(this.options.geo == "jp") {this.options.country = "Japan"}
				else if(this.options.geo == "kr") {this.options.country = "Korea"}
				else if(this.options.geo == "nl") {this.options.country = "Netherlands"}
				else if(this.options.geo == "no") {this.options.country = "Nordic"}
				else if(this.options.geo == "pt") {this.options.country = "Portugal"}
				else if(this.options.geo == "au") {this.options.country = "Australia"}
				else if(this.options.geo == "sk") {this.options.country = "Slovak Republic"}
				else if(this.options.geo == "sp") {this.options.country = "Spain"}
				else                              {this.options.country = "United States"}
				if ($('country') != null && this.options.isPages == false) {$('country').innerHTML = this.options.country;}
			} else {
				this.options.geo = "us"
				this.options.country = "United States"
        if ($('country') != null && this.options.isPages == false) {$('country').innerHTML = this.options.country;}
			}

			if(this.options.isGeo === true)  {this.options.zone = this.options.filePath[2] } else {	this.options.zone = this.options.filePath[0]}
			
			if(this.options.fileName == this.options.defaultFileName) {
				this.options.isIndex = true;
				
				if(this.options.filePath.length == 0 || ((this.options.filePath[1] == "geo") && (this.options.filePath[2].length == 2) && (this.options.filePath.length == 2))) {
					this.options.isHome = true;
				}
				
				if((this.options.filePath.length > 0) && (this.options.filePath[1] != "geo") || (this.options.filePath[1] == "geo") && (this.options.filePath.length == 3)) {
					this.options.isZoneHome = true;
				}
			}

			if(window.location.href.indexOf("?") > -1) {
				var tempString;
				this.options.qstring = window.location.search.replace("?","");
				this.options.qarray  = this.options.qstring.split("&");				
				for (i=0;i<this.options.qarray.length;i++) {
					tempString = this.options.qarray[i].split("=");
					this.qString[i] = [];
					this.qString[i][0] = tempString[0];
					this.qString[i][1] = tempString[1];
				}		
			}  else {
				this.qString = null;
			}		
			
			this.tempArray = null;
			this.tempString = null;
	},
	
	getQueryStringPair: function(pairId){
		if(this.qString != null) {
			if(this.qString.length > 0) {
				for (i=0;i<this.options.qString.length;i++) {
					if(this.qString[i][0] == pairId) {
						return this.qString[i][0]+ " : " + this.qString[i][1];
					}				
				}
				return null;
			} else {
				return null;
			}
		} else { return null;	}
	},
	
	getQueryStringValue: function(pairId){
		if(this.qString != null) {
			if(this.qString.length > 0) {
				for (i=0;i<this.qString.length;i++) {
					if(this.qString[i][0] == pairId) {
						return this.qString[i][1];
					}				
				}
				return null;
			} else {
				return null;
			}
		} else {
				return null;
		}
	}
}
window.addEvent('domready',  PageInfo.initialize.bind(PageInfo));


/*
Class: Usercookie
	Creates a new class usercookie info -- its initialize method will fire upon class instantiation.

Arguments:
	options - name value pairs to set this.options properties

Public Properies:
	this.options.mbCookie = mb cookie name
	this.options.mbCookie = serena cookie name
	PageInfo.options.filePath = array of the url
	this.isActive = is the session active
	this.userName = username
	this.full_name = full name
	this.last_name = first name
	this.email = email
	this.company = comapany 
	this.geo = geo
	this.country = country full name
	this.id_User = id_User
	this.id_User = id_Person
	this.prefs = prefs
	this.privs = privs
*/

var Usercookie = {
	initialize: function(options){
		this.options = Object.extend({	
			mbCookie:    "Marketbright_Cookie",
			mbDivider:   "/",
			mbArray:     [],
			sCookie:     "SerenaCookie",
			sDivider:    "&"
		}, options || {});	
		
		this.cookieArray = [];
		this.isActive    = false;
		this.userName    = "";
		this.full_name   = "";
		this.first_name  = "";
		this.last_name   = "";
		this.email       = "";
		this.company     = "";
		this.geo         = "";
		this.country     = "";
		this.id_User     = "";
		this.id_Person   = "";
		this.id_Group    = "";
		this.prefs       = "";
		this.privs       = "";

		if (document.cookie && document.cookie.length != 0 ) {
			this.cookieArray = document.cookie.split(";");
			var cookieArrayLength = this.cookieArray.length
			for (i=0;i<cookieArrayLength;i++){
				if(this.cookieArray[i].indexOf(this.options.mbCookie) > -1) {
					this.options.mbArray = this.getValues(this.cookieArray[i].substring((this.cookieArray[i].indexOf("=") + 1), this.cookieArray[i].length), this.options.mbDivider)
					this.isActive = true;
					for (j=0;j<this.options.mbArray.length;j++){
						if(j == 0) { this.userName   = this.options.mbArray[j]	}
						if(j == 1) { this.id_User    = this.options.mbArray[j]	}
						if(j == 2) { this.id_Group   = this.options.mbArray[j]  }
						if(j == 3) { this.id_Person  = this.options.mbArray[j]	}
						if(j == 4) { this.full_name  = this.options.mbArray[j]	}
						if(j == 5) { this.email      = this.options.mbArray[j]	}
						if(j == 6) { this.prefs      = this.options.mbArray[j]	}
						if(j == 7) { this.privs      = this.options.mbArray[j]	}
					}
					this.company    = this.getCompany(this.privs);
					this.first_name = this.getName(this.full_name, " ", 0);
					this.last_name  = this.getName(this.full_name, " ", 1);
				}
			}			
		} else {
			this.cookieArray = null;
		}
	},
	getValues: function(cookieString, divider) {
		valueArray = cookieString.split(divider);
		return valueArray;
	},
	getName: function(string, divider, returnPosition) {
		string = string.split(divider);
		string = string[returnPosition];
		return string;
	},
	getCompany: function(privs) {
		begStr = privs.indexOf("Company(") + 8;
		endStr = privs.indexOf(")");	
		return privs.substring(begStr,endStr);
	}		
}
window.addEvent('domready',  Usercookie.initialize.bind(Usercookie));


/*
Class: Menu1
	Sets the active stat for the menu / main nav
*/
var Menu1 = {
	initialize: function(options){	
			this.tempArray = []
			
			if($("menu")) {
				this.menuLi = $$('a.menuButton');
				for(i=0;i < this.menuLi.length;i++) {
					this.tempArray = this.menuLi[i].href.split("/");
					if((this.menuLi[i].innerHTML != "On Demand Login") && (this.menuLi[i].href != "http://community.serena.com/")) {
						if(PageInfo.options.isGeo === true)  {
							if(PageInfo.options.filePath.length > 1) {
								if(this.tempArray[5] == PageInfo.options.zone) {
									this.menuLi[i].addClass('active')
								}
							}
						} else {
							if(this.tempArray[3] == PageInfo.options.zone) {
								this.menuLi[i].addClass('active')
							}
						}
					}
				}
			}
		this.tempArray = null;
	}
}
window.addEvent('domready',  Menu1.initialize.bind(Menu1));


/*
Class: HoverBox
	Creates the pop up for the country menu & Profile menu
	looks for anchors with a class="hoverbox" then attaches mouse over events and injects a div and iframe using the anchor href
	as the src for the iframe.
	
*/
var HoverBox = {
	initialize: function(options){			
		this.options = Object.extend({
			width:              250,
			height:             250,
			scrolling:          'no',
			offsetx:            20,
			offsety:            3,
			timeOut:            false,
			timeOutTimer:       600,
			unitMessurment:     'px',
			aId:                "hoverBox-",
			iframeId:           'hoverBox-iframe-',
			divId:              'hoverBox-div-',
			aClass:             'hoverBox',
			iframeClass:        'hoverBox-iframe',
			divClass:           'hoverBox-div',
			active:             null
		}, options || {});
		//STEVE
		
		if($('share') != null) {
			if($('share').tagName == "A") {
				var titleVar = $$("title")
				$('share').href = $('share').href + '?p_Title=' + titleVar[0].innerHTML + '&p_URL=' + escape( document.location.href );
				titleVar = null;
			}
		}
		
		if($('myProfile')) {
			if($('myProfile').tagName == "A") {
				if(Usercookie != null) {
					if(Usercookie.email != null) {
						//if(Usercookie.first_name != "Guest") {	$('myProfile').innerHTML = "My Profile / Log Out"; }
					}
				}
		
				$('myProfile').href = $('myProfile').href + '?Referrer=' + PageInfo.options.fullUrl;

			}
		}
			
		this.anchors = $$('a[rel=hoverbox]');
		this.divs = [];
		this.iframes = [];
		
		var divElement;
		var iframeElement;
		var i;
		var coordinates = null;
		
		var anchorsLength = this.anchors.length;
		for (i=0;i<anchorsLength;i++) {
		
			coordinates = this.anchors[i].getCoordinates();
			
			if(!this.anchors[i].id) {	this.anchors[i].id = this.options.aId + i	}
			
			this.anchors[i].index     = i;
			this.anchors[i].revArray  = this.anchors[i].rev.split(",");	
			this.anchors[i].width     = this.getValue('width', this.anchors[i].revArray);
			this.anchors[i].height    = this.getValue('height', this.anchors[i].revArray);
			this.anchors[i].scrolling = this.getValue('scrolling', this.anchors[i].revArray);
			this.anchors[i].iframeId  = this.options.iframeId  + this.anchors[i].id;	
			this.anchors[i].divId     = this.options.divId    + this.anchors[i].id;	
			
			var coordinates = this.anchors[i].getCoordinates();
			
			divElement  = new Element('div', {'id': this.anchors[i].divId + i , 'styles' : {'display' : 'block'} , 'class' : this.options.divClass });	
			divElement.setStyle('position', 'absolute');
			divElement.setStyle('z-index', '25000' + i);
			divElement.setStyle('width', this.anchors[i].width);
			divElement.setStyle('height', this.anchors[i].height);
			divElement.setStyle('display', 'none');
			divElement.setStyle('top', coordinates['top'] + coordinates['height']);				
			
			divElement.setStyles({width:this.anchors[i].width + this.options.unitMessurment,  height:this.anchors[i].height +  this.options.unitMessurment, overflow: 'hidden' });				
			
			
			var iframeElement  = new Element('iframe', {'id': this.options.iframeId + i, 'src' : this.anchors[i].href , 'frameborder' : '0', 'scrolling': this.anchors[i].scrolling,'class' : this.options.iframeClass});
			// iframeElement.setStyle('position', 'absolute');	
			iframeElement.setStyle('width', this.anchors[i].width - 2);
			iframeElement.setStyle('height', this.anchors[i].height - 2);	
			iframeElement.setStyle('display', 'none');
			iframeElement.injectInside(divElement);
			divElement.injectAfter(this.anchors[i]);	
			
			this.divs.push($(divElement.id))
			this.iframes.push($(iframeElement.id))
									
			iframeElement = null;
			divElement    = null;
		}			
		
		i = 0;
		
		$each(this.anchors, function(el){
			el.index = i;
			el.onmouseover = this.mouseover.pass(el, this);
			el.onmouseout  = this.mouseout.pass(el, this);			
			i = i + 1;
		}, this);
		
		el = null;
		i = null;
		
		i = 0;
		$each(this.divs, function(el){
			el.index = i;
			el.onmouseover = this.mouseover.pass(el, this);
			el.onmouseout  = this.mouseout.pass(el, this);			
			i = i + 1;
		}, this);
		
		el = null;
		i = null;

	},
		
		
	mouseout: function(link) { 
		this.options.timeOut = setTimeout(this.timeOutMethod, this.options.timeOutTimer);
	},
	
	mouseover: function(link) { 	
		var coordinates;
		if(this.options.timeOut != false && this.options.active == link.index) { 
			clearTimeout(this.options.timeOut);
		}
		if(this.options.timeOut != false && this.options.active != link.index)	{	
			this.hide(this.options.active);
			clearTimeout(this.options.timeOut);
			this.options.timeOut = false;
		}
		if(link.tagName == "LI" || link.tagName == "A" ) {
			coordinates = link.getCoordinates();
			this.divs[link.index].setStyle('top',  coordinates['top'] + coordinates['height']);
			this.divs[link.index].setStyle('left', coordinates['left']);
			
			if((parseFloat(this.anchors[link.index].width) + parseFloat(coordinates['left']) ) > parseFloat(window.getWidth())) {
				var leftCoordinates = (parseFloat(coordinates['left']) + 0) - ((parseFloat(this.anchors[link.index].width) + parseFloat(coordinates['left'])) - parseFloat(window.getWidth()))
				this.divs[link.index].setStyle('left', leftCoordinates);
			}
			
			this.divs[link.index].setStyle('display', "block");
			this.iframes[link.index].setStyle('display', "block");
			this.iframes[link.index].addClass('block');	
			
			this.options.active       = link.index;
			
		} 
	},	
	
	timeOutMethod: function() {		
		if($(HoverBox.divs[HoverBox.options.active].id) != null) {
			$(HoverBox.divs[HoverBox.options.active].id).setStyle('left', 0);
			$(HoverBox.divs[HoverBox.options.active].id).setStyle('display', 'none');
			$(HoverBox.iframes[HoverBox.options.active].id).setStyle('display', 'none');
			HoverBox.options.active       = null;
			HoverBox.options.timeOut      = false;
		}	
	},
	
	hide: function(index) {						
		$(HoverBox.divs[index].id).setStyle('left', 0);
		$(HoverBox.divs[index].id).setStyle('display', 'none');
		$(HoverBox.iframes[index].id).setStyle('display', 'none');
	},
	
	getValue: function(value, stringArray){	
		var stringArrayLength = stringArray.length;
		for (j=0;j<stringArrayLength;j++) {	
			var itemArray = stringArray[j].split(":");
			if(itemArray[0] == value) {
				return itemArray[1];			
			}
		}		
		for(var name in this.options) {
			if(value == name)  {
				return this.options[name]
			}
		}
		return null;
	}
}
window.addEvent('domready', HoverBox.initialize.bind(HoverBox));



/*
Class: Breadcrumb
	Looks for a ul with id of bread then looks to the "PageInfo" class to rebuild out the breadcrumb based on the URL
	extra conditions are to hide the index... add a class="end" for the last item... and clean up the file name 
*/
var Breadcrumb = {
	initialize: function(options){	
		var strBreadTrail;
		breadTest = document.getElementById('bread');
		
		if(PageInfo != null) {
			
			if(document.getElementById("bread") != undefined) {
								
				strBreadTrail = '<li class="begin"><a href="/">home</a></li>'; // URL may need rework
				strATag = '/';
				
				for (i=0;i<PageInfo.options.folderNames.length;i++) {
					strATag = strATag + PageInfo.options.filePath[i] + '/' 
					if(PageInfo.options.isIndex === true && i == (PageInfo.options.folderNames.length - 1)) {
						strBreadTrail = strBreadTrail + '<li class="end"><a href="' + strATag + '">' + PageInfo.options.folderNames[i].replace(/ and /gi,"&amp;") + '</a></li>';
					} else {
						strBreadTrail = strBreadTrail + '<li><a href="' + strATag + '">' + PageInfo.options.folderNames[i].replace(/ and /gi," &amp; ") + '</a></li>';
					}
				}
				
				if(PageInfo.options.isIndex == false){
					strATag = strATag + PageInfo.options.fileName 
					strBreadTrail = strBreadTrail + '<li class="end"><a href="' + strATag + '">' + PageInfo.options.pageName.replace(/ and /gi," &amp; ") + '</a></li>';
				}		
				
				$("bread").innerHTML = strBreadTrail;
			}			
		}
	}
}
window.addEvent('domready',  Breadcrumb.initialize.bind(Breadcrumb));



/*
Class: Menu2_2
	Looks for a UL with class="menu"  It then parses the list for A tags and compares that to the URL...  
	if the compare then set the A class to active... you can set a class like <ul class="menu level-1"> or <ul class="menu level-2"> --  this wil lcompare the anchor and URL to 
	a certain level this way if you want and active state for a section
*/

var Menu2_2 = {
	initialize: function(options) {	
		this.url = window.location          // set this.url = to page address - this is used to set active state
		this.ul = $$('ul.menu');     // Get all UL tags with a class="menu2-2"
		//this.compareLevel =  0;              // Set class="menu level-2" to compare the anchor href & URL to a specific level
				
		
		for (i=0;i<this.ul.length;i++) {
			this.ul[i].compareLevel = 0;
			
			if(this.ul[i].className.indexOf(" level-") > -1) { 
				this.ul[i].compareLevel = this.getLevel(this.ul[i].className);
				if(PageInfo.options.isGeo == true) {
					this.ul[i].compareLevel = this.ul[i].compareLevel + 2;
				}
			}		
			
			if(this.ul[i].getElements('li') != null) {
				
				this.ul[i].li = this.ul[i].getElements('li');
				
				for (j=0;j<this.ul[i].li.length;j++) {
					if(this.ul[i].li[j].getElement("a") != null) {
						this.ul[i].li[j].anchors      = this.ul[i].li[j].getElements("a")
						this.ul[i].li[j].href         = this.ul[i].li[j].anchors[0].href
						this.ul[i].li[j].hrefArray    = this.ul[i].li[j].anchors[0].href.split("/");
						this.ul[i].li[j].level        = 0;
						this.ul[i].li[j].isIndex      = this.checkIndex(this.ul[i].li[j].hrefArray[this.ul[i].li[j].hrefArray.length - 1]);
						this.ul[i].li[j].isActive     = this.checkActive(window.location, this.ul[i].li[j].href, this.ul[i].compareLevel);

						if(this.ul[i].li[j].isActive === true) {
							this.ul[i].li[j].addClass("active");
						}
					}	
				}		
			}
		}
	},
	
	getLevel: function(className) {
		classArray = className.split(' ');
		for(h=0;h<classArray.length;h++) {
			if(classArray[h].indexOf("level-") > -1) {
				clasNameArray = classArray[h].split('-');
				return clasNameArray[1];
			}
		}
		return 0;
	},
	
	checkIndex: function(fileName) {
		if(fileName == "index.html" || fileName == "") {
			return true;
		}	else {
			return false;
		}	
	},
	
	checkActive: function(url, href, campareLevel) {

		var hrefArray = href.split("/");
		url  = url.toString();
		var urlArray = url.split("/");
			
		if(urlArray[urlArray.length -1] == "") {
			urlArray[urlArray.length -1] = "index.html";
		}
		
		if(hrefArray[hrefArray.length -1] == "") {
			hrefArray[hrefArray.length -1] = "index.html";
		}
		
		if(hrefArray[hrefArray.length -1].indexOf(".") == -1) {
			hrefArray.push("index.html");
		}
		
		if(campareLevel > 0 )  {
			hrefString = hrefArray.splice(3, campareLevel).toString()
			urlString  = urlArray.splice(3, campareLevel).toString()
			if(hrefString == urlString) {
					return true;
			}
			return false;
		}
				
		if(hrefArray[hrefArray.length -1] == "index.html") {
			if(0 < hrefArray.length - 2 ) {
				if(urlArray[urlArray.length -2]  == hrefArray[hrefArray.length -2]) {
					return true;
				}
			}
		}
		
		if(urlArray.toString() == hrefArray.toString()) {
			return true;
		}
		
		if(urlArray.length > hrefArray.length) {
			if(urlArray[hrefArray.length - 1] == hrefArray[hrefArray.length - 1]) {
				return true;
			} 
		}
		
		if(urlArray.length < hrefArray.length) {
			if(urlArray[urlArray.length - 1] == hrefArray[urlArray.length - 1]) {
				return true
			} 
		}
		
		return false;
	}
}	

window.addEvent('domready', Menu2_2.initialize.bind(Menu2_2));

/*
Class: RoundedBox
	Rounds a Box Corners

Arguments:
	options - the classname of the item you want to round
*/

var RoundedBox = new Class({
	Implements: Options,

	options: {
		className: 'box-f5f5f5-2-inner'
	},
	
	initialize: function(options){		
		this.setOptions(options);
		
		var box_inner = $$('div.'+this.options.className);
		
		if(Browser.Engine.trident || Browser.Engine.presto) {
			if((Browser.Engine.trident && (Browser.Engine.version > 4)) ||  Browser.Engine.presto) {			
				for(i=0;i < box_inner.length;i++) {	this.	createHTMLBox(box_inner[i]) }
			}	else {
				for(i=0;i < box_inner.length;i++) {  this.	createSimpleBox(box_inner[i])	 }
			}
		} else {
			for (i=0;i < box_inner.length;i++) {	this.	createCssBox(box_inner[i])}
		}
	},
	
	setClassName: function(className){
		this.options.className = className;
	},

	getClassName: function(className){
		return this.options.className
	},

	createSimpleBox: function(box){
		box.addClass('simple');
	},

	createCssBox: function(box){
		box.addClass('css');
	},

	createHTMLBox: function(box){
		box.addClass('html');
		
		var box_bi		= new Element('div', {'class': 'bi'});
		var box_bt		= new Element('div', {'class': 'bt'});
		var box_bc		= new Element('div', {'class': 'bc'});
		var box_bb		= new Element('div', {'class': 'bb'});
		
		box_bt.innerHTML = '<div></div>';
		box_bc.innerHTML = box.innerHTML;
		box.empty();
		box_bb.innerHTML = '<div></div>';
							
		box_bt.inject(box_bi);
		box_bc.inject(box_bi);
		box_bb.inject(box_bi);
		box_bi.inject(box);
				
	}
});


/*
Class: Modal
	For Modal Dialog box

Arguments:
	type = "id" or "iframe"
	src = "/link/to/iframe/"  | divId 
	size {width: 200, height: 200 }
*/
Modal = new Class({
	Implements: Options, 
	
  options: {
			id: 'modal',
			src: false,
			type: 'iframe',
			size: {	width: 880,	height: 605 } 
		},
	
	initialize: function(options){	
		/*|| Browser.Engine.gecko */
		
		
		this.setOptions(options);

		this.modalSize = this.options.size;
		this.modalType = this.options.type;
		
		this.modalVersion = 3;
		
		this.isVisible 					= 0;

		this.modalDiv 					= new Element('div', 	{'id': this.options.id, 'class': 'modal-dialog'});
		this.modalCloseDiv 			= new Element('div', 	{'class': 'modal-dialog-close-div'});
		this.modalCloseA 				= new Element('div', 	{'class': 'modal-dialog-close-a'});		
		
		if(this.modalType == 'id') {
			this.modalIframe	= $(this.options.src);
		} else {
			if(this.options.src == '') {
				this.modalIframe = new Element('div',		{'class': 'modal-error'});
				this.modalIframe.innerHTML = "Opps!  There was an error please contact us if you see this and we will fix it right away."
				return;
			} else {
				this.modalIframe	= new Element('iframe',		{'id': this.options.id + '-iframe', 'class': 'modal-iframe'});		
			}
		}
	
		//this.modalCloseA.set('href', '#');
		this.modalCloseA.set('text', 'close');
		
		this.buttons = new Array();
		
		this.modalCloseA.onclick = this.hideModalPublic.pass(this);

		this.modalCloseA.inject(this.modalCloseDiv);
		this.modalCloseDiv.inject(this.modalDiv);
				
		if(Browser.Engine.trident  ) { //|| Browser.Engine.presto 
			
			if((Browser.Engine.trident) && (Browser.Engine.version < 5)) {
				
				this.modalDiv.addClass('modalcss1');	
			
				this.modalDiv.setStyle('width', this.options.size.width + 'px');
				this.modalDiv.setStyle('height', this.options.size.height + 'px');
			
				if(this.modalType != 'id') {	
					this.modalIframe.setProperty('src', this.options.src);
					this.modalIframe.setProperty('width', this.options.size.width);
					this.modalIframe.setProperty('height', this.options.size.height);
				}
			
				this.modalIframe.inject(this.modalDiv); 
					
			} else {
				this.modalVersion = 2;
				
				this.modalDiv.setStyle('width', (this.options.size.width.toInt() + 71) + 'px');
				this.modalDiv.setStyle('height', (this.options.size.height.toInt() + 51) + 'px');
				
				this.modalDiv.addClass('modalcss2');
				
				this.modalTable 						= new Element('table', {'id': (this.options.id + '-table'), 'class': 'modal-dialog-table'});
				this.modalTBody 						= new Element('tbody');
				this.modalTrTop 						= new Element('tr', {'class': 'top'});		
				this.modalTdTopLeft 				= new Element('td', {'class': 'top-left'});
				this.modalTdTopCenter 			= new Element('td', {'class': 'top-center'});				
				this.modalTdTopRight				= new Element('td', {'class': 'top-right'});
				
				this.modalTrMiddle 					= new Element('tr', {'class': 'middle'});	
				this.modalTdMiddleLeft 			= new Element('td', {'class': 'middle-left'});
				this.modalTdMiddleCenter 		= new Element('td', {'class': 'middle-center'});				
				this.modalTdMiddleRight			= new Element('td', {'class': 'middle-right'});
				
				this.modalTrBottom 					= new Element('tr', {'class': 'bottom'});	
				this.modalTdBottomLeft 			= new Element('td', {'class': 'bottom-left'});
				this.modalTdBottomCenter 		= new Element('td', {'class': 'bottom-center'});				
				this.modalTdBottomRight			= new Element('td', {'class': 'bottom-right'});
							
				
				this.modalTable.setStyles({'width' :	(this.options.size.width.toInt() + 71), 'height' : (this.options.size.height.toInt() + 51)});			
				
				this.modalTable.inject(this.modalDiv);
				this.modalTBody.inject(this.modalTable);
				
				this.modalTrTop.inject(this.modalTBody);
				this.modalTdTopLeft.inject(this.modalTrTop);
				this.modalTdTopCenter.inject(this.modalTrTop);
				this.modalTdTopRight.inject(this.modalTrTop);
				
				this.modalTrMiddle.inject(this.modalTBody);
				this.modalTdMiddleLeft.inject(this.modalTrMiddle);
				this.modalTdMiddleCenter.inject(this.modalTrMiddle);
				this.modalTdMiddleRight.inject(this.modalTrMiddle);
				
				this.modalTrBottom.inject(this.modalTBody);
				this.modalTdBottomLeft.inject(this.modalTrBottom);
				this.modalTdBottomCenter.inject(this.modalTrBottom);
				this.modalTdBottomRight.inject(this.modalTrBottom);	
				
				if(this.modalType != 'id') {
					this.modalIframe.setProperty('src', this.options.href);
					this.modalIframe.setProperty('width', (this.options.size.width-18));
					this.modalIframe.setProperty('height', (this.options.size.height-15));
				}
							
				this.modalIframe.inject(this.modalTdMiddleCenter);
			
			}
		
		}	else {
			
			this.modalDiv.addClass('modalcss3');	
			
			this.modalDiv.setStyle('width', this.options.size.width + 'px');
			this.modalDiv.setStyle('height', this.options.size.height + 'px');
			
			if(this.modalType != 'id') {	
				this.modalIframe.setProperty('src', this.options.src);
				this.modalIframe.setProperty('width', this.options.size.width);
				this.modalIframe.setProperty('height', this.options.size.height);
			}
			
			this.modalIframe.inject(this.modalDiv); 
			
		}
		
		this.modalDiv.addClass('hide');
		this.modalDiv.inject(document.body);
		this.size = this.modalDiv.getSize();
	},
	
	getModal : function() {
		return this.modalDiv;
	},
	
	getModalId : function() {
		return this.modalDiv.id;
	},
	
	getModalIdIframe : function(id) {
		return this.modalIframe.set('id', id);
	},
	
	setModalId : function() {
		return this.modalDiv.id;
	},
	
	showModal : function() {
		this.centerModal();
		this.modalDiv.removeClass('hide');
		this.isVisible = 1;
	},
	
	centerModal : function() {
		var windowSize 	= $(document.body).getSize();		
		
		
		if(this.modalVersion == 2) {
		
			if (document.all != null) { 
				this.size.y = (document.documentElement.clientHeight / 2) - (this.modalSize.height/ 2) + document.documentElement.scrollTop;  
			}	else { 
				this.size.y = Math.round((window.innerHeight / 2) - (this.modalSize.height / 2) + window.scrollY);
			}
							
			if(Browser.Engine.trident || Browser.Engine.presto ) { 	
				if(this.size.y < 10 ) { this.size.y = 10 }
			} else {	
				if(this.size.y < 30 ) { this.size.y = 30 }	
			}
			this.size.x = (windowSize.x/2) - ( (this.modalSize.width.toInt()+65)/2);
		
		} else {
				
			if (document.all != null) { 
				this.size.y = (document.documentElement.clientHeight / 2) - (this.modalSize.height/ 2) + document.documentElement.scrollTop;  
			}	else { 
				this.size.y = Math.round((window.innerHeight / 2) - (this.modalSize.height / 2) + window.scrollY);
			}
							
			if(Browser.Engine.trident || Browser.Engine.presto ) { 	
				if(this.size.y < 10 ) { this.size.y = 10 }
			} else {	
				if(this.size.y < 30 ) { this.size.y = 30 }	
			}
					
			this.size.x = (windowSize.x/2) - ( this.modalSize.width/2);
			
		}
		this.modalDiv.setStyles({left: this.size.x,  top: this.size.y });		
		
		windowSize = null;
	}, 
	
	hideModal : function() {
		
		var objectArray = modalDiv.getElements('object');
		var embedArray = modalDiv.getElements('embed');
		var parent = '';
		
		if(objectArray.length > 0) {
			 for (i=0;i<objectArray.length;i++) {
				 parent = objectArray.getParent();
				 console.log(parent);
			 }
		}
		
		if(embedArray.length > 0) {
			for (i=0;i<embedArray.length;i++) {
				parent = objectArray.getParent();
				console.log(parent);
			 }
		}
		
		this.modalDiv.addClass('hide');
		this.isVisible = 0;
	},
	
	hideModalPublic : function(modal) {
		
		var objectArray = modal.modalDiv.getElements('object');
		var embedArray = modal.modalDiv.getElements('embed');
		var iframeArray = modal.modalDiv.getElements('iframe');
		var parent = '';
				
		if(objectArray.length > 0) {
			 for (i=0;i<objectArray.length;i++) {
				parent = objectArray[i].parentNode;
				parent = $(parent);
				parent.empty();
				parent.innerHTML = objectArray[i].outerHTML;
			 }
		}
		
		if(embedArray.length > 0) {
			for (i=0;i<embedArray.length;i++) {
				parent = embedArray[i].getParent();
				parent.empty();
				embedArray[i].inject(parent);
			}
		}
		
		if(iframeArray.length > 0) {
			for (i=0;i<iframeArray.length;i++) {
				parent = iframeArray[i].getParent();
				parent.empty();
				iframeArray[i].inject(parent);
			}
		}
		
		modal.modalDiv.addClass('hide');
		modal.isVisible = 0;
	},
	
	setIframeSrc : function(src) {
		this.modalIframe.set('src', src);
		this.setOptions({'src' : src});
	},
	
	deleteModal: function() {
		$(this.modalDiv).destroy();	
	},
	
	injectModalIframe: function(src, width, height) {
		
		if(Browser.Engine.trident || Browser.Engine.presto) { /*|| Browser.Engine.gecko */
			this.modalIframe.inject(this.modalTdMiddleCenter);
		} else {
			this.modalIframe.inject(this.modalDiv);
		}
		
		this.modalIframe.setProperty('src', src);
		this.modalIframe.setProperty('width', width);
		this.modalIframe.setProperty('height', height);

		this.setOptions({'src' : src,'width' : width,'height' : height});
		
	},
	 
	deleteModalIframe: function() {
		$(this.modalIframe).destroy();	
	}
	

});


// Modals On a Page Using class="modal" ----------------------------------------------------------------------------------------------------------------

Modals = new Class({
	Implements: Options, 
	
  options: {
			id: 'modal',
			src: false,
			size: {	width: 880,	height: 605 } 
	},
	
	initialize: function(options){	
		this.modalAnchors = $$('a.modal');
		this.modals = new Array();
		this.state = 0;
		this.current = 0;
		
		this.defaultStringDivider = '-';
		
		// Temporary variables
		this.tempLength 	= this.modals.length;
		this.tempId 			= '';
		this.tempType			= '';
		this.tempWidth 		= this.options.size.width;
		this.tempHeight 	= this.options.size.height;
		this.current = '';
		
		
		
		for (var i=0;i<this.modalAnchors.length;i++) {
		
			if(!this.modalAnchors[i].getProperty('id')) {	
				this.tempId  = this.options.id + this.defaultStringDivider + i;	
			}	else {	
				this.tempId  = this.modalAnchors[i].getProperty('id') + this.defaultStringDivider + this.options.id  + this.defaultStringDivider + i;	
			}
			
			if(this.modalAnchors[i].getProperty('class').indexOf('width-') > -1) {	
				this.tempWidth = this.modalAnchors[i].getProperty('class').parseCssString('width', this.defaultStringDivider);
			} else {	
				this.tempWidth =	this.options.size.width;	
			}	
			
			if(this.modalAnchors[i].getProperty('class').indexOf('height-') > -1) { 	
				this.tempHeight = this.modalAnchors[i].getProperty('class').parseCssString('height', this.defaultStringDivider);
			}	else {	
				this.tempHeight = this.options.size.height;	
			}	
			
			this.modals.push(new Modal( {'id' : this.tempId, 'src' : this.modalAnchors[i].href, 'size': { 'width' : this.tempWidth, 'height': this.tempHeight}}));	

			this.modalAnchors[i].index = i;
			this.modalAnchors[i].onclick = this.onclick.pass(this.modalAnchors[i], this);				
		}		
		
	},
	
	
	onclick: function(link) {	
		this.state = 1;
		this.current = 	link.index;
		this.modals[link.index].showModal();
		
		return false;
	}
	
});


window.addEvent('domready', function() {
																		 
	Box_f5f5f5 = new RoundedBox({'className' : 'box-f5f5f5-2-inner'});	
	PageModels = new Modals();
	
});


