/*
   Filename: behaviourspec.js

   See behaviour.js v1.1 by Ben Nolan, June 2005. Based largely on the work
   of Simon Willison (see comments by Simon below).

   Description:
   	
   	Uses css selectors to apply javascript behaviours to enable
   	unobtrusive javascript in html documents.
   	
   Usage:   
   
	var myrules = {
		'b.someclass' : function(element){
			element.onclick = function(){
				alert(this.innerHTML);
			}
		},
		'#someid u' : function(element){
			element.onmouseover = function(){
				this.innerHTML = "BLAH!";
			}
		}
	};
	
	Behaviour.register(myrules);
	
	// Call Behaviour.apply() to re-apply the rules (if you
	// update the dom, etc).

   License:
   
   	This file is entirely BSD licensed.
   	
   More information:
   	
   	http://ripcord.co.nz/behaviour/
   
*/   


// Example:

// <script type="text/javascript" src="behaviour.js"></script>
// <script type="text/javascript" src="behaviourspec.js"></script>

var spin = 0;

var myrules = {

  // Tutu
  '#tutu img' : function(el){
    el.onmouseover = function(){
      this.src = 'images/tutu2.png';
      //mysound.TGotoAndPlay('/barkmc','start')
    }
    el.onmouseout = function(){
      this.src = 'images/tutu.png';
      //mysound.TGotoAndPlay('/barkmc','stop')
    }
  },

  // Photos
  '#photos img' : function(el){
    el.onmouseover = function(){
      this.src = 'images/photos2.png';
    }
    el.onmouseout = function(){
      this.src = 'images/photos.png';
    }
  },

  // Tell a friend
  '#tell img' : function(el){
    el.onmouseover = function(){
      this.src = 'images/tell2.png';
    }
    el.onmouseout = function(){
      this.src = 'images/tell.png';
    }
  },

  // Buy the book
  '#buy img' : function(el){
    el.onmouseover = function(){
      this.src = 'images/buy2.png';
    }
    el.onmouseout = function(){
      this.src = 'images/buy.png';
    }
  },

  // Buy the book
  '#thebook img' : function(el){
    el.onmouseover = function(){
      spin = 1;
      spinbook(1);
    }
    el.onmouseout = function(){
      spin = 0;
      this.src = 'images/bookspin_12.png';
    }
  },

  // More about the book
  '#more img' : function(el){
    el.onmouseover = function(){
      this.style.marginLeft = '10px';
    }
    el.onmouseout = function(){
      this.style.marginLeft = '0px';
    }
  },

  // About
  '#about a' : function(el){
    //el.onclick = function(){
    //  Modalbox.show("about.html", {title: "&nbsp;", width: 354 });
    //  return false;
    //}
    el.onmouseover = function(){
      document.getElementById('aboutimg').src = 'images/about2.png';
    }
    el.onmouseout = function(){
      document.getElementById('aboutimg').src = 'images/about.png';
    }
  },

  // About overlay
  '#aboutoverlay a' : function(el){
    //el.onclick = function(){
    //  Modalbox.show("about.html", {title: "&nbsp;", width: 354 });
    //  return false;
    //}
    el.onmouseover = function(){
      document.getElementById('aboutimg').src = 'images/about2.png';
    }
    el.onmouseout = function(){
      document.getElementById('aboutimg').src = 'images/about.png';
    }
  },



  // Contact
  '#contact area' : function(el){
    el.onclick = function(){
      Modalbox.show("contact.html", {title: "&nbsp;", width: 354 });
      return false;
    }
    el.onmouseover = function(){
      document.getElementById('contactimg').style.marginLeft = '-10px';
      document.getElementById('contactimg').style.marginTop = '-10px';
    }
    el.onmouseout = function(){
      document.getElementById('contactimg').style.marginLeft = '0px';
      document.getElementById('contactimg').style.marginTop = '0px';
    }
  },

  // Movie
  '#movie img' : function(el){
    el.onmouseover = function(){
      this.style.paddingTop  = '0px';
      this.style.paddingLeft = '0px';
      this.src = 'images/alfred-tv-anim.gif';
    }
    el.onmouseout = function(){
      this.style.paddingTop  = '40px';
      this.style.paddingLeft = '20px';
      this.src = 'images/movie.png';
    }
  },

  // Pages
  '#pagenumbers a' : function(el){
    el.onclick = function(){
      var number = this.href;
      var myRe = /(\d+)$/;
      var myArray = myRe.exec(number);
      //alert(myArray[1]);
      showPage(myArray[1]);

      var pages=document.getElementsByClassName('pagenumber');
      for (key in pages) {
        if(pages[key].id == undefined){break}
        pages[key].style.color = "#00f";
      }
      
      this.style.color = "#f00";
      return false;
    }
  },


  // Photogrid
  '.gridphoto' : function(el){
    el.onclick = function(){
      var myRe = /(a\d+)(sol)?\.jpg/;
      var myArray = myRe.exec(this.src);
      var p=document.getElementById(myArray[1]); new Effect.Grow(p);
    }
    el.onmouseover = function(){
      var myRe = /a(\d+)(sol)?\.jpg/;
      var myArray = myRe.exec(this.src);
      this.src = 'images/a' + myArray[1] + 'sol.jpg';
    }
    el.onmouseout = function(){
      var myRe = /a(\d+)(sol)?\.jpg/;
      var myArray = myRe.exec(this.src);
      this.src = 'images/a' + myArray[1] + '.jpg';
    }
  },

  // Growphoto
  '.growphoto' : function(el){
    el.onclick = function(){
      new Effect.Shrink(this);
    }
  }

};

Behaviour.register(myrules);


// Misc behaviour function definitions

function showPage(p){
  document.getElementById('i1').src='images/page'+p+'.jpg';

  var p1=document.getElementById('page1text');
  if(p == 1){
    p1.style.display = "block";
  } else {
    p1.style.display = "none";
  }  
}

function spinbook(frame){
  /* am I still supposed to spin? */
  if(spin == 0){
    return;
  }

  /* src now bookspin_[frame] */
  document.getElementById('bookimg').src = '/images/bookspin_' + frame + '.png';

  /* increment */
  if(frame >= 12){ 
    frame = 1; 
  } else {
    frame = frame + 1;
  }

  /* call myself in the future */
  setTimeout("spinbook("+frame+")",80);  
}





