var CSlider = function(opt_cont, opt_cnt) {
  this.c = gSlider[opt_cnt][1];
  this.a = gSlider[opt_cnt][0];
  if (this.c<=1)
    return;
  this.cnt = opt_cnt;
  this.el = opt_cont;
  this.p = 0;
  this.start_();
};

CSlider.prototype.start_ = function() {
  this.fadeIn_ = bind(function(){
    setTimeout(bind(this.update_, this), Math.random() * 1000 + 5000);
  }, this);
  this.fadeOut_ = bind(function(){
    this.p = (this.c + this.p + 1) % this.c;
    $(this.el).attr('src', '/countries/'+this.a+(this.p+1)+'.jpg');
    $(this.el).fadeIn(1000, this.fadeIn_);
  }, this);
  setTimeout(bind(this.update_, this), Math.random() * 1000 + 5000);
};


CSlider.prototype.update_ = function() {
  $(this.el).fadeOut(1000, this.fadeOut_);
};

if ('undefined' == typeof(bind)) {
	// borrowed from google-closure js library
	function bind(fn, selfObj, var_args) {
	  var context = selfObj || goog.global;

	  if (arguments.length > 2) {
	    var boundArgs = Array.prototype.slice.call(arguments, 2);
	    return function() {
	      var newArgs = Array.prototype.slice.call(arguments);
	      Array.prototype.unshift.apply(newArgs, boundArgs);
	      return fn.apply(context, newArgs);
	    };

	  } else {
	    return function() {
	      return fn.apply(context, arguments);
	    };
	  }
	};
};
