// JavaScript Document

var questions = new Array('question01','question02','question03','question04','question05');
var results = new Array('result01','result02','result03');
var questionAnswers = new Array();

var questionIndex = 0;



var hideQuizScreens = function(){
	for(var i=0; i<questions.length; i++){
		$(questions[i]).setStyle('display','none');
	}
	for(var i=0; i<results.length; i++){
		$(results[i]).setStyle('display','none');
	}
}
var showProgess = function(){
	var msg = ""
	
	for(var i=0; i<questionAnswers.length; i++){
		msg += "Answer"+(i+1)+" => "+questionAnswers[i]+"\n";
	}
	
	//alert(msg)
}

var showResult = function(){
	
	hideQuizScreens();
	
	var As = 0;
	var Bs = 0;
	var Cs = 0;
	
	questionAnswers.each(function(item, index){
		//alert(index + " = " + item);
		switch(item){
			case "a":
				As++;
				break;
			case "b":
				Bs++;
				break;
			case "c":
				Cs++;
				break;
		}
	});
	
	var resultScreen = 'result02';
	/*
	if(As == (Bs || Cs)){
		resultScreen = 'result01';
	}
	if(Bs == (As || Cs)){
		resultScreen = 'result02';
	}
	if(Cs == (As || Bs)){
		resultScreen = 'result03';
	}
	*/
	if(As > (Bs || Cs)){
		//alert("mostly As:"+As)
		resultScreen = 'result01';
	}
	if(Bs > (As || Cs)){
		//alert("mostly Bs:"+Bs)
		resultScreen = 'result02';
	}
	if(Cs > (As || Bs)){
		//alert("mostly Cs:"+Cs)
		resultScreen = 'result03';
	}
	
	if(resultScreen == 'result01'){
		initMainImage('/desireme/assets/images/the-seduction-quiz/escada-incredible-me.jpg','Escada Incredible Me')
	}else{
		initMainImage('/desireme/assets/images/the-seduction-quiz/escada-desire-me-olivia.jpg','Escada Desire Me')	
	}
	$(resultScreen).fade('hide')
	$(resultScreen).setStyle('display','block');
	$(resultScreen).fade('in')
	
	if(localeShort == 'de'){
		<!-- Tag for Activity Group: Escada - Desire Me, Activity: DM-Seductionquiz-Result -->
		
		<!-- Beginn des DoubleClick-Spotlight-Tag: Bitte nicht entfernen.-->
		<!-- Aktivitätsname dieses Tags lautet:DM-Seductionquiz-Result -->
		<!-- Website-URL, bei der das Tag eingefügt werden soll: http://- -->
		<!-- Erstellungsdatum:8/20/2009 -->
		var axel = Math.random()+"";
		var a = axel * 10000000000000;
		var spotlighttag = '<IMG SRC="http://ad.de.doubleclick.net/activity;src=1243939;type=escad520;cat=desir002;ord=1;num='+ a + '?" WIDTH=1 HEIGHT=1 BORDER=0 />';
		//document.write(spotlighttag);
		<!-- Ende des DoubleClick-Spotlight-Tag: Bitte nicht entfernen.-->	
		
		$('DoubleClickDynamicSpotlightTag').set('html',spotlighttag);
		
	}
}
var nextQuestion = function(){
	
	if(questionIndex == 0){
		$('intro').setStyle('display','none');
		initVideo('http://media.escada-fragrances.com/desireme/assets/video/desireme30s.m4v');
	}
	
	if(questionIndex > 0 && questionIndex <= questions.length){
		
		var answers = $$('input[name=answer0'+String(questionIndex)+']');
		var answered = false;
		
		if(answers.length > 0){
			
			for(var i=0; i<answers.length; i++){
				if(answers[i].checked){
					answered = true;
					questionAnswers.push(answers[i].get('value'))
				}
			}
		}
		
		if(answered == false){
			alert("Please answer Question " + questionIndex + " of " + questions.length)
			return answered;
		}
		showProgess();
		
	}
	
	if(questionIndex < questions.length){
		
		var currentQuestion = questions[questionIndex]
			
		hideQuizScreens();
		
		$(currentQuestion).fade('hide')
		$(currentQuestion).setStyle('display','block');
		$(currentQuestion).fade('in')
		
		questionIndex++
		
	}else{
		
		showResult();
		
	}
	
}

var initVideo = function(video){
	if(correctFlashInstalled){
		var obj = new Swiff('/desireme/assets/flash/videoplayer.swf', {
			id: 'flashVideoObject',
			width: 552,
			height: 351,
			container: 'column02',
			params: {
				wmode: 'opaque',
				bgcolor: '#000000'
			},
			vars: {
				videoPath: video,
				videoLoop: true
			},
			callBacks: {
				//load: myOnloadFunc
			}
		});	
	}else if(Browser.Plugins.Quicktime){
		var qt = QT_GenerateOBJECTText_XHTML(video,
                        552, 351,             		// width & height
                        '',                         // required version of the ActiveX control, we're OK with the default value
                        'autoplay', 'true',         // autoplay the video?
						'loop', 'true',     		// Loop the video or not
                        'controller', 'false',      // show controller?
                        'enablejavascript', 'false',
                        'kioskmode', 'true',
                        'scale', 'tofit',           // scale to fit element size exactly so resizing works
                        'emb#id', 'qt_embed',    	// ID for embed tag only
                        'obj#id', 'qt_obj');     	// ID if container
		
		$('column02').set('html',qt)
	}
}

var initMainImage = function(image,alt){
	//initMainImage('/desireme/assets/images/the-seduction-quiz/escada-desire-me-olivia.jpg','Escada Desire Me')
	//initMainImage('/desireme/assets/images/the-seduction-quiz/escada-incredible-me.jpg','Escada Incredible Me')
	$('column02').fade('hide')
	$('column02').set('html','<img src="/desireme/images/552x351/552:351'+image+'" alt="'+alt+'" />');
	$('column02').fade('in')
	
}

var initQuiz = function(){
	
	hideQuizScreens();
	
	/*
	var objs = $$('div.galleryitem');
	
	objs.each(function(item, index){
		var linkObj = item.getChildren('a')[0];
		
			linkObj.addEvents({
				'click': function(){
					
					setGalleryLink(this.href,this.title);
					
					return false;
				}
			});
	});
	*/
	
}

window.addEvent('domready', function() {
									 
	initQuiz();
	
});
/*
window.addEvent('unload', function() {
									 
	var currentQuestion = window.location.href.split('#')[1]
	alert(currentQuestion);
					
	
});
*/
