var a;var b;var c;var d;var e;var f;var g;var h;var i;var j;var k;var l;

if ($.browser.msie && $.browser.version.substr(0,1)<7) 
{   
$.getScript('js/ie-base.js'); 
}


//end ie

else
{

$(document).ready(function()
{	

	    $.ajax({
        url: "sounds/FlushingToilet.mp3",
        success: function() {
         //   alert('done');
        }
    });

	    $.ajax({
        url: "sounds/Fart1.mp3",
        success: function() {
          //  alert('done');
        }
    });


	    $.ajax({
        url: "sounds/Fart2.mp3",
        success: function() {
         //   alert('done');
        }
    });

	    $.ajax({
        url: "sounds/Fart3.mp3",
        success: function() {
           // alert('done');
        }
    });



	$(document).pngFix(); 
	$('#slickbox').hide();
	$('#page').css( {backgroundPosition: "0 0"} );
/*

*/
	
	/**
	 * @author Alexander Farkas
	 * v. 1.02
	 */
	(function($) {
		$.extend($.fx.step,{
		    backgroundPosition: function(fx) {
	            if (fx.state === 0 && typeof fx.end == 'string') {
	                var start = $.curCSS(fx.elem,'backgroundPosition');
	                start = toArray(start);
	                fx.start = [start[0],start[2]];
	                var end = toArray(fx.end);
	                fx.end = [end[0],end[2]];
	                fx.unit = [end[1],end[3]];
				}
	            var nowPosX = [];
	            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
	            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
	            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
	
	           function toArray(strg){
	               strg = strg.replace(/left|top/g,'0px');
	               strg = strg.replace(/right|bottom/g,'100%');
	               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
	               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
	               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	           }
	        }
		});
		})(jQuery);
	

	
	$('#nav ul li').click(function()
	{
		elem = $('#page').find('div.showit');
		cur = elem.attr('id');
		
		$('#'+cur).removeClass('showit').hide();
		$('#slickbox').hide();
		el = $(this).attr('id').substring(1);
	
		doMove(el);
	});
	
	$('#logo').click(function()
	{
		/*
		elem = $('#page').find('div.showit');
		cur = elem.attr('id');
		alert(cur);
		
		$('#'+cur).removeClass('showit').hide();
		$('#slickbox').hide();
	*/
		doMove(0); 
	});

		
	
	$("#slider1, #slider2, #slider3, #slider4, #slider5, #slider6, #slider7, #slider8, #slider9, #slider10, #slider11, #slider12, #slider13, #slider14").slider(
	{
		value:20,
		min: 10,
		max: 30,
		step: 1,
		stop: function(event, ui) {
				el = parseInt($(this).attr('id').substring(6));
				//alert(ui.value+' - '+el);
				if (ui.value >= '21')
						{
							snd = 'fart1';
						}
					else if (ui.value <= '19')
						{
							snd = 'fart2';
						}else
						{
							snd = 'fart3';
						}
							
						//soundPlay(snd);
							doPopup(el, ui.value);
							collectVals(this,ui.value);
				}
				/*,
		change: function(event, ui)
				{
					
					
				}	*/				
});

	
});


function backscroll(bg,el)
{
	bg = parseInt(bg);
	$('#page').stop().animate(

		{backgroundPosition:"(0px -"+bg+"px)"},
		{duration:6500,
				complete: function()
								{
									$('#question'+el).addClass('showit').show();
									focuson(el);
								}
		});

}

function focuson(myel)
{
	sldr = '#slider'+myel;
	thisel = $(sldr).find('a');
	if (myel >= '1')
	{
		thisel.focus();
	}

}

function doMove(el)

{
	elem = $('#page').find('div.showit');
	cur = elem.attr('id');

	pos = 3500;
	amt = parseInt(el);
	cal = parseInt(pos)*amt;
	bg = cal;
	$('#'+cur).removeClass('showit').hide();
	
	backscroll(bg,el);

}

function doPopup(el,ans)
{
	nextel = parseInt(el)+1;
	
	if (ans < '20')
	{
	    answer = 'rarely';
	    img = '<img src="images/q1-rarely.png" width="74px" height="38px" alt="Rarely" />';
	}
	
	else if (ans > '20')
	{
	    answer = 'often';
	    img = '<img src="images/q1-often.png" width="61px" height="38px" alt="Often" />';
	}
	
	else
	{
	return;
		answer = 'not sure';
		img = 'not sure';
	}
	
	if (el == '12')
		{
		    //gobtn = '<div id="nbtn" onClick="soundPlay(\'FlushingToilet\');$(\'#slickbox\').hide();doMove(0);">THIS IS THE END - Click to start again</div>'
		    gobtn = '<div id="nbtn" onClick="$(\'#slickbox\').hide();doMove(' + nextel + ');"><img src="images/finished.gif" width="112px" height="27px" alt="finished?"></div>';
		    
        }
	else
		{
		    //gobtn = '<div id="nbtn" onClick="$(\'#slickbox\').hide();doMove('+nextel+');">Go to question '+nextel+'</div>';
		    gobtn = '<div id="nbtn" onClick="$(\'#slickbox\').hide();doMove(' + nextel + ');"><img src="images/next.gif" width="60px" height="35px" alt="Next Question"></div>';
		}
	
	object = '#a'+el+answer;
	
	//result = $('#results').load('answers/test.html '+object);
	//$('#results').load('answers/test.html '+object);
	//alert('question: '+el+' - answer: '+ans);
	$('#slickbox').empty();
	
	//close button dont want, creates bug in the logic
	//$('#slickbox').append('<div id="close" onClick="$(\'#slickbox\').hide();focuson('+el+');"><img src="images/popup-close.png" alt="Close" /></div>');
	
    if (el == 1 || el == 4 || el == 7 || el == 10) {
	    $('#slickbox').append('<h1><img src="images/mrpoo3.png" width="76px" height="88px" />Thank you for your answer</h1>');
	} else if (el == 2 || el == 5 || el == 8 || el == 11) {
	    $('#slickbox').append('<h1><img src="images/mrpoo2.png" width="51px" height="89px" />Thank you for your answer</h1>');
	} else if (el == 3 || el == 6 || el == 9 || el == 12) {
	    $('#slickbox').append('<h1><img src="images/mrpoo1.png" width="34px" height="88px" />Thank you for your answer</h1>');
    }
	
	$('#slickbox').append('<div id="results">');
	
	$('#results').load('answers/test.html '+object);
	
	
	$('#slickbox').append('</div>');

	setTimeout(function(){$('#slickbox').append(gobtn);} , 2000);
	

	 $('#slickbox').fadeIn('fast');
}

$('#endToilet,#finishNow').click(function () {
    doEnd();
    return false;
});

function doEnd() {

    $('#resultsBox').show();

    object = '#a' + el + answer;
    
     $('#bar1').css('width', barlength(a));
    $('#bar2').css('width', barlength(b));
    $('#bar3').css('width', barlength(c));
    $('#bar4').css('width', barlength(d));
    $('#bar5').css('width', barlength(e));
    $('#bar6').css('width', barlength(f));
    $('#bar7').css('width', barlength(g));
    $('#bar8').css('width', barlength(h));
    $('#bar9').css('width', barlength(i));
    $('#bar10').css('width', barlength(j));
    $('#bar11').css('width', barlength(k));
    $('#bar12').css('width', barlength(l));

    $('#printVer').attr({ 'href': 'print.htm?a=' + a + '&b=' + b + '&c=' + c + '&d=' + d + '&e=' + e + '&f=' + f + '&g=' + g + '&h=' + h + '&i=' + i + '&j=' + j + '&k=' + k + '&l=' + l });
      
}

function barlength(inVal) {
    var workingVal = parseInt(inVal) - 10;
    workingVal = 20 - workingVal;
    workingVal = (workingVal / 20) * 100;
    return workingVal + '%';
}

function collectVals(slider,valSent) {
    //alert($(slider).attr('id') + '|' + valSent);
    //a = valSent;
if ( $(slider).attr('id') == 'slider1' ){
    a = valSent; $('#q1').children('img').attr('src', 'images/NAV01_RO.gif');
} else if ($(slider).attr('id') == 'slider2') {
    b = valSent; $('#q2').children('img').attr('src', 'images/NAV02_RO.gif');
} else if ($(slider).attr('id') == 'slider3') {
    c = valSent; $('#q3').children('img').attr('src', 'images/NAV03_RO.gif');
} else if ($(slider).attr('id') == 'slider4') {
    d = valSent; $('#q4').children('img').attr('src', 'images/NAV04_RO.gif');
} else if ($(slider).attr('id') == 'slider5') {
    e = valSent; $('#q5').children('img').attr('src', 'images/NAV05_RO.gif');
} else if ($(slider).attr('id') == 'slider6') {
    f = valSent; $('#q6').children('img').attr('src', 'images/NAV06_RO.gif');
} else if ($(slider).attr('id') == 'slider7') {
    g = valSent; $('#q7').children('img').attr('src', 'images/NAV07_RO.gif');
} else if ($(slider).attr('id') == 'slider8') {
    h = valSent; $('#q8').children('img').attr('src', 'images/NAV08_RO.gif');
} else if ($(slider).attr('id') == 'slider9') {
    i = valSent; $('#q9').children('img').attr('src', 'images/NAV09_RO.gif');
} else if ($(slider).attr('id') == 'slider10') {
    j = valSent; $('#q10').children('img').attr('src', 'images/NAV10_RO.gif');
} else if ($(slider).attr('id') == 'slider11') {
    k = valSent; $('#q11').children('img').attr('src', 'images/NAV11_RO.gif');
} else if ($(slider).attr('id') == 'slider12') {
    l = valSent; $('#q12').children('img').attr('src', 'images/NAV12_RO.gif');
}

return false;
}

// ======================================================================
var soundEmbed = null;
// ======================================================================
function soundPlay(which)
{
    if (soundEmbed)
    
       document.body.removeChild(soundEmbed);
    soundEmbed = document.createElement("embed");
    soundEmbed.setAttribute("src", "sounds/" + which + ".mp3");
    soundEmbed.setAttribute("type", 'audio/mpeg');
    soundEmbed.setAttribute("hidden", true);
    soundEmbed.setAttribute("autostart", true);
    document.body.appendChild(soundEmbed);
}

//======================================================================




}// end browser sniff








