//Initiating jQuery to work with Prototype;

$(document).ready(function() { onDocumentLoad(); });
$(window).load(function() { onWindowLoad(); });

//Global Variables


/*
 * Standard page loading functions for prototype / jQuery
 */
function onDocumentLoad(){

}

//Stuff put into this function doesnt run until the entire document is loaded flash and all
function onWindowLoad(){

	$('#tvSkin').css("background-image","url('images/tvs/"+$('#tv_style').attr('value')+".jpg')");

	//TV Image preloader
	var images = $("#tv_style").children();

	$.each(images,function(i, val){
		(new Image()).src = "images/tvs/"+this.value+".jpg";
	});

	$('#tv_style').change(function(){
		$('#tvSkin').css("background-image","url('images/tvs/"+$(this).val()+".jpg')");
		return false;
	});
	
	$.each(vidArray,function(i, val){
		if(this.files.length > 0) {
			$("<option />").appendTo('#frame').attr({value:val.name}).html(((val.name).replace(/_/g, " ")));
		}
	});

	$.each(theory,function(i, val){
		$("<option />").appendTo('#theoryDD').attr({value:i}).html(val.name);
	});
	
	$('#theoryDD').change(function(){
		$('#theoryBottomBox').html(theory[this.value].title+theory[this.value].content);
		return false;
	});
	
	$.each(bias,function(i, val){
		$("<option />").appendTo('#biasDD').attr({value:i}).html(val.name);
	});
	
	$('#biasDD').change(function(){
		$('#biasTopBox').html(bias[this.value].title+bias[this.value].date+bias[this.value].content);
		return false;
	});
	
	//Set the boxes to the defaults
	var currentTheory = $('#theoryDD :first').attr('value');
	var currentBias = $('#biasDD :first').attr('value');
	$('#theoryBottomBox').html(theory[currentTheory].title+theory[currentTheory].content);
	$('#biasTopBox').html(bias[currentBias].title+bias[currentBias].date+bias[currentBias].content);
}