$ = YAHOO.util.Dom.get;
YD = YAHOO.util.Dom;
YE = YAHOO.util.Event;
YC = YAHOO.util.Connect;

/* a very simple bind method. Returns an anonymous function that calls the method
 * with the scope provided. Can't pre-bind arguments right now.
 */
Bind = function(__method, scope) {
  return function() {
    __method.apply(scope, arguments);
  }
}

/* Track a method call */
FlutherPageTrack = function(url) {
	if (typeof pageTracker != "undefined") {					
		pageTracker._trackPageview(url);
	}
}

/*takes a link and adds target=_blank so it opens in a new tab*/
LinksNewTab = function(link) {
    link.target = "_blank";    
    /*find all apprpriate links */
    /*For each link*/
    /*insert target = _blank */
}

//Our updater
function Updater(delay, func) {
  this.delay = delay;
  this.count = 0;
  this.func = func;
  this.args = [];
  this.interval = "stopped";

  for (var i = 2, length = arguments.length; i < length; i++) {
        this.args.push(arguments[i]);
  }

  Updater.prototype.stopUpdater = function() {
    this.count = 0;
    clearInterval(this.interval);
    this.interval = "stopped";
  }

  Updater.prototype.startUpdater = function() {
    if (this.interval == "stopped") {
      this.interval = setTimeout(Bind(this.fireFunc, this), this.delay[0]);
    }

  }
  
  Updater.prototype.fireFunc = function() {
    this.count += 1;
    var len = this.delay.length;
    if (this.count >= len) {
      var this_instance = this;
      this.interval = setInterval(function() { this_instance.func.apply(this_instance, this_instance.args); }, this.delay[len-1]);
    } else {
      this.func.apply(this, this.args);
      this.interval = setTimeout(Bind(this.fireFunc, this), this.delay[this.count]);
    }
    
  }
  
  Updater.prototype.resetUpdater = function(andFire) {
    this.count = 0;
    this.stopUpdater();
    if (andFire) { // Fire immediately
	this.fireFunc();
    } else { // Fire after the first interval
	this.startUpdater();
    }
  }

  Updater.prototype.resetUpdaterAndFire = function() {
	this.resetUpdater(true);
  }

  this.startUpdater();

}

function iphone_init() { 
  if (document.location.href.indexOf('#') == -1) {
    setTimeout(hideURLbar, 0);
  }

		// Setup all the custom inits
		for (var i=0;i<EXTENSIONS.length;i++) {
			EXTENSIONS[i]();
		}
}

function hideURLbar() {
  window.scrollTo(0, 1); 
}

YE.on(window, 'load', iphone_init); 

