/* 
 * hi, this is my home page .js file.
 * i'm edwardsharp, i'll be your javascripter today.
 * in this journey you will be transfixed on audio and animated imagez.
 * hopefully your browser doesn't crash.
 */

//get this init'd
var x = null;
var sliderSpeed= '5000';
var sliderColor = null;
var sliderSize = null;
//code to make image names work 
String.prototype.padLeft = function(char, count) { 
		var val = new String(this); 
		   char = char.toString().substr(0, 1); 
		while (val.length < count) { 
				   val = char + val; 
		} 
		return val; 
} 

$(document).ready(function(){

	//import jquery.timer
	//fuck, start with this, i guezz.
	//$(".box").scrambledWriter();
	$(".hide").hide("fast");

	$("#pre2").oneTime(5000, function() {
		//hide
		$("#pre1").toggle("slow");
		$("#pre2").toggle("slow");
		$("#pre3").toggle("slow");
		//show
		$("#pre4").toggle("slow");

	});
	$("#pre5").oneTime(15000, function() {
		//hide
		$("#pre4").hide("slow");
		//show
		$("#pre5").toggle("slow");
		$("#pre6").toggle("slow");
		$("#div5").toggle("slow");
		$("#div6").toggle("slow");
			
	});
	$("#pre1").oneTime(25000, function() {
		//show them all?
		$("#pre1").show("slow");
		$("#pre2").show("slow");
		$("#pre3").show("slow");
		$("#pre4").show("slow");
		$("#pre5").show("slow");
		$("#pre6").show("slow");
		$("#div5").show("slow");
		$("#div6").show("slow");
	});

	//mostly this is annoying.
	//$(".box").scrambledWriter();
	
	$("#pre4").click(function() {
		$(".homeImages").stopTime();
		$("#pre1").stopTime();
		$("body").css({'background-image' : 'none'});
		$("body").css({'background-color' : 'white'});
		
		$("#pre1").hide("slow");
		$("#pre2").hide("slow");
		$("#pre3").hide("slow");
		$("#pre4").hide("slow");

		//speed slider stuff.
		$("#speedSlider").slider({
			animate: true,
			min: 300,
			max: 15000,
			step: 100,
			range: false,
			slide: function(e,ui){

				$(this).slider("value");
				sliderSpeed=ui.value;
				
			}

		});

		//color slider stuff.
		/*
		$("#colorSlider").slider({
			animate: true,
			values: ['color', 'color1','color2','color3']
		});
		*/
		//size slider stuff.
		/*
		$("#sizeSlider").slider({
			animate: true,
			change: handleSizeSliderChange,
			slide: handleSizeSliderSlide,
			values: ['small','medium','large']
		});
		//size slider functionz
		function handleSizeSliderChange(e, ui){
		  
		}

		function handleSizeSliderSlide(e, ui){
		  
		}
		*/
		//slider precaution?
		/*
		if(event.type   == 'mousemove') {
			var allowed = this._trigger("slide", event, {
				handle: this.handles[index],
				value: newVal
			});
		}
		*/

		//begin the AJAX STUFF
		//x is just a counter. a regulator. regu1@t0r.
		var x = 0;

		$(".wrapper").everyTime(sliderSpeed, function(x) {
			
			//this was coming from php, legacy for the moment.
			//generate a date to flush the cache. shitcash.
			/*var theDate=new Date();
			var click_url= '/home/homeAction.php?x='+x+'&shitcash='+ theDate;   
			
			$.get(click_url, function(html) { 
				 // append the "ajax'd" data to the body. in this case an <img> tag.
				 
				 $(".wrapper").append(html); 
			});
			*/
			//IFITIS MAGIC!
			//<img src="" alt="" title="" class="homeImages hide" />
			//$(".wrapper").append('<img src="" alt="" title="" class="homeImages hide" />'); 
			//hang on, this is going to be a long line.
			var imageLoad = '<img src="/home/images/' + 'color1/' + x.toString().padLeft("0", 3) + '.jpg' + '" />';
			x=x+1;
			if (x < '123') { }
			else if (x=='123') {x=0;}
			$("#keynav").append(x);
			}); 
	});

	//span update shit
	//you know. make it nice and easy to know just how many secondz it is until your death defying keyboard stuntz.
	//but, really. isn't that all that you wanted?
	// okay, no more auto backspace
	/*
	$(".homeImages").everyTime(10000, function() {
		if(!x){x=0}
		if(x){x+1}
		$("#span1").append(x); 
	});
	*/
	// Initialize jQuery keyboard navigation
	/*
    $('#keynav').keynav('keynav_focusbox','keynav_box');
	*/


});
