/**
                          "tax the rich"
			            by jason van anden

               found at http://tax.cf.huffingtonpost.com

                               and/or

                  http://www.smileproject.com/tax

		   you can contact jason at jason@smileproject.com
				   or visit www.smileproject.com


        (c) copyright 2006 jason van anden. all rights reserved.
*/

    function chewy(objArt, index, behavior){
        this.setProperties(objArt, index, behavior);

        if (behavior == undefined) behavior = MODE_NORMAL;
        this.behavior_switch(behavior);
        return this;
    }

    chewy.prototype = new BaseBehaviors();
    chewy.prototype.constructor = new BaseBehaviors;
    chewy.superclass = BaseBehaviors.prototype;

    chewy.prototype.super_looper = function (){
	// FLOW NOTE: checks "fini" which keeps track of count.
       if (this.co.fini()) this.behavior_switch(this.co.behavior());
       this.output();
    };

    chewy.prototype.behavior_switch = function (behavior){

		this.assign_style(); // this forces style back to default

		switch (behavior){

			case MODE_NORMAL:
				this.co = new normal(this, 800, 200, 2);
				break;

			case MODE_BLURB:
				this.co = new blurb(this, 600, 100, 6);
				break;

			case MODE_TAX:
				this.co = new tax(this, 100, 3000, 1);
				break;

			default:
				this.co = new BaseSequence(this, 1000, 100, 2);
				break;
	   }
    };

    chewy.prototype.md = function(posX, posY){

	    var retval = this.co.md(posX, posY)
	    return (retval);
    };

    chewy.prototype.start_face = function(){

		this.blurb();
		this.brow_up();
		this.punctuation();
		this.eyes();
		this.mouth();

        this.redraw (C_TAX,  "               ");
    };

    chewy.prototype.punctuation = function(x){

		if (x == undefined) x = "?";

		var line_num = C_FOREHEAD;
		var line = "       " + x + "       ";

		switch (this.latitude[line_num]){
			case LINE_RIGHT: line =   "      " + x + "        "; break;
			case LINE_LEFT:  line =   "        " + x + "      "; break;
            default:         break;
		}

        if (x == "!") {
			this.redraw (C_HEAD,  "");
			this.redraw (C_BROW,  "");
			line_num = C_OVERHEAD;
		}
		else {

			switch(C_FOREHEAD){

				case C_BROW: this.redraw (C_HEAD,  "");
						     this.redraw (C_OVERHEAD,  "");
						     break;

				default:     this.redraw (C_BROW,  "");
						     this.redraw (C_OVERHEAD,  "");
						     break;
			}
	    }

		if (C_FOREHEAD == C_HEAD) this.redraw (C_BROW,  "");
        else this.redraw (C_HEAD,  "");

		this.redraw (line_num,  line);
    };

    chewy.prototype.eyes = function(l, r){

        if (l == undefined) l = ".";
        if (r == undefined) r = ".";

		var line_num = C_EYES;
		var line = "     " + l + "   " + r + "     ";

		switch (this.latitude[line_num]){
			case LINE_RIGHT: line = "   " + l + "  " + r + "        "; break;
			case LINE_LEFT:  line = "        " + l + "  " + r + "   "; break;
            default:         break;
		}

		this.redraw (line_num,  line);
    };

    chewy.prototype.mouth = function(x){

        if (x == undefined) x = "-";

		var line_num = C_MOUTH;
		var line     = "       " + x + "       ";

		switch (this.latitude[line_num]){
			case LINE_RIGHT: line = "    " + x + "          "; break;
			case LINE_LEFT:  line = "          " + x + "    "; break;
            default:         break;
		}

		this.redraw (line_num,  line);
    };

    chewy.prototype.eyes_wink = function(){

		switch (this.latitude[5]){
			case LINE_RIGHT: this.eyes(".", "_"); break;
			case LINE_LEFT:  this.eyes("_", "."); break;
            default:         this.eyes(".", "_"); break;
		}
    };

    chewy.prototype.antsy = function(){
		this.eyes("=", "=");
		this.mouth("*");
    };

 // START OF 'TAX' SEQUENCE!

    chewy.prototype.pretax = function(){

		this.turn_center();
		this.brow_down();
		this.punctuation();
		this.eyes("=", "=");
		this.mouth();

        super_duper (this.index, "almost_tax()", 100);
	}

    chewy.prototype.almost_tax = function(){

		this.brow_up();
		this.punctuation();

        super_duper (this.index, "tax()", 100);
	}

    chewy.prototype.tax = function(){

		this.turn_center();  // TODO: comment out
		this.brow_up();
		this.punctuation("!");
		this.eyes(".", ".");
		this.mouth("0");
		this.redraw (C_TAX,  " tax the rich! ");

		super_duper (this.index, "untax()", 800);
    };

    chewy.prototype.untax = function(){

		this.turn_center();
		this.brow_down();
		this.punctuation();
		this.eyes();
		this.mouth();

        this.redraw (C_TAX,  "               ");
        super_duper (this.index, "post_tax()", 50);
    };

    chewy.prototype.post_tax = function(){
		this.brow_up();
		this.punctuation();

        this.redraw (C_TAX,  "               ");
    };

 // END OF TAX SEQUENCE

    chewy.prototype.nothing = function(){
        return;
    };

    // NEW STUFF!
    chewy.prototype.unblurb = function(){
		this.brow_up();
        this.redraw (C_BLURB,  "               ");
    };

    chewy.prototype.blurb = function(b){

        if (b == undefined) b = "               ";

		this.turn_center();
		this.brow_down();
		this.punctuation("¿");
		this.eyes(".", ".");
		this.mouth("-");
        this.redraw (C_BLURB,  b);
    };

    chewy.prototype.say_tax = function(){
	    this.pretax();
    };

	chewy.prototype.flash_eyes = function(l, r, t){
	    if (t == undefined) t = 200;
	    this.eyes(l, r);
		super_duper(this.index, "eyes()", t);
	}

    chewy.prototype.blink = function(){
	    this.eyes("_", "_");
        super_duper (this.index, "eyes()", 200);
    };

    chewy.prototype.wink = function(){
	    this.eyes_wink();
        super_duper (this.index, "unwink()", 200);
    };

    chewy.prototype.unwink = function(){
	    this.eyes();
     };


 // POSITION/POSTURE

    chewy.prototype.turn_right = function(){

		for (i=0; i<10; i++)this.latitude[i] = LINE_RIGHT;

	    this.punctuation();
	    this.eyes();
	    this.mouth();
    };

    chewy.prototype.turn_center = function(){

		for (i=0; i<10; i++)this.latitude[i] = LINE_CENTER;

	    this.punctuation();
	    this.eyes();
	    this.mouth();
    };

    chewy.prototype.turn_left = function(){

		for (i=0; i<10; i++)this.latitude[i] = LINE_LEFT;

	    this.punctuation();
	    this.eyes();
	    this.mouth();
    };

    chewy.prototype.brow_up = function(){C_FOREHEAD = C_HEAD;};
    chewy.prototype.brow_down = function(){C_FOREHEAD = C_BROW;};


 // END POSITION/POSTURE


 // OLD STUFF

    chewy.prototype.sleep_z = function(){
        this.redraw (1, "    z        ");      //    z    //
    };

    chewy.prototype.sleep_z_z = function(){
        this.redraw (1, "   z-z       ");      //   z-z   //
    };

    chewy.prototype.sleep_z_z_z = function(){
        this.redraw (1, "  z-z-z      ");      //  z-z-z  //
    };

    chewy.prototype.sleep_z_z_z_z = function(){
        this.redraw (1, " z-z-z-z     ");      // z-z-z-z //
    };

    chewy.prototype.sleep_z_z_z_z_z = function(){
        this.redraw (1, "z-z-z-z-z    ");      //z-z-z-z-z//
    };

    chewy.prototype.shake_head_middle = function(){
        this.redraw (0, "             ");
        this.redraw (1, "             ");
        this.redraw (2, "             ");
        this.redraw (3, "     ???     ");
        this.redraw (4, "             ");
        this.redraw (5, "    .....    ");
        this.redraw (6, "     ---     ");
        this.redraw (7, "             ");
        this.redraw (8, "             ");
        this.redraw (9, "             ");
    };

    chewy.prototype.shake_head_left = function(){
        this.redraw (0, "             ");
        this.redraw (1, "             ");
        this.redraw (2, "             ");
        this.redraw (3, "       ?     ");
        this.redraw (4, "             ");
        this.redraw (5, "     . .. .  ");
        this.redraw (6, "         -   ");
        this.redraw (7, "             ");
        this.redraw (8, "             ");
        this.redraw (9, "             ");
    };

    chewy.prototype.shake_head_right = function(){
        this.redraw (0, "             ");
        this.redraw (1, "             ");
        this.redraw (2, "             ");
        this.redraw (2, "             ");
        this.redraw (3, "     ?       ");
        this.redraw (4, "             ");
        this.redraw (5, "  . .. .     ");
        this.redraw (6, "   -         ");
        this.redraw (7, "             ");
        this.redraw (8, "             ");
        this.redraw (9, "             ");
    };

    chewy.prototype.interested = function(){
        this.redraw (0, "             ");
        this.redraw (1, "             ");
        this.redraw (2, "             ");
        this.redraw (3, "      ?      ");
        this.redraw (4, "             ");
        this.redraw (5, "    .   .    ");
        this.redraw (6, "      o      ");
        this.redraw (7, "             ");
        this.redraw (8, "             ");
        this.redraw (9, "             ");
    };

    chewy.prototype.listen_right = function(){
        this.redraw (0, "             ");
        this.redraw (1, "             ");
        this.redraw (2, "             ");
        this.redraw (2, "             ");
        this.redraw (3, "     ?       ");
        this.redraw (4, "             ");
        this.redraw (5, "  .  .       ");
        this.redraw (6, "   -         ");
        this.redraw (7, "             ");
        this.redraw (8, "             ");
        this.redraw (9, "             ");
    };

    chewy.prototype.listen_left = function(){

        this.redraw (0, "             ");
        this.redraw (1, "             ");
        this.redraw (2, "             ");
        this.redraw (3, "       ?     ");
        this.redraw (4, "             ");
        this.redraw (5, "       .  .  ");
        this.redraw (6, "         -   ");
        this.redraw (7, "             ");
        this.redraw (8, "             ");
        this.redraw (9, "             ");
		// TODO: for this and the one above - add wide eyed timed well
		// TODO: could also add gaping mouth
    };


    chewy.prototype.sleeping = function(){

        this.redraw (0, "             ");
        this.redraw (1, "             ");
        this.redraw (2, "             ");
        this.redraw (3, "             ");
        this.redraw (4, "      ?      ");
        this.redraw (5, "    _   _    ");
        this.redraw (6, "      -      ");
        this.redraw (7, "             ");
        this.redraw (8, "             ");
        this.redraw (9, "             ");
    };

    chewy.prototype.sleepy = function(){

        this.redraw (0, "             ");
        this.redraw (1, "             ");
        this.redraw (2, "             ");
        this.redraw (3, "      ?      ");
        this.redraw (4, "             ");
        this.redraw (5, "    ;   ;    ");
        this.redraw (6, "      -      ");
        this.redraw (7, "             ");
        this.redraw (8, "             ");
        this.redraw (9, "             ");
    };

    chewy.prototype.yawn = function(){

        this.redraw (0, "             ");
        this.redraw (1, "             ");
        this.redraw (2, "             ");
        this.redraw (3, "             ");
        this.redraw (4, "      ?      ");
        this.redraw (5, "    =   =    ");
        this.redraw (6, "      0      ");
        this.redraw (7, "             ");
        this.redraw (8, "             ");
        this.redraw (9, "             ");

        super_duper (this.index, "sleepy()", 1500);
    };

    chewy.prototype.look_fast = function (){    // this one is pretty funny!

        this.redraw (0, "             ");
        this.redraw (1, "             ");
        this.redraw (2, "             ");
        this.redraw (3, "     ???     ");
        this.redraw (4, "             ");
        this.redraw (5, "    .....    ");
        this.redraw (6, "     ---     ");
        this.redraw (7, "             ");
        this.redraw (8, "             ");
        this.redraw (9, "             ");
    };

    chewy.prototype.assign_style = function(newstyle, justface){

       if (newstyle == undefined) newstyle = "liner";
       if (justface == undefined) justface = true;


       var span_count = 0;
       var objLine = this.objArt.childNodes[0];
       var span_count = 0;

	  for (i=0; i < this.objArt.childNodes.length; i++){ // this accomodates firefox + ie
		   objLine = this.objArt.childNodes[i];

           if (objLine.nodeName == "SPAN") {
			   span_count += 1;

			   if (justface){
				   if ((span_count >= C_HEAD) && (span_count < C_TAX)) {
					   objLine.setAttribute((document.all?"className":"class"), newstyle);
				   }
		       }
		       else {
				   objLine.setAttribute((document.all?"className":"class"), newstyle);
			   }
		   }
	   }
	};


