var mainPageLinks = {
	/*'watchtheproducts' : '/Products.aspx',*/
	'questions' : '/Vote.aspx',
	'stamp1_upd' : '/Lifestuff.aspx',
	'stamp2_upd' : '/Tetris.aspx'			
}

$(document).ready(function(){
	
	$('#pencil_bkmrk').click(function(){
		$('#banner_container .center').css('backgroundImage', 'url(/i/bg.banner-esc.jpg)');
	});
	
	$('#play_upd div').jrumble({
		rumbleEvent: 'hover',
		rumbleSpeed: 120,
		rangeX: 3,
		rangeY: 3
	});
	
	$('#news_hot').jrumble({
		rumbleEvent: 'hover',
		rumbleSpeed: 120,
		rangeX: 3,
		rangeY: 3
	});
	
	$.each(mainPageLinks, function(index, value){
		$("#"+index).click(function(e){
			t.location.href = value;
		});
	});
		
	swfobject.embedSWF("f/pad.swf", "check_flash", "450", "400", "10.0.0", null, null, {"wmode":'transparent'});
	/*
	swfobject.embedSWF("f/banners/soft.swf", "banner1", "550", "324", "10.0.0", null, null, {"wmode":'transparent', 'allowScriptAccess':'always'});
	*/
	/*
	swfobject.embedSWF("f/banners/konkurs.swf", "banner1", "550", "324", "10.0.0", null, null, {"wmode":'transparent', 'allowScriptAccess':'always'});
	*/
	/*
	swfobject.embedSWF("f/banners/colors.swf", "banner2", "550", "324", "10.0.0", null, null, {"wmode":'transparent', 'allowScriptAccess':'always'});
	*/
	serverURL = "";
	currentQuestionNum = 0;
	
	/* Функция получения списка возможных вопросов true/false с сервера */
	getQuestionsObject = function(){
		var uid = "B3465413-369E-4EAA-8D4A-FFD0CDB7DD60";
		var votes = [];
		// спрашиваем вопросы
		$.ajax({
			url:serverURL+'/websrv/voting/voting.asmx/GetVoting2?guid='+uid,
			type:'get',
			
			success:function(response){
				var answers = [],
					object = {}
				$("Question",response).each(function(key){
					answers = [];
					object = {};
					$(this).find('VotingAnswer').each(function(){
						answers.push({
							uid:$(this).find('uid').text(),
							answer:$(this).find('name').text(),
							image:$(this).find('File1Path').text(),
							image_active:$(this).find('File2Path').text(),
							percents:$(this).find('Percents').text(),
						})
					})
					object = {
						title: $($(this).find('name').get(0)).text(),
						answers: answers,
						uid: $($(this).find('uid').get(0)).text(),
						answered: -1, /* Индекс выбранного варианта ответа: -1 ничего не отвеченно. */
						
						// добавилось для "правды"
						points:$($(this).find('points').get(0)).text(),
						resulttext:$($(this).find('resulttext').get(0)).text()

					}
					votes.push(object);	
				});
				
				var url = window.location.hash.substr(1);				
				if($.cookie('answered') != null){
					var guid = $.cookie('question');
					var answered = $.cookie('answered');
					$('#hiddenInformation').append('<span class="hiddenQuestion_'+guid+'">'+answered+';</span>');
					$(votes).each(function(key){
						if(votes[key].uid == guid) {
							$('#voteMenu li:eq('+key+') a').addClass('answered');
							votes[key].answered = true;
						}
					})
				}
				//getAnswers(url);
				//animateCirclesStart();
				//console.log('votes = ' + votes[0]['title']);	
				setQuestions();
			}
		})
		return votes;
	}
	
	var questions = getQuestionsObject();
	
	
	showAnswer = function(){
		hideQuestion();
		$('#myths_upd h2').after('<p>' + questions[currentQuestionNum]['resulttext'] + '</p>');
		$('#myths_upd').fadeIn('slow', function() {
	    // Animation complete.
		if (currentQuestionNum < questions.length-1) {
			$('#myths_upd a#next').fadeIn('slow');
			$('#myths_upd a#next').click(function(){
				currentQuestionNum++;
				setQuestions();
			});
		}
		})
	}
	
	setQuestions = function(){
		
		hideQuestion();
		
		$('#myths_upd h2').html(questions[currentQuestionNum]['title']);
		$('#myths_upd').fadeIn('slow', function() {
		    // Animation complete.
			$('#myths_upd a#true').fadeIn('slow', function(){
				$('#myths_upd a#false').fadeIn('slow');
			});
		});
		
		// при клике на "правде"
		$('#myths_upd a#true').click(function(){
			// если вопрос действительно про правду
			if (questions[currentQuestionNum]['points'] == 1) {
				$('#myths_upd h2').html("Да, ты права!<br />");
			} else {
				$('#myths_upd h2').html("К сожалению, ты не права.<br />");
			}
			showAnswer();
		});
	
		$('#myths_upd a#false').click(function(){
			// если вопрос действительно про неправду
			if (questions[currentQuestionNum]['points'] == 0) {
				$('#myths_upd h2').html("Да, ты права!<br />");
			} else {
				$('#myths_upd h2').html("К сожалению, ты не права.<br />");
			}
			showAnswer();
		});
		
		//console.log(questions[currentQuestionNum]['points']);		
		//console.log(questions[currentQuestionNum]['resulttext']);
	}	
	
	hideQuestion = function(){
		$('#myths_upd').hide();
		$('#myths_upd p').remove();
		$('#myths_upd a').hide();
		$('#myths_upd a').stop();
		$('#myths_upd a').unbind('click');
	}
	
	hideQuestion();	
	
	//$('#newsblock p').append('<img src="i/arr.png" />');
	/* Расставляем ссылки по статьям. */
	$('#newsblock .article').each(function(index) {
		$(this).children('p').append($(this).children('a.arr'));
	});
});



