var SLIDER_COOKIE = "USED_SLIDER"; //id of the cookie that stores if we have used the slider
var DAYS_KEEP_COOKIE = 31;

var CLEAR_COOKIES_TEXT = "Clear Cookies";

$(document).ready(function(){
	if ( CookieManager.exists(SLIDER_COOKIE) == false ){ //if we haven't used the slider (and js is enabled)
		//show the click to hide text
		$('.sidebar div:first').each(function(){$(this).children("a").text("Mods (Click to Toggle)");});
		
		//when clicked, set it back to normal
		$('.sidebar div:first').click(function() {
			$(this).children("a").text("Mods");
		});
	}
});


$(document).ready(function(){
	//restore the state form previous pages
	$('.sidebar div').each(function() {
		if ( CookieManager.exists($(this).text()) ){
			$(this).next().hide();
		}
	});
	
	$('.sidebar div').click(function() {
		CookieManager.create(SLIDER_COOKIE, "", DAYS_KEEP_COOKIE); //set the fact that we have used the slider
		
		//toggle it
		$(this).next().toggle('slow');
		
		//rem toggle state
		if ( CookieManager.exists($(this).text()) )
			CookieManager.destroy($(this).text());
		else			
			CookieManager.create($(this).text(), "hidden", DAYS_KEEP_COOKIE);
		
		return false;
	});
	
	
});
 
 //SIDE BAR ANIMATION
$(document).ready(function() {
	//flag js as enabled
	$("div[class='js_disabled']").attr("class", "js_enabled");
 
   $("div[class='sidebar'] ul li > a").hover(
   		function() {
			$(this).animate( {backgroundColor: '#353535'}, 250);
			$(this).animate( {borderLeftColor: '#CFB35B'}, 250);
		},
		function(){
			$(this).animate( {backgroundColor: '#000000'}, 750);
			$(this).animate( {borderLeftColor: '#000000'}, 750);
		}
	); //hover
 });
 
 $(document).ready(function() {
	$("div[class='footer'] p a:first").each(function(){
		$(this).text(CLEAR_COOKIES_TEXT); 
	});
	$("div[class='footer'] p a:first").click(function(){
		CookieManager.destroyAll();
		$(this).text(CLEAR_COOKIES_TEXT + "... Done"); 
	});
 });
 
 
 //requires list. Add a link to the search engine
 $(document).ready(function() {
 	$("ul[class='listRequires'] li").each(function(){
		var text = $(this).text();
		if ( $(this).children().length > 0 ){
			return;
		}
		
		var badWords = ['bloodmoon', 'tribunal', '.net', 'python'];
		for ( var i = 0; i < badWords.length; i++ ){
			if ( text.toLowerCase().indexOf(badWords[i]) != -1 ){
				return;
			}
		}
		
		
		$(this).html('<a href="http://search.yacoby.net/?name='+text+'&game=MW" target="_blank">'+text+'</a>');
	});
 });