/*Global variables*/
var textOne= "  Remove your mouse pointer from this text and it will change"; // första texten
var textTwo= "  Rest your mouse pointer over this text and it will change"; // andra texten
var newText= "Amazing!"; // text som skapas
var textNode1 =  document.createTextNode(textOne); 
var textNode2 =  document.createTextNode(textTwo); 
var newTextNode = document.createTextNode(newText);

/*Browser detection*/
var ie = (document.all) ? true:false; // IE4+
var dom = ((document.getElementById) && (!ie)) ? true:false; // Mozilla 


/*Assigns event handler functions by using 
the help functions setEventById and setEventByObject*/
setEventByObject(window, "load", changeToTextTwo);
setEventByObject(window, "load", runInterval);
setEventById('d', "mouseover", changeToTextOne);
setEventById('d', "mouseout", changeToTextTwo);


/*Help function to set events by id*/
function setEventById(id, ev, fu) {
	
	if(dom) {
		document.getElementById(id).addEventListener(ev, fu, false);
	} 
	if(ie) {
		document.getElementById(id).attachEvent('on' + ev, fu);
	}
} 


/*Help function to set events by object*/
function setEventByObject(ob, ev, fu) {

	if(dom) {
		ob.addEventListener(ev, fu, false);
	} 
	if(ie) {
		ob.attachEvent('on' + ev, fu);
	}	
} 


//starts interval
function runInterval() {
    
    theInterval = window.setInterval("ticToc()", 1000);
}


/*Called according to the interval to view current time*/
function ticToc() {
	var d = new Date();
	try {
		removeChildNode(date,'d2')
	}
	catch(e) {
    //ignore
	}
	date = document.createTextNode(d.toLocaleTimeString());
	document.getElementById('d2').appendChild(date);
	delete(d);
}

/*Makes the first text visible*/
function changeToTextOne() {
	try {
		removeChildNode(textNode2,'d')
	}
	catch(e) {
    //ignore
	}
	appendChildNode(textNode1,'d');
	appendChildNode(newTextNode,'d1'); 
}

/*Makes the second text show*/
function changeToTextTwo() {
	
	try {
	removeChildNode(textNode1,'d')
	removeChildNode(newTextNode,'d1')
	}
	catch(e) {
    //ignore
	}
	appendChildNode(textNode2,'d'); 
}

/*Appends a node*/
function appendChildNode(node,id) {

window.document.getElementById(id).appendChild(node); 
}

/*Removes a node*/
function removeChildNode(node,id) {
	
	window.document.getElementById(id).removeChild(node); 
}







