/**
 * @author jordi.touza
 *
 * Agent PROTOTYPE
 * v1
 */

if (typeof(_funky.client) == "undefined") _funky.client = {};
else alert(" var name 'client' is already set!");

_funky.client = function(){

	return {browser:this.browser(), platform:this.platform(), ViewportSize : this.getViewportSize()};
};

/**
 * Obtiene el nombre del sistema operativo del cliente
 */
_funky.client.prototype.platform = function(){

	var platform	= navigator.platform;
	var isWin		= false;
	var isMac		= false;

	if ((platform == "Win32")  || (platform == "Windows")){

		isWin = true;
		return "windows";
	}

	if ((platform == "Mac68K") || (platform == "MacPPC") || (this.platform == "Macintosh")){

		isMac = true;
		return "mac os x";
	}

	if ((platform == "X11") && !isWin && isMac){

		return "unix";
	}
};

/**
 * Obtiene el nombre del navegador del cliente
 */
_funky.client.prototype.browser = function()
{
	var userAgent  	= navigator.userAgent;
	var isOpera 	= false;

	if (userAgent.indexOf("Opera") > -1){

		isOpera = true;
		return "opera";
	}

	if (userAgent.indexOf("Gecko") > -1)																						return "mozila";
	if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") && !isOpera> -1) 										return "IE";
	if (userAgent.indexOf("KHTML") > -1 || userAgent.indexOf("konqueror") > -1 || userAgent.indexOf("AppleWebKit") > -1) 		return "KHTML";

	return "not supported";
};


_funky.client.prototype.getViewportSize = function()
{
    var x, y;

    if (self.innerHeight) { // MOZ

        y = self.innerHeight;
        x = self.innerWidth;

    } else if (document.documentElement && document.documentElement.clientWidth) { // IE6 Strict

        x = document.documentElement.clientWidth;
        y = document.documentElement.clientHeight;

    } else if (document.body.clientHeight) { // IE quirks

        y = document.body.clientHeight;
        x = document.body.clientWidth;
    }
    return {x: x, y: y};
};

