// js for component page documentation
// copyright Sun Microsystems
// contact webdesign -at- sun.com for info
// this script relies on sniff.js functions!

/*
reg.click('ul.compTabs > li > a@href',function(e){
	if (!this.ctx) {
		this.ctx = {};
		this.ctx.li = this.parentNode;
		this.ctx.allLi = gebtn('li', this.parentNode.parentNode);
		this.ctx.sect = gebi(this.href.split("#")[1]);
		this.ctx.allSect = gebcn('compSect',this.ctx.sect.parentNode);
	}
	for (var i=0;i<this.ctx.allLi.length;i++){
		rcn(this.ctx.allLi[i],'compCurrent');
	}
	for (var i=0;i<this.ctx.allSect.length;i++){
		acn(this.ctx.allSect[i],'hidethis');
	}
	acn(this.ctx.li,'compCurrent');
	rcn(this.ctx.sect,'hidethis');
	return false;
});
*/

addHashStateListener("^#(v\\d+x\\d+)\\-(\\w+)$", function(hash, ident, sectName){
	if (!this.ctx) {
		this.ctx = {};
		this.ctx.titleBar = gebcn('for-'+ident, this.parentNode.parentNode)[0];
		this.ctx.tabs = gebtn('li', this.ctx.titleBar);
		this.ctx.tab = gebs('li > a@href$="'+hash+'"', this.ctx.titleBar)[0].parentNode;
		this.ctx.allSect = gebcn('compSect',this.parentNode);
	}
	for (var i=0;i<this.ctx.tabs.length;i++){
		rcn(this.ctx.tabs[i],'compCurrent');
	}
	for (var i=0;i<this.ctx.allSect.length;i++){
		acn(this.ctx.allSect[i],'hidethis');
	}
	acn(this.ctx.tab,'compCurrent');
	rcn(this,'hidethis');
	var top = document.documentElement.scrollTop;
	getXY(this.ctx.tab);
	var tabTop = this.ctx.tab.Y;
	if (top < 10 || top > tabTop) {
		window.scrollTo(0,tabTop-10);
	}
});

reg.setup('div.compTitlebar', function(){
	var h4 = gebtn('h4',this)[0];
	var inner = h4.parentNode;
	var compStatus = h4.className;
	var tabs = gebcn('compTabs',this)[0];
	if (compStatus && compStatus != 'current') {
		acn(tabs,'hidethis');
		var revealer = elem('a',{'href':'#'},'show '+compStatus+' sample and code');
		var revealerP = elem('p.revealer',{},revealer);
		inner.appendChild(revealerP);
		revealer.tabs = tabs;
		revealer.div = this;
	}
});

reg.click("a@href.templateLink", function(){
	window.open(this.href, "_template", "scrollbars,resizable,status,width=900,height=800");
	return false;
});

reg.click('li.compCurrent > a@href',function(){return false;});
