// variables for the browser screen available area----
var w,d,e,g,x,y;
var fontSize, marginTop, marginBottom;
$(window).resize(function() {
	liquidElements();				
});
function liquidElements(){
	w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],x=w.innerWidth||e.clientWidth||g.clientWidth,y=w.innerHeight||e.clientHeight||g.clientHeight;
	if(x<600){
		fontSize=parseInt(22+(48-22)*(x-320)/(600-320));			
	}else{
		fontSize=48;		
	}
	$('h1 ul').css("fontSize", fontSize+"px");	
	$('h1 ul').css("lineHeight", fontSize+"px");	
	
	if(y<240){
		marginTop=parseInt(2+(10-2)*(y-240)/(320-240));
		marginBottom=parseInt(5*(y-240)/(320-240));		
	}else{
		marginTop= "10";	
		marginBottom = "5";
	}
	//marginTop=marginTop===0?1:marginTop;
	if(marginTop>4){
		$('#content #typing').css("marginTop", marginTop+"%");
	}
	$('#content #typing').css("marginBottom", marginBottom+"%");
	
	//alert($("#uitgaven").css("height").split("px")[0]+" | "+(y-100));
	
}

// when the DOM is ready...
var tickerIterations = 0;
var currentTickerIteration = 0;
$(document).ready(function () {				
		// load the ticker	 
		createTicker();
		$('#main').css('height',"100%");
		liquidElements(); 	  
	  
}); 

function createTicker(){
	// put all list elements within #ticker-area into array
	var tickerLIs = $("h1 li span");
	tickerItems = new Array();
	tickerLIs.each(function(el) {						
		tickerItems.push( jQuery(this).html() );
	});
	i = 0
	rotateTicker();
}

function rotateTicker(){
	if( i == tickerItems.length ){
	  i = 0;
		if( tickerIterations > 0 ){
			console.log( "tickerIterations: " +tickerIterations );
			currentTickerIteration++;
			console.log( "currentTickerIteration: " + currentTickerIteration );
			if( currentTickerIteration >= tickerIterations ){
				console.log( "Done iterating" );
				return false;
			}
		}
	}
  tickerText = tickerItems[i];
	c = 0;
	typetext();
	setTimeout( "rotateTicker()", 5000 );
	i++;
}

var isInTag = false;
function typetext() {
	var thisChar = tickerText.substr(c, 1);
	if( thisChar == '<' ){ isInTag = true; }
	if( thisChar == '>' ){ isInTag = false; }	
	//alert($('h1 li:first').html());
	$('h1 li:first span.bg').html(tickerText.substr(0, c++) + "<span class='bg'><span class='cursor'>_</span></span>");
	//alert($('h1 li:first span.bg').html());
	if(c < tickerText.length+1)
		if( isInTag ){
			typetext();
		}else{
			setTimeout("typetext()", 120);
		}
	else {
		c = 1;
		tickerText = "";
	}	
}

function cursorAnimation()
{
  $("h1 li span span.cursor").animate(
  {
    opacity: 0
  }, "fast", "swing").animate(
  {
    opacity: 1
  }, "fast", "swing");
}

$(document).ready(function()
{
  setInterval ( "cursorAnimation()", 600 );
});
