/**************************
 @ JTab
 @ Created on 5 September 2008
 @ giovann.adonis@graydot.co.za
*************************/

var widths = new Array;
widths = {
        property_search : 'width:80px;',
        advanced_search: 'width:100px;',
        map_search: 'width:40px;',
		area_information: 'width:40px;',
		news: 'width:20px;',
		sell: 'width:20px;',
		financing: 'width:20px;',
		financhise: 'width:20px;',
		dstv: 'width:50px;'
};


var JTab = Class.create();
JTab.prototype = {
	image : null,
    width : null,
    height: null,
    name  : "",
    id_prefix : "",
    JContentPane : null,
    div   : null,
    cssactive : null,
    cssinavtive : null,
    parent : null,
    onfunction : null,
    offfunction : null,
    jdata : null,
    initialize : function (data) {
        if (data['image']) this.image = data ['image'];
        if (data['width']) this.width = data ['width'];
        if (data['height']) this.height = data ['height'];
        if (data['prefix']) this.id_prefix = data ['prefix'];
        if (!data ['name']) {
            alert ("ERROR: No Tab name");
            return;
        }
	this.jdata = data ['javadata'];
	this.onfunction = data ['onjavacode']
	this.offfunction = data ['offjavacode']
        this.cssactive = data ['active'];
        this.cssinavtive = data ['inactive'];
        this.name = data ['name']
        this.createTabDiv ();
        this.name = data ['name'];
        if (data['CPane']) this.setJContentPane (data['CPane']); 
        
    },
    createTabDiv : function () {
        var _div = document.createElement ("div");
        this.div = _div;
        this.div.id = this.id_prefix + "-" + this.name.replace (/ /g,"-");
        // this.div.innerHTML = "<img alt='"+this.name+"' src='images/tab_"+this.name+".png' style='height:15px;"+widths[this.name]+"' border='0' />";
        if (this.width) this.div.style.witdh = this.width + "px;";
        if (this.height) this.div.style.height = this.height + "px";
        var self = this;
        this.div.onclick = function () {
            self.activate ();
        }
    },
    setJContentPane : function (JPane) {
        JPane.setId (this.div.id + "-content-pane");
         this.JContentPane = JPane;
    },
    getJContentPane : function () {
        return this.JContentPane;
    },
    activate: function (use_html) {
        if (this.getParent().getParent () ) {
            this.getParent().getParent ().cleanOut ();
        }
        this.div.className = this.cssactive;
        this.getJContentPane().activate(use_html);
	if (this.onfunction) {
		this.onfunction (this.jdata);
	}
    },
    deactivate : function () {
        this.div.className = this.cssinavtive;
        this.getJContentPane().deactivate(); 
	if (this.offunction) {
		this.offunction ();
	}
    },
    setParent : function (parent){
        this.parent = parent;
    },
    getParent : function () {
        return this.parent;
    }
}

