Deep = {
  version    : 1.5,
  author     : "jeremy@jeremyboles.com",
  lastEdit   : new Date (2008, 1, 28),
  initialize : function() {
	$$('div#loader').removeClass('noShow');
	$$('div#home').addClass('noShow');
    this.navLinks = new Deep.NavLinks();
    this.navLinks.setCurrentSlide("home");
    this.apathy   = new Deep.Apathy.Video();
    this.broadcast = new Deep.Work.Broadcast();
    this.people = new Deep.People();
    this.popups = new Deep.PopUps();
    if (Browser.Engine.trident4) {
      $$("div.inside ul.nav li").each(function(li) {
        li.addEvent("mouseover", function() { $(this).addClass("with-dot"); });
        li.addEvent("mouseout", function() { $(this).removeClass("with-dot"); });
      });
      
      $$("div.thumbs a").each(function(li) {
        if (!li.hasClass("selected")) {
          li.addEvent("mouseover", function() { $(this).addClass("selected"); });
          li.addEvent("mouseout", function() { $(this).removeClass("selected"); });
        }
      });
    }
  }
};



//Jeremy's code 
Deep.PopUps = new Class({
  initialize: function() {
    this.links = $$("a.pop-up");
    this.links.each((function(link) {
      link.addEvent("click", (function(event) {
        event.stop();
        event.target = $(event.target);
        var results = event.target.get("src").match(new RegExp("img/work/(.*)/(.*)-img.jpg"));
        //window.open("img/work/" + results[1] + "/zoom/" + results[2] + ".jpg", "work", "status=0,toolbar=0,width=800,height=800,resizable=0,scrollbars=0");
		
		    //skye hacks
		    var new_window = window.open("","_blank","width=800,height=650,left=20,top=20,scrollbars=1");
		    if (!$defined(new_window)) { return true; } 

		    new_window.document.write('<html><head><title>deep :: '+results[2]+'<\/title><\/head><body><div align="center"><img src="img\/work\/'+results[1]+'\/zoom\/'+results[2]+'.jpg"><\/div><\/body><\/html>');
		    if ($defined(new_window.focus)) { new_window.focus(); }
		  
      }).bindWithEvent(this));
    }).bind(this));
  }
});

Deep.NavLinks = new Class({
  finderCss  : "ul.nav li a",
  initialize : function() {
    this.links = $$(this.finderCss).extend($$("a.nav"));
    
    this.links.each(this._attachEvents.bind(this));
  },
  _attachEvents : function(link) {
    link.addEvent("click", this.changeSlide.bindWithEvent(this));
  },
  changeSlide : function(event) {
    event.target = $(event.target);
    if (event.target.get("tag") == "a") {
      if (!(event.target.get("href").test(new RegExp("#")))) {
        return true;
      }
    } 
    
    var slide = null
    if (event.target.get("tag") == "img") {
      slide = $(this._getIdFromHref((Browser.Engine.trident  ? event.target.parentNode : event.target.getParent("a.nav")).get("href")));
    } else {
      slide = $(this._getIdFromHref(event.target.get("href")));
    }
    
    if (this.currentSlide != slide) {
      this._showSlide(slide);
      (function(){ 
        this._hideSlide(this.currentSlide); 
        this.setCurrentSlide(slide);
      }).bind(this).delay(250);
    }
    
    event.stop();
  },
  setCurrentSlide : function(slide) {
    this.currentSlide = $(slide);
  },
  _hideSlide : function(slide) {
    slide = $(slide);
    
    slide.set("tween", { duration: "short" });
    slide.tween("opacity", 1, 0);
    
    (function() { slide.setStyle("display", "none") }).delay(250);
  },
  _showSlide : function(slide) {
    slide = $(slide);
    
    slide.setStyle("z-index", (parseInt(this.currentSlide.getStyle("z-index")) + 1));
    slide.setStyle("display", "block");
    slide.setStyle("opacity", 0);
    
    slide.set("tween", { duration: "short" });
    slide.tween("opacity", 0, 1);
  },
  _getIdFromHref : function(href) {
    return href.replace("#", "").replace(window.location.toString(), "").replace(window.location.hash.toString(), "").toString();
  }
});

Deep.Apathy = {};
Deep.Apathy.Video = new Class({
  replaceId  : "apathy-movie",
  flashFile  : "apathy.swf",
  initialize : function() {
    this.movie = new Swiff(("flash/" + this.flashFile), { 
      container : this.replaceId, 
      width     : 720, 
      height    : 480, 
      params    : {
        bgcolor : "#000000"
      }
    });
  }
});

Deep.Work = {};
Deep.Work.Broadcast = new Class({
  initialize: function() {
    this.megaTire = new Swiff("flash/megatire.swf", { 
      container : "mega-tire", 
      width     : 320, 
      height    : 240, 
      params    : {
        bgcolor : "#000000"
      }
    });
    
    this.henrysMeats = new Swiff("flash/henrysmeats.swf", { 
      container : "henrys-meats", 
      width     : 320, 
      height    : 240, 
      params    : {
        bgcolor : "#000000"
      }
    });
    
    this.featherAndFur = new Swiff("flash/featherandfur.swf", { 
      container : "feather-and-fur", 
      width     : 320, 
      height    : 240, 
      params    : {
        bgcolor : "#000000"
      }
    });
    
    this.leaf = new Swiff("flash/barnabas_leaf.swf", { 
      container : "leaf", 
      width     : 320, 
      height    : 240, 
      params    : {
        bgcolor : "#000000"
      }
    });
    
    this.frog = new Swiff("flash/barnabas_frog.swf", { 
      container : "frog", 
      width     : 320, 
      height    : 240, 
      params    : {
        bgcolor : "#000000"
      }
    });
    
    this.turtle = new Swiff("flash/barnabas_turtle.swf", { 
      container : "turtle", 
      width     : 320, 
      height    : 240, 
      params    : {
        bgcolor : "#000000"
      }
    });
	
    this.nescafe = new Swiff("flash/nescafe.swf", { 
      container : "nescafe", 
      width     : 318, 
      height    : 239, 
      params    : {
        bgcolor : "#000000"
      }
    });
    
    this.casa = new Swiff("flash/casa.swf", { 
      container : "casa", 
      width     : 320, 
      height    : 240, 
      params    : {
        bgcolor : "#000000"
      }
    });
  }
});

Deep.People = new Class({
  initialize : function() {
    this.nextLinks = $$("a.next-person");

    this.previousLinks = $$("a.previous-person");
    
    this.thumbs = $$("div.people-list > div.thumbs");
    
    this.nextLinks.each((function(link) {
      link.addEvent("click", this.scootLeft.bindWithEvent(this));
    }).bind(this));
    
    this.previousLinks.each((function(link) {
      link.addEvent("click", this.scootRight.bindWithEvent(this));
    }).bind(this));
    
  },
  scootLeft : function(event) {
    event.stop();
    this.thumbs.each((function(thumb) {
      thumb.set("tween", { duration: "short" });
      thumb.tween("left", -85);
    }).bind(this));
  },
  scootRight : function(event) {
    event.stop();
    this.thumbs.each((function(thumb) {
      thumb.set("tween", { duration: "short" });
      thumb.tween("left", 0);
    }).bind(this));
  }
});
