/* call these events when the page loads */
addLoadEvent(blurLinks);
addLoadEvent(validateContactForm);
addLoadEvent(setupMainMenu);
addLoadEvent(confirmDelete); 
addLoadEvent(EmailUnobsfuscate);




function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}



/* remove all focus lines from links when clicked */
function blurLinks() {
	var links = document.getElementsByTagName('a');
	for (i=0;i<links.length;i++) {
		links[i].onfocus = function() {
			this.blur();
		}
	}
}





function validateContactForm() {
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	
	if (document.getElementById('frmContact')) {
		var frm = document.getElementById('frmContact');
		frm.onsubmit = function() {
			
			var reqFields = Array('txtName','txtEmail','txtSubject','txtMessage');
			
			if ( !isValid(reqFields) ) {
				alert('Please fill in all fields');
				return false;
			} else {
				return true;
			}
		}
	}
	

}


/* mouseover for main menu nav */
function setupMainMenu() {
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	
	var nav = document.getElementById('nav');
	
	if (nav) {
		
		var links = nav.getElementsByTagName('a');
		
		// start loop at 1 to bypass logo
		for (i=1;i<links.length;i++) {
			
			links[i].onmouseover = function() {
				this.firstChild.setAttribute('src', 'assets/images/btn/'+this.id+'_over.gif');
			}
			
			links[i].onmouseout = function() {
				this.firstChild.setAttribute('src', 'assets/images/btn/'+this.id+'_up.gif');
			}
		}
	}
	
	
}




function rollOverListings(name) {
	
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	
	var listRow = document.getElementById(name).getElementsByTagName('ul');
	for (i=0;i<listRow.length;i++) {
	
	var upStateColor = '';
	
		listRow[i].onmouseover = function() {
			
			if (this.className!='heading' ) {
				upStateColor = this.style.backgroundColor;
				this.style.backgroundColor='#cceeff';
			}
		}
		
		listRow[i].onmouseout = function() {
			
			if (this.className!='heading' ) {
				this.style.backgroundColor=upStateColor;
			}
		}
	}
}






function confirmDelete() {
	
	var buttons = document.getElementsByTagName('a');
	
	
	
	// action to take for delete buttons
	for (i=0;i<buttons.length;i++) {
		if (buttons[i].className=='delete') {
			
			buttons[i].onclick = function() {
				
				var status1 = confirm('Confirmation 1 of 2\n\nAre you sure you want to delete this item?\nTHIS ACTION CAN NOT BE UNDONE.\n\n\nClick OK to proceed or Cancel to Exit.');
				if (status1==false) {
					return false;
				} else {
					var status2 = confirm('Confirmation 2 of 2\n\nIf you continue this item and \nany linked information will be deleted.\n\n\nClick OK to DELETE this item or Cancel to Exit.');
					if (status2==false) {
						return false;
					} else {
						return true;
					}
				}
				
				
			}
		}
	} // end delete action
	
	
}




function subscribe() {
	
	var params = $('frmSubscribe').serialize();
	
	new Ajax.Updater('subscriptionData', 'http://www.summitxperience.com/assets/http_requests/action_subscribe.php', {
	  parameters: params
	});
	
	return false;
}





// itenerary functions
function toggleItenerary(id) {
	Effect.toggle(id, 'appear', { duration: 1.0 });
}






function EmailUnobsfuscate() {
	
	// find all links in HTML
	var link = document.getElementsByTagName && document.getElementsByTagName("a");
	var email, e;
	
	// examine all links
	for (e = 0; link && e < link.length; e++) {
	
		// does the link have use a class named "email"
		if ((" "+link[e].className+" ").indexOf(" email ") >= 0) {
		
			// get the obfuscated email address
			email = link[e].firstChild.nodeValue.toLowerCase() || "";
			
			// transform into real email address
			email = email.replace(/dot/ig, ".");
			email = email.replace(/\(at\)/ig, "@");
			email = email.replace(/\s/g, "");
			
			// is email valid?
			if (/^[^@]+@[a-z0-9]+([_\.\-]{0,1}[a-z0-9]+)*([\.]{1}[a-z0-9]+)+$/.test(email)) {
			
				// change into a real mailto link
				link[e].href = "mailto:" + email;
				link[e].firstChild.nodeValue = email;
		
			}
		}
	}
}



function embedVideo(id, videoFile, iWidth, iHeight, boolAutoplay, splashImg) {
	
		
	new flashembed(id, { 
		src: "../assets/video/FlowPlayerLight.swf", width: iWidth, height: iHeight, wmode: 'transparent' }, {
			config: {
				autoPlay: boolAutoplay,
				autoRewind: true,
				showStopButton: true, 
				showScrubber: true, 
				showVolumeSlider: false,
				showMuteVolumeButton: false, 
				showFullScreenButton: false, 
				showMenu: false, 
				controlsOverVideo: 'ease',
				controlBarBackgroundColor: -1,
				backgroundColor: -1,
				controlBarGloss: 'high',
				bufferLength:55,
				timeDisplayFontColor:0x1c6c91,
				startingBufferLength:25,
				bufferingAnimationColor:0x1c6c91,
				initialScale: 'scale',
				videoFile: videoFile,
				splashImageFile: splashImg,
				loop:false
			}
		}
	);
}





