$(document).ready(function() {
	
	$('#moretext').bind('click',
	
		function(){
			$(this).hide();
			$('#ngtext').show();
			$('#onoff').show();		
		}
	);



	$('#ngtext').bind('click',
	
		function(){
			$(this).hide();
			$('#moretext').show();	
			$('#onoff').hide();		
	
		}
	);
	
	
	$('#credittitle').bind('click',
	
		function(){
			$('#credits').toggle();
		}
		
	);
	
	
		
});



var jscountdown={
	padfield:function(f){
		return (f<10)? "0"+f : f+"" // takes care of the additional 0
	},
	unkern:function(str){
		// insert a Zero Width Non Joiner
		// after each character!
		
		charray = str.split("");
		newstring = charray.join("&#8204;")
							
		return (newstring);
		
	},
	addasecond:function(){
		
		// epoch test
		var nowdate = new Date();
		var nowmilliseconds = nowdate.getTime();
		
		this.totalseconds = Math.round((nowmilliseconds - this.starttime)/1000);
		// end of epoch test
		
		
		//this.totalseconds++;
		this.hours = Math.floor(this.totalseconds / 3600);
		this.minutes = Math.floor((this.totalseconds % 3600)/60);
		this.seconds = this.totalseconds % 60;	
				
		if (this.totalseconds < 1){
			ct = ("|&thinsp;&thinsp;<span class='whiteminusleft'>&ndash;</span>0&#8204;0<span id='rightpart'><span class='lift'>:</span>" + this.unkern(this.padfield(Math.abs(this.seconds)))) + "<span class='whiteminusright'>&ndash;</span>&thinsp;&thinsp;|</span>";
		}
		else if(this.totalseconds < 3600){
			ct = ("|&thinsp;&thinsp;<span class='minus'>&ndash;</span>" + this.unkern(this.padfield(this.minutes)) + "<span id='rightpart'><span class='lift'>:</span>" + this.unkern(this.padfield(this.seconds))) + "<span class='whiteminusright'>&ndash;</span>&thinsp;&thinsp;|</span>";

		} else {
			ct = ("|&thinsp;&thinsp;<span class='minus'>&ndash;</span>" + this.unkern(this.padfield(this.hours)) + "<span id='rightpart'><span class='lift'>:</span>" + this.unkern(this.padfield(this.minutes)) + "<span class='lift'>:</span>" + this.unkern(this.padfield(this.seconds))) + "<span class='whiteminusright'>&ndash;</span>&thinsp;&thinsp;|</span>";

		}
			
		this.ctref.innerHTML=ct

	},
	init:function(){
		this.ctref=document.getElementById("jscountdownSpan")
		//this.totalseconds = -11;
		this.totalseconds = -11;
		
		// test test test with seconds since epoch
		var thisdate = new Date();
		this.starttime = thisdate.getTime() +10000; // plus 10 seconds
		// end of test
		
		jscountdown.addasecond();
		jscountdown.timer=setInterval(function(){jscountdown.addasecond()}, 1000)
	}
	
}


function swap(){
	inhoud = document.getElementById('onoff');
	lefttextvar = document.getElementById('lefttext');
	if(inhoud.style.display == "none"){
		inhoud.style.display = "inline";
		lefttextvar.innerHTML = "Noa Giniger";
	} else {
		inhoud.style.display = "none";
		lefttextvar.innerHTML = "More";
	}	
}
function swapcredits(){

	credittitle = document.getElementById('credittitle');
	creditlinks = document.getElementById('creditlinks');
	
	if(creditlinks.style.display == "none"){
		creditlinks.style.display = "inline";
		credittitle.innerHTML = "Credits:";
	} else {
		creditlinks.style.display = "none";
		credittitle.innerHTML = "Credits";
	}	
	
}

function centerdiv(){
	shifter = document.getElementById('rightpart').offsetWidth + 8;
	
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}


	
	document.getElementById('jscountdownDiv').style.top = ((y/2)-(document.getElementById('jscountdownDiv').offsetHeight)/2 - 25) + "px";
	document.getElementById('jscountdownDiv').style.left = (x/2)-(document.getElementById('jscountdownDiv').offsetWidth)/2 - shifter + "px";

}

window.onload = function(){jscountdown.init();centerdiv();

							window.onresize = function(){
												 centerdiv();
											  }
						};
