
var g_oProductDetailsPanel = null;

getProductDetailsPanel = function() {
	try {
    	if (g_oProductDetailsPanel == null) {
            g_oProductDetailsPanel = new ProductDetailsPanel();
        }
        return g_oProductDetailsPanel;
    } catch (e) {

    }
}

ProductDetailsPanel = function() {
	
	var _selector = "div#product-further-details";
	var _fancy = "fancy";
	var _selected = "selected";
	var _container = {};
	var _panels = {};
	var _links = {};
	
	this.getSelector = function() { return _selector; }
	
	this.getContainer = function() { return _container; }
	this.setContainer = function(obj) {
		try {
			this._container = obj;
		} catch(e) {}
	}
	
	
	this.init = function(){
		this.setContainer($(this.getSelector()));
		this._container.wrapInner("<div class=\"fancy\"></div>");
		this._panels = this._container.find("div.panel");
		this._links = this._panels.children("h2").find("a");
		this._links.each(function(i){
			$(this).click(function(){
				getProductDetailsPanel().changePanel(i);
				return false;
			})
			$(this).focus(function(){
				getProductDetailsPanel().changePanel(i);
			})
		});
		this.changePanel(0);
	}
	
	this.changePanel = function(index){
		this.reset();
		this.open(index)
	}
	
	this.reset = function() {
		this._panels.each(function(){
			getProductDetailsPanel().close(this)
		})
	}
	
	this.close = function(el) {
		$(el).removeClass("selected")
		$(el).children("h2").children("a").children("span").css("padding-bottom","0px");
	}
		
	this.open = function(index) {
		$(this._panels[index]).addClass("selected");
		$(this._panels[index]).children("h2").children("a").children("span").css("padding-bottom","1px");
	}
	
}

g_oProductDetailsPanel = getProductDetailsPanel();
