﻿
VisitorContent = function(rootElement, servicePath, contentFile, configFile)
{
	this._rootElem = rootElement;
	this._servicePath = servicePath;
	this._configFile = configFile;
	this._contentFile = contentFile;
	//this._callbackDelegate = callbackDelegate;
	//this._detectNetbook = detectNetbook;
	//this._netbookOverride = netbookOverride;
}

VisitorContent.prototype =
{
	initialize: function() {
		var caller = this;
		var netbook = this.netbookDetect();
		var silverlight = this.silverlightDetect();

        //TODO: consolidate all the http requests into just 1 request, grab all the content and put it in the correct content areas
         jQuery.ajax({
                type: "GET",
                url: this._servicePath,
                data: { content: this._contentFile, config: this._configFile, netbook: netbook, silverlight: silverlight },
                success: function(data) {
                    caller.showContent(data);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(textStatus);
                }
            });
            
//		jQuery.ajax(
//			this._servicePath,
//			{ content: this._contentFile, config: this._configFile, netbook: netbook, silverlight: silverlight },
//			function(data) {
//				caller.showContent(data);
//			});
	},

	showContent: function(data) {
		jQuery(this._rootElem).append(data);

		// bind any tooltips in the loaded content.
		// TODO: refactor to observer or controller
		/*if (typeof (f_display) != "undefined") {
			f_display.bindTooltipsTo(jQuery(this._rootElem + " .win7_tooltip"));
		}
		if (typeof (f_display_generic) != "undefined")
		{
			f_display_generic.bindTooltipsTo(jQuery(this._rootElem + " .win7_generic"));
		}

		if (this._callbackDelegate != null) {
			this._callbackDelegate();
		}*/
	},

	netbookDetect: function() {
		var maxw = 1024;
		var maxh = 600;

		if (screen.width < maxw && screen.height < maxh)
			return true;
		return false;
	},

	silverlightDetect: function() {
		if (typeof (Silverlight) != 'undefined') {
			return Silverlight.isInstalled('2.0');
		}
		return false;
	}
}
