window.addEvent('domready', initwindow);


function initwindow() {
	doSIFR();
	
	$ES('div.mainnav_inactive').addEvents({
		'mouseover': function() { 
			this.style.backgroundPosition = '0px -26px';
		},
		'mouseout': function() {
			this.style.backgroundPosition = '0px 0px';
		}
	});
	
	$ES('#nivenlink_login').addEvents({
		'focus': function() {
			this.value = (this.value == 'username') ? '' : this.value;
		},
		'blur': function() {
			this.value = (this.value == '') ? 'username' : this.value;
		}
	});
	
	$ES('#nivenlink_dummypassword').addEvents({
		'focus': function() {
			setClass(this, 'hidden', 'visible');
			setClass($('nivenlink_password'), 'visible', 'hidden');
			$('nivenlink_password').focus();
		}
	});
	
	$ES('#nivenlink_password').addEvents({
		'blur': function() {
			if (this.value == '') {
				setClass(this, 'hidden', 'visible');
				setClass($('nivenlink_dummypassword'), 'visible', 'hidden');
			}
		}
	});
	
	$ES('#nivenlink_go').addEvents({
		'mouseover': function() {
			this.style.backgroundPosition = '0px -39px';
			this.style.cursor = 'pointer';
		},
		'mouseout': function() {
			this.style.backgroundPosition = '0px 0px';
		},
		'mouseup': function() {
			this.style.backgroundPosition = '0px 0px';
			this.style.cursor = 'pointer';
		},
		'mousedown': function() {
			this.style.backgroundPosition = '0px -78px';
			this.style.cursor = 'pointer';
		}
	});
	
	$ES('#contactform_submit').addEvents({
		'mouseover': function() {
			this.style.backgroundPosition = '0px -33px';
			this.style.cursor = 'pointer';
		},
		'mouseout': function() {
			this.style.backgroundPosition = '0px 0px';
		},
		'mouseup': function() {
			this.style.backgroundPosition = '0px 0px';
			this.style.cursor = 'pointer';
		},
		'mousedown': function() {
			this.style.backgroundPosition = '0px -66px';
			this.style.cursor = 'pointer';
		}
	});
	
	$ES('img.rollover').addEvents({
		'mouseover': function() {
			if (this.src.indexOf('_off') != -1) {
				var imgsrc = new String(this.src);
				imgsrc = imgsrc.replace(new RegExp('_off\.','g'),'_on\.');
				this.src = imgsrc;
				this.onmouseout = function() {
					if (this.src.indexOf('_on') != -1) {
						var imgsrc = new String(this.src);
						imgsrc = imgsrc.replace(new RegExp('_on\.','g'),'_off\.');
						this.src = imgsrc;
					}
				}
			}
			if (this.src.indexOf('_off') != -1) {
				var imgsrc = new String(this.src);
				imgsrc = imgsrc.replace(new RegExp('_off\.','g'),'_on\.');
				this.src = imgsrc;
				this.onmouseout = function() {
					if (this.src.indexOf('_on') != -1) {
						var imgsrc = new String(this.src);
						imgsrc = imgsrc.replace(new RegExp('_on\.','g'),'_off\.');
						this.src = imgsrc;
					}
				}
			}
		}
	});
	
	$('nivenlink_login').value = 'username';
	
	
	$ES('div.landingcategory').addEvents({
		'mouseover': function() {
			this.style.cursor = 'pointer';
			$ES('.landingarrow img', this)[0].src = '/images/portfolio/landing_arrow_on.gif';
		},
		'mouseout': function() {
			$ES('.landingarrow img', this)[0].src = '/images/portfolio/landing_arrow_off.gif';
		},
		'click': function() {
			document.location = $ES('a', this)[0].getAttribute('href');
		}
	});

	$ES('div.categoryproject').addEvents({
		'mouseover': function() {
			this.style.cursor = 'pointer';
			$ES('.projectarrow img', this)[0].src = '/images/portfolio/landing_arrow_on.gif';
		},
		'mouseout': function() {
			$ES('.projectarrow img', this)[0].src = '/images/portfolio/landing_arrow_off.gif';
		},
		'click': function() {
			document.location = $ES('a', this)[0].getAttribute('href');
		}
	});
	
	$ES('#whatopen').addEvents({
		'mouseover': function() {
			if ($('nivenlink_whatcontent').className.indexOf('hidden') != -1) {
				setClass($('nivenlink_whatcontent'), 'visible', 'hidden');
				$ES('img', $('whatclose'))[0].src = '/images/common/helpclose_off.gif';
			} 
			setClass($('nivenlink_helpcontent'), 'hidden', 'visible');
		}
	});

	$ES('#helpopen').addEvents({
		'mouseover': function() {
			if ($('nivenlink_helpcontent').className.indexOf('hidden') != -1) {
				setClass($('nivenlink_helpcontent'), 'visible', 'hidden');
				$ES('img', $('helpclose'))[0].src = '/images/common/helpclose_off.gif';
			} 
			setClass($('nivenlink_whatcontent'), 'hidden', 'visible');
		}
	});
	
	$ES('#whatclose').addEvents({
		'mouseover': function() {
			$ES('img', this)[0].src = '/images/common/helpclose_on.gif';
		},
		'mouseout': function() {
			$ES('img', this)[0].src = '/images/common/helpclose_off.gif';
		},
		'click': function() {
			setClass($('nivenlink_whatcontent'), 'hidden', 'visible');
		}
	});

	$ES('#helpclose').addEvents({
		'mouseover': function() {
			$ES('img', this)[0].src = '/images/common/helpclose_on.gif';
		},
		'mouseout': function() {
			$ES('img', this)[0].src = '/images/common/helpclose_off.gif';
		},
		'click': function() {
			setClass($('nivenlink_helpcontent'), 'hidden', 'visible');
		}
	});
}

function doSIFR() {
	if(typeof sIFR == "function"){
		sIFR.replaceElement(".bodycopy h2", named({sFlashSrc: "/swf/myriadpro.swf", sColor: "#0061d2", sBgColor: '#ffffff', sLinkColor: '#ffffff', sHoverColor: '#ec1f2d', sWmode: 'transparent'}));
		sIFR.replaceElement("div#project_text h1", named({sFlashSrc: "/swf/myriadpro.swf", sColor: "#0061d2", sBgColor: '#ffffff', sLinkColor: '#ffffff', sHoverColor: '#ec1f2d', sWmode: 'transparent'}));
	}
}


function setClass(element, newValue, oldValue) {
	if(!newValue && !oldValue) {
		element.className = '';
		return;
	}

	//while(element.className.indexOf('  ') > -1) element.className = element.className.replace('  ', ' ');
	var classes = element.className.split(' ');
	if (oldValue != null && oldValue != '') {
		while (classes.length) { 
			var position = classes.indexOf(oldValue);
			if(position == -1) break;
			var temp = classes.splice(position, 1);
		}
	}
	if (newValue != null && newValue != '') { 
		while (classes.length) { 
			var position = classes.indexOf(newValue); 
			if (position == -1) break;
			var temp = classes.splice(position, 1);
		}
		var temp = classes.push(newValue);
	}
	element.className = classes.join(' ');
}

function callinspires(caller) {
	activeiphoto = 1;
	var vidAjax = new Ajax(caller.getAttribute('href'), {method: 'get', update: $('home_inspires'), evalScripts: true}).request();
//	caller.getAttribute('href')
	return false;
}

var activeiphoto = 1;

function swapphoto(whichphoto, photosrc) {
	$('inspires_photo').src = '/images/home/inspires/' + photosrc;
	setClass($('ip' + whichphoto), 'active', ' ');
	setClass($('ip' + activeiphoto), ' ', 'active');
	activeiphoto = whichphoto;
}

function swapnextphoto() {
	try {
		$('ip' + (activeiphoto + 1)).style.visibility = 'visible';
		var ocstr = new String($('ip' + (activeiphoto + 1)).onclick);
		if (ocstr.indexOf('anonymous') == -1) {
			var nextphoto = ocstr.substring(ocstr.indexOf('"') + 1, ocstr.lastIndexOf('"'));
		} else {
			var nextphoto = ocstr.substring(ocstr.indexOf('\'') + 1, ocstr.lastIndexOf('\''));
		}
		swapphoto(activeiphoto + 1, nextphoto);
	} catch(err) {
		$('ip1').style.visibility = 'visible';
		var ocstr = new String($('ip1').onclick);
		if (ocstr.indexOf('anonymous') == -1) {
			var nextphoto = ocstr.substring(ocstr.indexOf('"') + 1, ocstr.lastIndexOf('"'));
		} else {
			var nextphoto = ocstr.substring(ocstr.indexOf('\'') + 1, ocstr.lastIndexOf('\''));
		}
		swapphoto(1, nextphoto);
	}
}