


function hightlightFaqEntry(){
  var anchor = window.location.hash.replace("#", "");
	var eles = document.getElementsByName(anchor);
	if (eles && eles[0] && hightlightFaqEntry.lastAnchor != anchor){
		hightlightFaqEntry.lastAnchor = anchor;
		var box = eles[0].parentNode;
		$('div.faq-answer').each(function(){
			if (this === box){
				$(this).addClass('faq-highlight');
			}
			else {
				$(this).removeClass('faq-highlight');
			}				
		});
	}
}


/**
* highlight the currently viewed faq entry
*/
if (document.location.href.indexOf("faq.html") > -1){
	$(function(){
	  hightlightFaqEntry();
		setInterval(hightlightFaqEntry, 200);
	});
}


/**
* replaces bot resistant email addresses with clickable human readble mailto links
*/
$(document).ready(function(){
    $("span.mailto").each(function(){
        var textEmail = $(this).text();
        var email = textEmail.replace(/\s+AT\s+/, "@").replace(/\s+DOT\s+/g, ".");
        var link = '<a href="mailto:'+ email +'">'+ email +'</a>';
        $(this).html(link);
    });
});

/**
* load stats packages
*/
//run once the page has loaded, so we don't wait for external files
$(document).ready(function(){

    if (/^http/.test(document.URL)){
        var html = '<script src="http://api.interclue.com/mint/index.php?js" type="text/javascript"></script>';
        html += '<script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script>';
        $('head').append(html);
        //wrapping in try catch block to prevent errors caused by adblock
        trackStats();
    }
});

function trackStats(){
    if (window._gat){
        var pageTracker = _gat._getTracker("UA-1713383-5");
        pageTracker._initData();
        pageTracker._trackPageview();
        //$("#footer").append("...");
    }
    else {
        setTimeout(trackStats, 500);
    }
}

 
/**
* 
*/
function toHTML(str){
    str = str.replace(/&/g, "&amp;");
    str = str.replace(/"/g, "&quot;");
    str = str.replace(/</g, "&lt;");
    str = str.replace(/>/g, "&gt;");
    return str;
}


function showQuote(showImmediately){
   
    //check quotes are valid.
    if (showQuote.quotes.length < 2){throw Error("showQuote: Must have at least two quotes so work")}
    
    //choose a random quote
    if (showQuote.remainingQuotes.length == 0){
        showQuote.remainingQuotes = showQuote.quotes;
    }
    
    var index = Math.floor(Math.random() * showQuote.remainingQuotes.length);
    var quote = showQuote.remainingQuotes[index];
    
    var html = quote.url ? '<q cite="'+ toHTML(quote.url) +'">' : '<q>';
    html += quote.quote;
    html += "</q>";
    if (quote.name){
        html += "<br /><span> - "
        if (quote.url){
            html += '<a href="'+ toHTML(quote.url) +'">'+ toHTML(quote.name) +'</a>';
        }
        else {
            html += toHTML(quote.name);
        }
        html += "</span>";
    }
    
    
    if (showImmediately === true){
        $("#quotes").html(html);
    }
    else {
        $("#quotes").fadeOut(500, function(){
            $("#quotes").html(html).fadeIn();
        });
    }
    //remove the quote from the remaining quotes
    var quotes = [];
    for (var i=0; i<showQuote.remainingQuotes.length; i++){
        if (i != index){
            quotes.push(showQuote.remainingQuotes[i]);
        }
    }
    
    showQuote.remainingQuotes = quotes;
}



/**
* show random quotes
*/
//and show one right now.
$(document).ready(function(){
    if ($("#quotes").get(0)){
        showQuote(true);
        
        //show a new quote every so often
        setInterval(showQuote, showQuote.interval);
    }
});


showQuote.interval = 7000;
showQuote.remainingQuotes = [];
showQuote.quotes = [];
showQuote.quotes.push({
    //Quoted text 
    "quote" : "oh man,that happen to me all the time, thank you for this addons",
    
    //Name/alias of person being quoted 
    "name" : "thebigabdo",
    
    //url of the quote
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984"
});

showQuote.quotes.push({
    "quote" : "this looks like something everyone could use!!",
    "name" : "coolare1",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});


showQuote.quotes.push({
    "quote" : "I can't believe no-one has built this already. How did we live without it?",
    "name" : "werehamster",
    "url" : ""
});

showQuote.quotes.push({
    "quote" : "This is the biggest thing since sliced bread. \
I have lost count how many times this has happened to me - \
thank you for the add-on that should be number 1 on the list",
    "name" : "John J. from San Francisco",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});

showQuote.quotes.push({
    "quote" : "Lose 2 or 3 workshop forms I am working on? No worries Lazarus saves them all. I can choose from the list and bang! there it is.<br /><br />[Lazarus] is an extension that I will never install Firefox without.</p>",
    "name" : "James Herbert",
    "url" : "http://jh2fct.wordpress.com/"
});

showQuote.quotes.push({
    "quote" : "great",
    "name" : "lynne ireland",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});

showQuote.quotes.push({
    "quote" : "I don't want to try to relieve all the painful memories of when I lost my data. \
    Now I right click and chose \"recover form\" and all 36 fields magically appear. \
    I can fill out 10 to 15 of these forms in the time it took me to fill out 1. I would pay for Lazarus.",
    "name" : "jh2fct",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});

showQuote.quotes.push({
    "quote" : "Works flawlessly, does not interfere with anything, top score!",
    "name" : "raveren",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});

showQuote.quotes.push({
    "quote" : "It works! Just like it's supposed to! (You should detect a hint of astonishment in the tone of my typing). I installed this an hour ago and it's already saved at least 20 minutes of rethinking/retyping due to timeout errors.",
    "name" : "onebadpenny",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});

showQuote.quotes.push({
    "quote" : "Wow....who would have thunk it? How did we live so long without this??? This is amazing. No. Better than amazing. This is...well...there are no words to describe how incredible this is. Eliminating the #%$& moments...the world is a better place now...",
    "name" : "AliSmith13",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});

showQuote.quotes.push({
    "quote" : "I was in panic mode for all of 30 seconds thinking how I would have to do all of that work again, when it came to me. Opening up a new tab to the forum page all I had to do was right click and select Recover Form - Lazarus to the rescue again.",
    "name" : "John Jackson",
    "url" : ""
});

showQuote.quotes.push({
    "quote" : "This what I've always wanted! Only today, Lazarus has recovered 2 forum posts that I would have had to rewrite. BRILLIANT! Just .... thank you :D",
    "name" : "cherryaa",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});
showQuote.quotes.push({
    "quote" : "While I recovered the page, all that I had typed was gone. That's when I clicked on Lazarus: Form Recovery and everything I wrote appeared again. I love, love, love, love this add-on.",
    "name" : "msveemac",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});
showQuote.quotes.push({
    "quote" : "Lazarus is the BEST text saving extension ever! I have been using this for about a year, and believe me, it will NEVER let you down.",
    "name" : "Abdul Hasib",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});
showQuote.quotes.push({
    "quote" : "This should be a standard add-on for Firefox, next to No-Script and Ad-Block. ",
    "name" : "Chacham1",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});
showQuote.quotes.push({
    "quote" : "Lazarus does what it claims to do, and it does it discreetly--you won't even know it's there until you need it, and then it appears like the Lone Ranger to put everything right.<br /><br />This plugin gives you back your life 5 minutes at a time--it adds up. Download it, install it, and there will come a day when you will be glad you did so.",
    "name" : "MJ Livesey",
    "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
});

//~ showQuote.quotes.push({
    //~ "quote" : "",
    //~ "name" : "",
    //~ "url" : "https://addons.mozilla.org/en-US/firefox/reviews/display/6984#reviews"
//~ });