$(document).ready(function(){
	//check text only enabled
    textOnlySwitcher()
    
    // text only control
    $(".textonlycontrol").click(function(){
    	textOnlyToggle()
    });
    
	/*text only styles*/
  $('#darktheme').click(function(){
  	darktheme()
  	$.cookie('text_theme','darktheme')
  });
  
  $('#lighttheme').click(function(){
  	lighttheme()
  	$.cookie('text_theme','lighttheme')
  });
  
  $('#normaltext').click(function(){
  	normaltext()
  	$.cookie('text_size','normal')
  });
  
  $('#largetext').click(function(){
  	largetext()
  	$.cookie('text_size','large')
  });
});


function textOnlyToggle(){		
	//check if cookie exists if not create and turn text only on
	if($.cookie('text_only')== 'on'){
		//switch the status by deleting the cookie and refresh the page
		$.cookie('text_only',null);
		$.cookie('text_theme',null)
		$.cookie('text_size',null)
		location.reload();
	}else{	
		$.cookie('text_only','on')
		location.reload();		
	}
    textOnlySwitcher()  
}

function textOnlySwitcher(){	
	if($.cookie('text_only') == 'on'){
		$('head link[rel="stylesheet"]').remove();
		$('#textonlycontrol').remove();
		$('head #textonly').attr('rel','stylesheet');		
		$('body').prepend("<a class='textonlycontrol' href='#'>[Graphical Version]</a>&nbsp;");
		$('body').prepend("<a id='largetext' href='#'>[Large Text Size]</a>&nbsp;");
		$('body').prepend("<a id='normaltext' href='#'>[Normal Text Size]</a>&nbsp;");
		$('body').prepend("<a id='darktheme' href='#'>[Dark Theme]</a>&nbsp;");
		$('body').prepend("<a id='lighttheme' href='#'>[Light Theme]</a>&nbsp;");
		lighttheme()
		normaltext()
	}
				
	//Handle theme
	theme = $.cookie('text_theme');
	if(theme == 'darktheme'){
		darktheme()
	}else if(theme == 'lighttheme'){
		lighttheme()
	}
	
	//Handle Size
	size = $.cookie('text_size');
	if(size == 'normal'){
		normaltext()
	}else if(size == 'large'){
		largetext()
	}
}

function darktheme(){
	$('body').css('background','#000');
    $('body').css('color','#00E1E8');
    $('body a').css('color','#FFFF00');
}

function lighttheme(){
	$('body').css('background','#fff');
    $('body').css('color','#000');
    $('body a').css('color','#025699');
}

function normaltext(){
	$('body').css('font-size','100%');	
}

function largetext(){
	$('body').css('font-size','175%');
}			
    

