/**
 * An ajax ad viewer.
 * @class
 * @scope public
 */
 
 /**
  *	@brief Constructor
  *
  *	@param in_tag_type is the type of tag we want ads for
  * @param in_div the div where the ajax content will go
  *	@param in_tag_id The id of the tag (optional, only on a tag page)
  */
function AdViewer(in_tag_type, in_div, in_tag_id) 
{
    /**
     * The currently selected suggestions.
     * @scope private
     */   
    this.tag_type = in_tag_type;
	this.div = in_div;
    this.tag_id = in_tag_id || -1;
	this.height = getWindowHeight();
	this.request = null;
	this.mutex = 0;		//semaphore
	
	//make our request object
    if (typeof XMLHttpRequest != "undefined") {
        this.request = new XMLHttpRequest();
    } else if (typeof ActiveXObject != "undefined") {
        this.request = new ActiveXObject("MSXML2.XmlHttp");
    } else {
        alert("No XMLHttpRequest object available. This functionality will not work.");
    }
	

	this.getAds();
}

 /**
  *	@brief show the requested page
  *
  */
AdViewer.prototype.getAds = function() 
{
	var me = this;	//for some reason I can't use this on the 'onreadystatechange' function, it has to be a local variable
	
	if (me.mutex == 0)
	{
		me.mutex = 1;	//lock the control
		
		var sURL = "ajax/get_ad_viewer.php?tag_type=" + me.tag_type + 
				   "&tag_id=" + me.tag_id + 
				   "&dummy=" + new Date().getTime();
		
		//open connection to the gallery getter
		me.request.open("get", sURL , true);
		
		me.request.onreadystatechange = function () {
			if (me.request.readyState == 4) 
			{
				if (me.request.status == 200)
				{
					me.div.innerHTML = me.request.responseText;
				}
				me.mutex = 0;
			}   
		};
		
		me.request.send(null);
	}
}
