//
// Kosmix application javascript
// (try to use JS classes as much as possible)
// The kapp global namespace
var kapp = {}
// kapp Global init
//
kapp.init = function() {
	// Set global vars
	this.javascript = true;
	this.home =  _proxy_jslib_handle( _proxy_jslib_handle(document, 'location', '', 0, 0), 'protocol', '', 0, 0) + "//" +  _proxy_jslib_handle( _proxy_jslib_handle(document, 'location', '', 0, 0), 'host', '', 0, 0);
}
kapp.init();

// Sleep
//
kapp.nap = function(m) {
	var then = new (Date)(new (Date)().getTime() + m); 
	while (new (Date)() < then) {} 
}
// Kosmix Cookie class (or should that be Kookie? )
//
kapp.Cookie = function() {
	// Member vars
	this.support = false; 
    /* createCookie, readCookie, and eraseCookie are copied from
     * QuirksMode http://www.quirksmode.org/js/cookies.html
     * and are copyright Peter-Paul Koch, based on a script by Scott Andrew;
     * used under license http://www.quirksmode.org/about/copyright.html
     */
    this.create = function(name,value,permanent,session) {
    	var expires = "";
        if (! session)
        {
        	var minutes = permanent ? 10000*24*60 : 24*60;
            var date = new (Date)();
            date.setTime(date.getTime() + minutes*60*1000);
            var expires = "; expires="+date.toGMTString();
        }

         _proxy_jslib_assign('', document, 'cookie', '=', ( name + "=" +  _proxy_jslib_handle(null, 'value', value, 0, 0) + expires + "; path=/"));
    }
    
    this.read = function(name) {
        var nameEQ = name + "=";
        var ca =  _proxy_jslib_handle(document, 'cookie', '', 0, 0).split(';');
        for(var i=0;i < ca.length;i++)        {
            var c =  _proxy_jslib_handle(ca, (i), 0, 0);
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return (c.substring(nameEQ.length,c.length));
        }
        return null;
    }
    
    this.erase = function(name) {
        this.create(name,"",-1);
    }
    // Constructor
    {
        var test = "KosmixCookieTest";
        this.create(test, "true", 0);
        if (this.read(test) == "true") {
            this.support = true;
            this.erase(test);
       }
    }
} 
 _proxy_jslib_assign('', kapp, 'cookie', '=', ( new (kapp.Cookie)())); // Global var

//ads related global variables
kapp.ads = {}
kapp.ads.dc_tile=0;
kapp.ads.axel = Math.random() + "";
kapp.ads.ord = kapp.ads.axel * 1000000000000000000;
kapp.ads.cat1="";
kapp.ads.cat2="";
kapp.ads.cat3="";
kapp.ads.cat4="";
kapp.ads.cat5="";
kapp.ads.cat6="";
kapp.ads.cat7="";
kapp.ads.cat8="";
kapp.ads.cat9="";
kapp.ads.cat10="";
kapp.ads.ts="";
kapp.ads.kw="";		// user-entered keyword
kapp.ads.ksite="";	// eg: kosmix, kosmixused
kapp.ads.advid ="";	// advertiser-id - added to adserver call
kapp.ads.adid = "";	// ad-id - added to adserver call


kapp.ads.showall = function (inpstr, hide) {

	var tokens = inpstr.split(':');
	for(i = 0; i < tokens.length; i++){
		var adid =  _proxy_jslib_handle(tokens, (i), 0, 0);
		try {
			if (typeof adid != "undefined") {
				var hadid = 'h' + adid;
				var addiv =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(adid);				
				if ((typeof addiv != "undefined") && (addiv != null)) {
					addiv.style.height='auto';
					var haddiv =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(hadid);
					haddiv.style.height='auto';
					var ht = addiv.offsetHeight;					
					if (ht > 73) {
						haddiv.style.display = 'block';
						addiv.style.display = 'block';
					}
					else {
						if (hide) {
							haddiv.style.display = 'none';
							addiv.style.display = 'none';
						}					
					}
				}
			}
		}
		catch (e) {}
	}
}

kapp.ads.hideall = function() {
	var adids = ['moduleAds_body_top','moduleAds_body_right1',
				 'moduleAds_body_right2','moduleAds_body_bottom'];
	for (i = 0; i < adids.length; i++) {
		try {
			var adid =  _proxy_jslib_handle(adids, (i), 0, 0);
			var addiv =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(adid);
			if (addiv != null) addiv.style.display = 'none';
		}
		catch (e) {}
	}
}
 ;
_proxy_jslib_flush_write_buffers() ;