Array.prototype.shuffle = function() 
{
    var s = [];
    
    while(this.length) 
        s.push(this.splice(Math.random() * this.length, 1));
    while(s.length) 
        this.push(s.pop());
    
    return this;
} 

var qCnt = 0;
var qSeq = [1,2,3,4,5,6,7];
var playMode;
var NyoomblQuotes = {};

NyoomblQuotes.init = function() 
{ 
    var $qNext = $(".qnext");
    var $qPrev = $(".qprev");
    var $memFrm  = $(".memFrm");
    var $nMemFrm  = $(".nMemFrm");
    var $showMemFrm = $(".show-memFrm");
    var $showNmemFrm = $(".show-nonmemFrm");
		
    $showMemFrm.click(function()
    {						   
        $(".show-btn").fadeOut('slow',function(){
            $(".mem").fadeIn(790);								 
        });		
    });
	
    $showNmemFrm.click(function()
    {
        $(".show-btn").fadeOut('slow',function(){
            $(".non-mem").fadeIn(790);		
            $("#mem-err").remove();
        });
    });
	
    qSeq.shuffle();
	
    $qNext.click(function()
    {
        clearInterval(playMode);
        NyoomblQuotes.playNext();			  
    });
	
    $qPrev.click(function()
    {
        clearInterval(playMode);
        NyoomblQuotes.playPrev();	
    });
		
    NyoomblQuotes.playQuotes();
	
    $memFrm.click(function()
    {
        $(".non-mem").fadeToggle('slow',function(){
            $(".mem").fadeToggle('slow');
        });
        $("em").remove();
        $("#mem-err").remove();
    });
	
    $nMemFrm.click(function()
    {
        $(".mem").fadeToggle('slow',function(){
            $(".non-mem").fadeToggle('slow');
        });
        $("em").remove();
        $("#mem-err").remove();
    });
};

NyoomblQuotes.playQuotes = function () 
{
    playMode = setInterval('NyoomblQuotes.playNext();',5000);
};

NyoomblQuotes.playNext = function() 
{
    ++qCnt;
    if(qCnt >= qSeq.length)
        qCnt = 0;
    $(".cont, .cont-b").hide();
    $(".hover-box").removeClass('showBox');
    $("#hover-ms-" + qSeq[qCnt]).toggleClass('showBox');
    $("#cont-ms-" + qSeq[qCnt]).show('slow');
};

NyoomblQuotes.playPrev = function() 
{
    --qCnt;
    if(qCnt <= 0)
        qCnt = qSeq.length - 1;
    $(".cont, .cont-b").hide();
    $(".hover-box").removeClass('showBox');
    $("#hover-ms-" + qSeq[qCnt]).toggleClass('showBox');
    $("#cont-ms-" + qSeq[qCnt]).show('slow');	
}

$(document).ready(function(){ 
    NyoomblQuotes.init();				  
});
