/**
*	Ten Questions javascript module.
*	author:	bvaeth@ologie.com
*/

var TenQuestions = new Class(
{
	Implements: Events,
	
	initialize: function(canvas)
	{
		this.canvas = canvas;
		this.canvas.empty();
		this.canvas.grab(new Element('div',{'class':'ts-ten-questions'}));
		
		this.leftColumn = new LeftColumn();
		this.rightColumn = new RightColumn();
		
		this.canvas.getFirst().grab( this.leftColumn );
		this.canvas.getFirst().grab( this.rightColumn );
		
		$$('div.ts-ten-questions a.ts-link')[0].fireEvent('click');
		
		this.preload.delay(200);
	},
	
	preload: function()
	{
		data.each(function(item)
		{
			item.images.each(function(img)
			{
				new Element('img', {alt:img.alt, src:img.src, width:img.width, height:img.height});
			});
		});
	}
});

var LeftColumn = new Class(
{
	
	initialize: function()
	{
		this.el = new Element('div',{'class':'ts-left-column'});
		this.canvas = new Element('div', {'style':'margin:50px 0 0 0;'});
		this.el.grab(this.canvas);
		
		this.canvas.grab( new Element('p', {'class':'ts-welcome-msg','html':'Here are answers to eleven questions<br/>we hear again and again.'}) );
		
		data.each(this.addButton.bind(this));
		
		return this.el;
	},
	
	addButton: function(the_data)
	{
		var btn = new LinkButton(the_data);
		this.el.getFirst().grab(btn);
	}
});

var LinkButton = new Class(
{
	initialize: function(the_data)
	{
		this.data = the_data;
		this.button = new Element('a',{'class':'ts-link', 'href':'#', 'html':this.data.question});
		
		this.button.addEvent('click', this.onclick.bind(this));
		
		return this.button;
	},
	
	onclick: function()
	{
		$$('a.ts-link').removeClass('selected');
		this.button.addClass('selected');
		
		window.fireEvent('questionclick', this.data);
		return false;
	}
});

var RightColumn = new Class(
{
	initialize: function()
	{
		this.el = new Element('div', {'class':'ts-right-column'});
		this.el.grab( new Element('div', {'style':'margin:0 0 0 15px;'}) );
		
		this.canvas = this.el.getFirst();
		this.canvas.setStyle('opacity', 0);
		this.canvas.set('tween',{duration:500, transition:Fx.Transitions.Cubic.easeIn});
		
		this.canvas.grab( new Question() );
		this.canvas.grab( new Answer() );
		this.canvas.grab( new Details() );
		this.canvas.grab( new Links() );
		this.canvas.grab( new Images() );
		
		window.addEvent('questionclick', this.onQuestionClick.bind(this));
		
		return this.el;
	},
	
	onQuestionClick: function(the_data)
	{	
		this.data = the_data;
		this.fadeOut().chain(this.fadeIn.bind(this));
	},
	
	fadeOut: function()
	{
		return this.canvas.get('tween').start('opacity', 0);
	},
	
	fadeIn: function()
	{
		window.fireEvent('newdata', this.data)
		this.canvas.tween('opacity', 1);
	}
});

var Question = new Class(
{
	initialize: function()
	{
		this.el = new Element('div', {'html':'&nbsp;','class':'ts-question'});
		window.addEvent('newdata', this.onButtonClick.bind(this));
		
		return this.el;
	},
	
	onButtonClick: function(the_data)
	{
		this.el.set('html', the_data.question);
	}
});

var Answer = new Class(
{
	initialize: function()
	{
		this.el = new Element('div', {'html':'&nbsp;','class':'ts-answer'});
		window.addEvent('newdata', this.onButtonClick.bind(this));
		
		return this.el;
	},
	
	onButtonClick: function(the_data)
	{
		this.el.set('html', the_data.answer);
	}
});

var Details = new Class(
{
	initialize: function()
	{
		this.el = new Element('div', {'html':'&nbsp;','class':'ts-details'});
		window.addEvent('newdata', this.onButtonClick.bind(this));
		
		return this.el;
	},
	
	onButtonClick: function(the_data)
	{
		this.el.empty();
		the_data.details.each((function(txt)
		{  
			this.el.grab( new Element('p', {html:txt}) );
		}).bind(this));
	}
});

var Links = new Class(
{
	initialize: function()
	{
		this.el = new Element('div', {'html':'&nbsp;', 'class':'ts-links'});
		window.addEvent('newdata', this.onButtonClick.bind(this));
		
		return this.el;
	},
	
	onButtonClick: function(the_data)
	{
		this.el.empty();
		the_data.links.each((function(lnk)
		{  
			this.el.grab( new Element('a', {href:lnk.href, title:lnk.title, html:lnk.title + ' &#187;'}) );
		}).bind(this));

	}
});

var Images = new Class(
{
	initialize: function()
	{
		this.el = new Element('div', {'html':'&nbsp;', 'class':'ts-image-div'});
		window.addEvent('newdata', this.onButtonClick.bind(this));
		
		return this.el;
	},
	
	onButtonClick: function(the_data)
	{
		this.el.empty();
		the_data.images.each((function(img)
		{  
			this.el.grab( new Element('img', {src:img.src, alt:img.alt, height:img.height, width:img.width}) );
		}).bind(this));
	}
});



var data = 
[
 	{
 		question:	'How late is the library really open?',
	 	answer:		'Nope, Junior isn&rsquo;t pulling your leg.',
	 	details:	[
	 	        	 'Our library is open until midnight during the week. So when you call late at night (just to check in), and your student claims to be buried in a book, it&rsquo;s probably true. We know that not all students keep the same schedule. And we want to be accommodating&#8212;even late. So the lights are on, the help desk is staffed, and the computers are booted up, to be sure that every resource is available.',
	 	        	 'Just ask to speak with a librarian. They&rsquo;re happy to serve as witness to your student&rsquo;s hard work. And they might be looking for some company toward the end of the evening.'
	 	        	],
	 	links:		[
	 	      		 {title:'See our library&rsquo;s amenities', href:'http://www.capital.edu/14207/'}
	 	      		],
	    images:		[
	           		 {alt:'library', src:'tenquestions/library1.jpg', height:133, width:266},
	           		 {alt:'library', src:'tenquestions/library2.jpg', height:133, width:266}
	           		]
 	},
 	{
 		question:	'Where do students live?',
	 	answer:		'We promise, it&rsquo;s nothing like <i>Animal House</i>.',
	 	details:	[
	 	        	 'Unlike many schools, most of our students live in residence halls&#8212;many for all four years, not just their first. It&rsquo;s a great way to connect with new friends and get involved on campus, and the easiest way to find someone to help study for an exam.',
	 	        	 'When you visit, you won&rsquo;t find blocks of substandard apartments surrounding campus, or the artifacts from a weekend&rsquo;s worth of parties. (And that&rsquo;s the way we like it.)'
	 	        	],
	 	links:		[
	 	      		 {title:'Learn more about our residence halls', href:'http://www.capital.edu/14832/'},
	 	      		 {title:'How to visit campus', href:'http://www.capital.edu/108/'}
	 	      		],
	    images:		[
	           		 {alt:'dorms', src:'tenquestions/dorms1.jpg', height:133, width:266},
	           		 {alt:'dorms', src:'tenquestions/dorms2.jpg', height:133, width:266}
	           		]
 	},
 	{
 		question:	'Is the food healthy?',
	 	answer:		'It&rsquo;s largely up to your child&rsquo;s definition of nourishment.',
	 	details:	[
	 	        	 'Part of going to college is striking it out on your own, making your own decisions. So we provide scores of dining options. There are always fresh vegetables, both as side dishes and at our salad bar. We make sure to serve at least five kinds of fresh fruit daily&#8212;locally grown whenever possible. And we offer special choices to meet any dietary requirement.',
	 	        	 'Of course, there&rsquo;s pizza, too. It wouldn&rsquo;t be college if there weren&rsquo;t. And dotted along Main Street are wonderful cafes and casual eateries for when your student needs some time outside the campus gates.'
	 	        	],
	 	links:		[
	 	      		 {title:'Capital Dining', href:'http://www.capital.edu/2291/'},
	 	      		 {title:'Main Street Restaurants', href:'http://maps.google.com/maps?f=q&source=s_q&abauth=843d453a%3AHfTj1iBrdsYbW4wkw-0Huched7k&view=text&gl=us&q=bexley+main+street+restaurant&btnG=Search+Maps'}
	 	      		],
	    images:		[
	           		 {alt:'food', src:'tenquestions/food1.jpg', height:133, width:266},
	           		 {alt:'food', src:'tenquestions/food2.jpg', height:133, width:266}
	           		]
 	},
 	{
 		question:	'Where&rsquo;s the washing machine?',
	 	answer:		'Just down the hall. (Don&rsquo;t let your child&rsquo;s appearance convince you otherwise.)',
	 	details:	[
	 	        	 'Washing machines and dryers are located in every residence hall across campus. And, what&rsquo;s more, using them is free. (We think college students need every incentive to keep their laundry clean.)',
	 	        	 'We do not, however, offer a class on separating colors from whites. Something to keep in mind when your son or daughter comes home for Thanksgiving with a pile of pink socks.'
	 	        	],
	 	links:		[
	 	      		 {title:'Residence hall amenities', href:'http://www.capital.edu/3197/'}
	 	      		],
	    images:		[
	           		 {alt:'food', src:'tenquestions/wash1.jpg', height:133, width:266},
	           		 {alt:'food', src:'tenquestions/wash2.jpg', height:133, width:266}
	           		]
 	},
 	{
 		question:	'Are there internship opportunities?',
	 	answer:		'Just make sure your student has some adequate interview attire.',
	 	details:	[
	 	        	 'One of the greatest advantages to being situated in a big city is the real-world opportunities it affords. Columbus is home to Fortune 500 companies and the state government. It&rsquo;s filled with successful small businesses, a bustling arts community, and a trio of professional sports teams.',
	 	        	 'Our students have interned at Abercrombie & Fitch&rsquo;s corporate offices, at Nationwide Insurance, and for the governor, to name a few. There are numerous opportunities both in Columbus and around the country.'
	 	        	],
	 	links:		[
	 	      		 {title:'See one student&rsquo;s experience', href:'http://www.capital.edu/10524/'},
	 	      		 {title:'Career services', href:'http://www.capital.edu/careerservices'}
	 	      		],
	    images:		[
	           		 {alt:'internship', src:'tenquestions/internship1.jpg', height:133, width:266},
	           		 {alt:'internship', src:'tenquestions/internship2.jpg', height:133, width:266}
	           		]
 	},
 	{
 		question:	'Is the rec center close by?',
	 	answer:		'Walking there from anywhere on campus shouldn&rsquo;t be considered a workout.',
	 	details:	[
	 	        	 'The Capital Center is a new, 126,000-square-foot facility whose state-of-the-art equipment is available to both varsity athletes and all other students. It features a competition-sized indoor track, a 2,100-seat arena, and a 2,500-seat stadium outdoors.',
	 	        	 'Whether your student is destined to make a career from her athletic prowess or he has two left feet, there are plenty of opportunities to stay in shape.'
	 	        	],
	 	links:		[
	 	      		 {title:'The Capital Center', href:'http://www.capital.edu/14196/'},
	 	      		 {title:'Varsity sports', href:'http://www.capital.edu/71/'},
	 	      		 {title:'Intramural sports', href:'http://www.capital.edu/5819/'}
	 	      		],
	    images:		[
	           		 {alt:'gym', src:'tenquestions/gym1.jpg', height:133, width:266},
	           		 {alt:'gym', src:'tenquestions/gym2.jpg', height:133, width:266}
	           		]
 	},
 	{
 		question:	'What&rsquo;s the policy on alcohol?',
	 	answer:		'Responsibility is everything.',
	 	details:	[
	 	        	 'We don&rsquo;t tolerate underage drinking on our campus. We don&rsquo;t allow binge drinking behaviors, either. When RAs, faculty or staff witness this behavior, disciplinary action is taken, along with mandatory classes to educate the student about appropriate behavior.',
	 	        	 'Students here know how to have fun, but they know how to be responsible, too. We&rsquo;re not a party school (and our neighborhood isn&rsquo;t that type of atmosphere either).'
	 	        	],
	 	links:		[
	 	      		 {title:'Student rights and standards', href:'http://www.capital.edu/14204/'}
	 	      		],
	    images:		[
	           		 {alt:'alcohol', src:'tenquestions/alcohol1.jpg', height:133, width:266},
	           		 {alt:'alcohol', src:'tenquestions/alcohol2.jpg', height:133, width:266}
	           		]
 	},
 	{
 		question:	'Are students involved in the community?',
	 	answer:		'Overwhelmingly so.',
	 	details:	[
	 	        	 'Leadership is something that&rsquo;s stressed at Capital. And part of becoming a good leader is taking the time to serve others&#8212;without the expectation of reward. Service is central to our campus. Students spend free time volunteering in the community (and around the world too).',
	 	        	 'Many students take an &ldquo;alternative spring break,&rdquo; where they travel to underserved areas to provide care and offer assistance. Sure, it looks good on a resum&eacute;. But even if it didn&rsquo;t, our students are the type who would do it anyway.'
	 	        	],
	 	links:		[
	 	      		 {title:'Service Opportunities', href:'http://www.capital.edu/10142/'}
	 	      		],
	    images:		[
	           		 {alt:'community', src:'tenquestions/community1.jpg', height:133, width:266},
	           		 {alt:'community', src:'tenquestions/community2.jpg', height:133, width:266}
	           		]
 	},
 	{
 		question:	'Is Capital safe?',
	 	answer:		'Yes. We make sure of it.',
	 	details:	[
	 	        	 'Capital University is an enclosed campus with a tight-knit community. And we&rsquo;re surrounded by one of Columbus&rsquo;s safest and most affluent suburbs. Still, safety is not something we take lightly.',
	 	        	 'We have our own public safety officers patrolling campus 24 hours a day. And they&rsquo;re easy to reach&#8212;for any reason&#8212;by telephone. The City of Bexley&rsquo;s police department is located just across the street from our campus and coordinates closely with our officers.'
	 	        	],
	 	links:		[
	 	      		 {title:'Get safety details', href:'http://www.capital.edu/3042/'}
	 	      		],
	    images:		[
	           		 {alt:'safe', src:'tenquestions/safe1.jpg', height:133, width:266},
	           		 {alt:'safe', src:'tenquestions/safe2.jpg', height:133, width:266}
	           		]
 	},
 	{
 		question:	'What if my student gets sick?',
	 	answer:		'Help is only a few steps away.',
	 	details:	[
	 	        	 'It&rsquo;s an inevitable fact of college life that sometimes, students get sick. Colds and the flu travel fast. That&rsquo;s why we have a fully staffed primary care health clinic on campus.',
	 	        	 'A nurse practitioner and physician conduct tests, administer prescriptions and refer students to additional care when needed. And, with a quick stop at the Capital Court, fresh, hot soup will help speed the road to recovery.'
	 	        	],
	 	links:		[
	 	      		 {title:'The Kline Health Clinic', href:'http://www.capital.edu/3043/'}
	 	      		],
	    images:		[
	           		 {alt:'sick', src:'tenquestions/sick1.jpg', height:133, width:266}
	           		]
 	},
 	{
 		question:	'Do I need to buy my student a computer?',
	 	answer:		'Despite the objections you&rsquo;ll hear, no.',
	 	details:	[
	 	        	 'While having a personal computer can be immensely helpful to a student, it&rsquo;s not a requirement. Each residence hall has a computer lab, as do the library and several other locations around campus.',
	 	        	 'For those with notebook computers, wireless Internet is accessible throughout the entire campus, which makes it easy to do research (or check Facebook) from anywhere&#8212;even outdoors.'
	 	        	],
	 	links:		[
	 	      		 {title:'Technology resources', href:'http://www.capital.edu/285/'}
	 	      		],
	    images:		[
	           		 {alt:'computer', src:'tenquestions/computer1.jpg', height:133, width:266},
	           		 {alt:'computer', src:'tenquestions/computer2.jpg', height:133, width:266}
	           		]
 	}
];


window.addEvent('domready', function()
{ 
	new Element('link', {'rel': 'stylesheet', 'media': 'screen', 'type': 'text/css', 'href':'tenquestions/tenquestions.css' }).inject(document.head);
	new TenQuestions($$('td.column3')[0]);   

});