/**
 * @author bdgeorge
 * @version 1.1 27/01/2009 Replaced .html() with .text() to work around bug with Safari 2.0.4
 */
$(document).ready(function(){
deck.init();
});
//Helper functions
function remSuffix(a,b){
	//removes suffix b from filename a without removing the file extension
	var lastdot = a.lastIndexOf(b + '.');
	if (lastdot==-1){
		return a;
	} else {
		var ext = a.slice(lastdot+b.length,a.length);
		return a.slice(0,lastdot) + ext;
	}		
}
function addSuffix(a,b){
	//adds suffix b to filename a without removing the file extension
	var lastdot = a.lastIndexOf(".");
	if (lastdot==-1){
		return a;
	} else {
		var ext = a.slice(lastdot,a.length);
		return a.slice(0,lastdot) + b + ext;
	}
	
}
//Quiz-Slideshow object
var deck = {
		slides:[	
				{
				title:"Slide 1",
				content:"Do you live in a house not a Home?",
				image:"path to some image"
				},
				{
				title:"Slide 2",
				content:"Are there minute levels of detailing needed to finish off your project?",
				image:"path to some image"
				},
				{
				title:"Slide 3",
				content:"Do you need a common thread to pull your spaces together?",
				image:"path to some image"
				},
				{
				title:"Slide 4",
				content:"Do you need someone sympathetic to all practices to work towards a common goal?",
				image:"path to some image"
				},
				{
				title:"Slide 5",
				content:"Are you interested in a team who will reinterpret what you want, not what they used on the last house?",
				image:"path to some image"
				}	
		],
		pass:	"Please call us. We should meet soon. Sara 0304939193",
		fail:	"The curious paradox is that when I accept myself just as I am, then I can change.",
		links:	"<a href='#' id='yes' class='next'><img src='images/quiz-button.gif' class='wh-roll' width='19' height='19' />YES</a>"+
				"<a href='#' id='no' class='next'><img src='images/quiz-button.gif' class='wh-roll' width='19' height='19' />NO</a>",
		quote:	'#quote',
		wrapper:"#slide",
		yes:	"#yes",
		no:		"#no",	
		next:	".next",	
		/***********************************************************/
		/*********** No need to change below here ******************/
		/***********************************************************/
		index: 0,
		yesCount:0,
		noCount:0,
		init: function(){
			//load the first slide content immediately
			$(deck.quote).text(deck.slides[deck.index].content);
			deck.index++;			
			//append the yes no buttons
			$(deck.wrapper).append(deck.links);
			//Add roll over images to them
			$('img.wh-roll').hover(
				function(){
					//Over function
					this.src = addSuffix(this.src,'_on');
				},
				function(){
					//Out function
					this.src = remSuffix(this.src,'_on');
				});
			//Add the quiz tracking functions to them
			$(deck.yes).click(function(){
				//console.log("in the click, index "+deck.index);
				//add the click events to them	
				deck.yesCount++;		
				deck.nextSlide();
			});
			$(deck.no).click(function(){
				//console.log("in the click, index "+deck.index);
				//add the click events to them	
				deck.noCount++;		
				deck.nextSlide();
			});			
		},
		nextSlide: function(){
			//fade out current slide
			$(deck.wrapper).fadeOut("slow",function(){
				//change the content
				if(deck.index <= deck.slides.length - 1){
					$(deck.quote).text(deck.slides[deck.index].content);
				}else{
					$(deck.next).remove();
					if(deck.noCount == 5){
						$(deck.quote).text(deck.fail);
					} else {
						$(deck.quote).text(deck.pass);
					}									
				}
			deck.index++;									
			}).fadeIn("slow");	
		}	
	}