 //coded by Kyle Constance for CowParade

function shrinky(){
	var right = document.getElementById('right');
		right.setAttribute('style','display:none');
	var middle = document.getElementById('center');
		middle.setAttribute('style','display:none');
	var newMid = document.createElement('newMid');
		var ni = document.getElementById('top');
		  
		  var newdiv = document.createElement('div');
		  var divIdName = 'mydiv';
		  newdiv.setAttribute('id',divIdName);
		  		  newdiv.setAttribute('style','float:right;width:300px;height:600');
		  newdiv.innerHTML = "wooo";
		  ni.appendChild(newdiv);
}


function addLoadEvent(func) {
			  var oldonload = window.onload;
			  if (typeof window.onload != 'function') {
				window.onload = func;
			  } else {
				window.onload = function() {
				  if (oldonload) {
					oldonload();
				  }
				  func();
				}
			  }
			}

		function aroundTheWorld(){	
			
			var story = document.getElementById('story');
			
			story.innerHTML = jsonData.stories[0].body;
			story.innerHTML += "<br>" + jsonData.stories[1].body;
			story.innerHTML += "<br>" + jsonData.stories[2].body;
			
			if (document.getElementById('newsPic') == null){ return; }
			
			var x = document.getElementById('newsPic');
			
			x.parentNode.removeChild(x);
			

		}

function popUp(URL) {

day = new Date();

id = day.getTime();

eval("page" + id + " = window.open(URL, \'" + id + "\', \'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 100,top = 425\');");
}
function travel(URL) {

day = new Date();

id = day.getTime();

eval("page" + id + " = window.open(URL, \'" + id + "\', \'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=215,height=500,left = 100,top = 425\');");
}

//below here is all ajax

function createRequestObject(){
	var request_o; 
	var browser = navigator.appName; 
	if(browser == "Microsoft Internet Explorer"){
		// Create the object using MSIE's method
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

var http = createRequestObject(); 


function getBody(page,where){
	
	var url = 'internal_request.php?cmd=' + page;
	
	http.open('get', url);
	var rightmid = document.getElementById('rightmid');
	
				
	http.onreadystatechange = function() { handleBody(where); };
	
	http.send(null);
}

function getGal(page,where){
	
	var url = page;
	
	http.open('get', url);
	var rightmid = document.getElementById('rightmid');
	
				
	http.onreadystatechange = function() { handleGal(where); };
	
	http.send(null);
}

function getExpedia(){
	var url = 'expedia.php';
	http.open('get', url);
	http.onreadystatechange = handleInfo; 
	
	http.send(null);
}
function getCustomized(){
	var url = 'internal_request.php?cmd=customizer';
	http.open('get', url);
	http.onreadystatechange = handleCustom; 
	
	http.send(null);
}
		function getColor(color){
			var url = 'internal_request.php?cmd=customizer&color='
					+ color;
			alert(url);
			http.open('get', url);
			http.onreadystatechange = handleCustom; 
			
			http.send(null);
		}

function handleBody(where){
	/* The XMLHttpRequest object different states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		
		var response = http.responseText;
		
		document.getElementById(where).innerHTML = response;
		
		var dyingDiv = document.getElementById('body_head');
		
		if (dyingDiv == null || document.getElementById('body_head') == null){ return; }
		//actual removal
		dyingDiv.parentNode.removeChild(dyingDiv);
		
		setTall();
		setTall();
		
		
			
			addLoadEvent(setTall());
			
		
	}
}

function handleGal(where){
		/* The XMLHttpRequest object different states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		
		var response = http.responseText;
		
		document.getElementById(where).innerHTML = response;
		
		var dyingDiv = document.getElementById('body_head');
		
		if (dyingDiv == null || document.getElementById('body_head') == null){ return; }
		//actual removal
		dyingDiv.parentNode.removeChild(dyingDiv);
		
		setTall();
		setTall();
		
		
			
			addLoadEvent(setTall());
			
		
	}
}

function rand(){
	var url = 'internal_request.php?cmd=random';
	
	http.open('get', url);
				
	http.onreadystatechange = handleRand;
	
	http.send(null);

	
	
}
function handleRand(){
	/* The XMLHttpRequest object different states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		
		var response = http.responseText;
		
		if(document.getElementById('sig') == null){ return; }
		
		var img = document.getElementById('sig');
		
		document.getElementById('sig').innerHTML = response;
		
		
	//setting the height should not have to be done if all images are the same dimensions
	//for lack of images it will be used during the testing phases
		setTall();
		
		var t=setTimeout("rand()",10000);
		
	}
}
function handleInfo(){
	/* The XMLHttpRequest object different states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		
		var response = http.responseText;
		
		document.getElementById('body_cage').innerHTML = response;
	}
}