/**
 * jBugger 0.2 - jBugger javascript tool
 * 
 * Copyright (c) 2008 Luiz Paulo (lppjunior.com)
 * 
 * @request JQuery
 * @request JQuery UI Resizeble
 */

jBugger = {
    VERSION   : "0.2 - 2009-06-28",
    THEME     : "black",
    LANG      : "en",
	loadFiles : [],
    
    init: function () {
    	//if(jQuery("#jBugger").length > 0) return;
    	
        var f = "jbugger.js";
        var script = jQuery("script[src*=" + f + "]").get(0);
        if(script == undefined) return;
        
        var src        = script.src;
        this.path      = src.substr(0, src.length - f.length);
        this.themePath = this.path + 'theme/' + this.THEME + "/";
        
		this.loadFiles.push(this.themePath + "css/styles.css");
        this.loadFiles.push(this.path + "lang/messages." + this.LANG +".js");
		this.loadFiles.push(this.path + "toolbar.js");
		
		//console includes
        this.loadFiles.push(this.path + "plugins/console/log.js");
        this.loadFiles.push(this.path + "plugins/console/console.js");
        this.loadFiles.push(this.path + "plugins/console/html.js");
		
        this.loadFiles.push(this.path + "plugins/error.js");
        
		this.loadFiles.push(this.path + "about.js");
		
        this.loadFiles.push(this.path + "plugins/rule/rule.js");
		this.loadFiles.push(this.path + "plugins/rule/rule.css");
        //this.loadFiles.push(this.path + "plugins/dom.js");
        //this.loadFiles.push(this.path + "plugins/topography.js");
		/* * */
        this.load();
    },//Method init
    
    extend: function (f){
		jQuery.extend(jBugger, f);
		for(method in f) {
			if(f[method].init != undefined) f[method].init();
		}
	},
    
    load: function () {
        var initHead  = '';
        for(var i = 0; i < this.loadFiles.length; i++) {
			if(this.loadFiles[i].indexOf(".css") > -1)
				initHead += '<link rel="stylesheet" type="text/css" href="' + this.loadFiles[i] + '" />';
			else
				initHead += '<script type="text/javascript" src="' + this.loadFiles[i] + '"></script>';
        }
        jQuery("head").append(initHead);
    },//Method load
    
    getMessage: function (value) {
        return (this.messages == undefined || this.messages[value] == undefined) ? "???" + value + "???" : this.messages[value];
    },//Method getMessage
	
	getVersion: function () {
		return this.VERSION.split(" - ")[0];
	}//Method getVersion
};

//Init jBugger
(function () {
	if(window.jQuery === undefined) {
		alert("AN ERROR IS OCCURRED!\n"
			+ "* jQuery framework is Undefined\n\n"
			+ "Please, import the jQuery 1.2.6 (or more) to use the jBugger plugin\n\n"
			+ "To any question, please access the url:\n"
			+ "http://blog.lppjunior.com\n\n"
			+ "Thanks");
	} else if(jQuery().resizable === undefined) {
		alert("AN ERROR IS OCCURRED!\n"
			+ "* Resizeble jQuery plugin is Undefined\n\n"
			+ "Please, import the jquery-ui-resizeble to use the jBugger plugin\n\n"
			+ "To any question, please access the url:\n"
			+ "http://blog.lppjunior.com\n\n"
			+ "Thanks");
	}else {
		jQuery(document.body).ready(function() { jBugger.init(); });
	}
})();