function switchStyle() {
	if (window.name=='chapter') {
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == 'compact') a.disabled = false;
			}
		}
	}
}

function changeLinks() {
	//if (window.name=='chapter') {
		chapterFrameLinks = document.getElementsByTagName('a');
		for (var i=0; i<chapterFrameLinks.length; i++) {
			if (chapterFrameLinks[i].getAttribute('rel')!='chapters' && window.name=='chapter') chapterFrameLinks[i].target = 'article';
			if (chapterFrameLinks[i].getAttribute('rel')=='external' && window.name=='article') chapterFrameLinks[i].target = '_top';
		}
	//}
}

function breakoutButton() {
	if (window.name=='article'||window.name=='chapter') {
		var breakout = document.createElement('a');
		breakout.id='breakout';
		breakout.title = 'show this page without frames';
		breakout.onclick = function() {
			window.top.location.href = window.location.href;
		}
		var content = document.createElement('span');
		content.className = 'non_visual';
		content.appendChild(document.createTextNode('break out of frames'));
		breakout.appendChild(content);
		document.body.appendChild(breakout);
	}
	if (window.name=='chapter') {
		var closebtn = document.createElement('a');
		closebtn.id='closebtn';
		closebtn.title = 'close this frame';
		closebtn.onclick = function() {
			window.top.location.href = parent.frames['article'].location.href;
		}
		var content = document.createElement('span');
		content.className = 'non_visual';
		content.appendChild(document.createTextNode('close this frame'));
		closebtn.appendChild(content);
		document.body.appendChild(closebtn);
	}
}

window.onload = function() {
	changeLinks();
	breakoutButton();
}

switchStyle();