var Nav = {
	init: function() {
		if ($$('#globalNav li.current')[0].previous()) {
			$$('#globalNav li.current')[0].previous().down().setStyle({
		  		'border': 'none'
			});
		}
	}
}

var Slide = {
	init: function() {
		if (!$('slide1Link')) return;
		Slide.click('slide1');
		Slide.click('slide2');
		Slide.click('slide3');
		Slide.click('slide4');
		Slide.click('slide5');
		Slide.previous();
		Slide.next();
		Slide.preload();
	},
	click: function(slideId) {
		Event.observe(slideId + 'Link', 'click', function() {
			$('slide').down().src = Slide[slideId].img;
			$('slideInformation').update(Slide[slideId].text);
			Slide.clear();
			this.up().addClassName('current');
			Slide.currentSlide = Number(slideId.substr(5,1));
		});
	},
	previous: function() {
		Event.observe('previousLink', 'click', function() {
			var slidePosition;
			(Slide.currentSlide == 1) ? slidePosition = 5 : slidePosition = Slide.currentSlide - 1;
			var slideNum = "slide" + String(slidePosition);
			$('slide').down().src = Slide[slideNum].img;
			$('slideInformation').update(Slide[slideNum].text);
			Slide.clear();
			var linkName = "slide" + String(slidePosition) + 'Link';
			$(linkName).up().addClassName('current');
			Slide.currentSlide = slidePosition;
		});
	},
	next: function() {
		Event.observe('nextLink', 'click', function() {
			var slidePosition;
			(Slide.currentSlide == 5) ? slidePosition = 1 : slidePosition = Slide.currentSlide + 1;
			var slideNum = "slide" + String(slidePosition);
			$('slide').down().src = Slide[slideNum].img;
			$('slideInformation').update(Slide[slideNum].text);
			Slide.clear();
			var linkName = "slide" + String(slidePosition) + 'Link';
			$(linkName).up().addClassName('current');
			Slide.currentSlide = slidePosition;
		});
	},
	clear: function() {
		$$('#slideNav li').each(function(el) {
			el.removeClassName('current');
		});
	},
	preload: function() {
		var imgs = [Slide.slide2.img, Slide.slide3.img, Slide.slide4.img, Slide.slide5.img];
		imgs.each(function(i) {
			var img = new Image();
			img.src = i;
		});
	},
	currentSlide: 1,
	"slide1": {
		"img": "images/slide1.png",
		"text": "<h3>Increase awareness and cross-pollination.</h3><p><strong>Help your researchers learn more about each other's backgrounds and work.</strong></p><p><strong>Help new discoveries and best practices spread throughout your organization.</strong></p>"
	},
	"slide2": {
		"img": "images/slide2.png",
		"text": "<h3>Tap internal expertise.</h3><p><strong>Your researchers have accumulated years of valuable expertise in and outside their current field.</strong></p><p><strong>Tap this internal value by helping researchers find the right internal expert at the right time.</strong></p>"
	},
	"slide3": {
		"img": "images/slide4.png",
		"text": "<h3>Extract value from resources.</h3><p><strong>Promote the use of new technologies by more people in your organization.</strong></p><p><strong>Help your researchers find existing internal equipment and reagents for their experiments.</strong></p>"
	},
	"slide4": {
		"img": "images/slide3.png",
		"text": "<h3>Build bridges between silos.</h3><p><strong>Help your researchers connect and collaborate across divisions, locations and competencies.</strong></p><p><strong>Integrate new employees and acquired companies into the way you work.</strong></p>"
	},
	"slide5": {
		"img": "images/slide5.png",
		"text": "<h3>Recognize and motivate good work.</h3><p><strong>Engage with your community of researchers.</strong></p><p><strong>Use the network as a venue to recognize great work and progress on a regular basis.</strong></p>"
	}
}

var Quote =  {
	init: function() {
		if (!$('quote1')) return;
		Quote.click('quote1');
		Quote.click('quote2');
		Quote.click('quote3');
	},
	click: function(quoteId) {
		Event.observe(quoteId, 'click', function() {
			$('quote').update(Quote[quoteId]);
			Quote.clear();
			this.down().src = "images/fullCircle.gif";
		});
	},
	clear: function() {
		$$('#circles img').each(function(el) {
			el.src = "images/emptyCircle.gif";
		});
	},
	"quote1": "\"I have wanted a site such as this since I first started at [Large Biotech]... I was truly amazed at how well organized, simplistic, user-friendly, helpful, and informative this site is ...I believe that this will be the first step in a new era of openness and communication here.\"",
	"quote2": "\"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.\"",
	"quote3": "\"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\""
}

var Validate = {
	init: function() {
		if (!$('contact')) return;
		Event.observe('contact', 'submit', function(event) {
			var msg = '';
			var error = 0;
			
			if ($('name').value == '') {
				msg += '<p class="error">Please enter your name!</p>';
				$('name').setStyle({
			  		'borderColor': 'red'
				});
				error = 1;
			}
			
			if ($('title').value == '') {
				msg += '<p class="error">Please enter your title!</p>';
				$('title').setStyle({
			  		'borderColor': 'red'
				});
				error = 1;
			}
			
			if ($('company').value == '') {
				msg += '<p class="error">Please enter your company!</p>';
				$('company').setStyle({
			  		'borderColor': 'red'
				});
				error = 1;
			}
			
			if ($('email').value == '') {
				msg += '<p class="error">Please enter your email!</p>';
				$('email').setStyle({
			  		'borderColor': 'red'
				});
				error = 1;
			}
			
			if (error == 1) {
				$('error').update(msg);
				Event.stop(event);
			}
		});
	}
}

document.observe('dom:loaded', function() {
	Nav.init();
	Slide.init();
	Quote.init();
	Validate.init();
});

