function initBoxType(parentObj, obj){
	if (obj){
		boxTypes = $(obj);
		initBoxType(obj);
	} else {
		var boxTypes = $('[boxtype]', parentObj);
	}
	
	boxTypes.each(function(num){
		var boxType = $(boxTypes[num]).attr('boxType');
		if (!boxType){
			return;
		}
		var eventName = '_' + boxType;
		var boxoptions = $(boxTypes[num]).attr('boxoptions');
		var options;
		if (boxoptions){
			eval('options = {' + boxoptions + '}');
		}
		
		$(document).trigger(eventName, [$(boxTypes[num]), parentObj, options]);
		
	});
}
function urldecode( str ) {
    
    var histogram = {};
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urlencode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';

    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }
    
    ret = decodeURIComponent(ret);
    return ret;
}

$(document).ready(function(){
	initBoxType($(this));
});


function addRandNoCache(addr){
	var nocache = Math.floor((Math.random( ) * 1000));
	
	if (addr.search(/nocach=[0-9]/i) == -1){
		if (addr.search(/\?/i) != -1){
			addr += '&nocach=' + nocache;			
		} else {
			addr += '?nocach=' + nocache;
		}
	} else {
		addr = addr.replace(/(nocach=)[0-9]/i, "$1" + nocache);
	}
	
	return addr;
}

