
YAHOO.namespace('gaia.app.Arena');
YAHOO.gaia.app.Arena.Collection = function() {
    
    this._settings = null;
    this._ajaxRequest= null;

};


YAHOO.gaia.app.Arena.Collection.prototype.init = function(settings){
	

    this._settings = {

        //settings for watchlist 
        error_div:  YAHOO.util.Dom.get(settings.error_div),
        ajax_error: settings.ajax_error || 'ajax failures ...',
        href_prefix1: settings.href_prefix1,
        href_prefix2: settings.href_prefix2,
        ids: eval( settings.ids ),
		referalPageURL:settings.referalPageURL,
        ajax_url : "/arena/collection-set-cookie/"

    };
    this._attach_handlers(); 
    
};


YAHOO.gaia.app.Arena.Collection.prototype._attach_handlers = function() {
    for (var i in this._settings.ids) {
     YAHOO.util.Event.addListener(YAHOO.util.Dom.get( this._settings.href_prefix1 + this._settings.ids[i] ), 'click', this._doAjax, this,true);
     YAHOO.util.Event.addListener(YAHOO.util.Dom.get( this._settings.href_prefix2 + this._settings.ids[i] ), 'click', this._doAjax, this,true);
    }
    
}


YAHOO.gaia.app.Arena.Collection.prototype._doAjax = function(e, obj){
  YAHOO.util.Event.preventDefault(e);
  if(navigator.appName == 'Microsoft Internet Explorer')
  {
  	href = window.event.srcElement.parentElement.href;
	if(  href == undefined ) href = window.event.srcElement; 
  }else{
  	href = e.target.parentNode.href;
	if(  href == undefined ) href = e.target.href ; 
  }
    
  var callback = {
     success: function(o){
	 	location.href = o.responseText;
	},
     failure: function(o){
     },
     scope: this
  }
  	
  var param = "referalPageURL="+this._settings.referalPageURL+"&redirectionLink="+escape(href);
   this._ajaxRequest =  YAHOO.util.Connect.asyncRequest('POST',this._settings.ajax_url, callback, param);
};

function initCollection(settings) {
    collection = new YAHOO.gaia.app.Arena.Collection();
    collection.init(settings);

}
