/* NB: This script is shared by the following Web sites:
 *   perseuspromos.com, perseustools.com, etc.
 *   perseusacademic.com
 *   toolkit sites (pgwtoolkit.com, pbgtoolkit.com, perseustoolkit.com, cbsdtoolkit.com, etc.)
 *
 *   FULL PATH: /usr/local/www/apache22/data/PAB/p/perseusbookspromos.com/html/js/reveal_book_content.php
 *   ABSOLUTE URL: http://www.perseuspromos.com/js/reveal_book_content.php
 */

if (typeof PBP_SHARED == "undefined") {
	var PBP_SHARED = {};	
}

PBP_SHARED.bookHeadline = "About the Book";
PBP_SHARED.bookcontentHeadline = "About the Book";
PBP_SHARED.buyHeadline = "Buy the Book";
PBP_SHARED.excerptHeadline = "Excerpt";
PBP_SHARED.reviewsHeadline = "Reviews";
PBP_SHARED.tocHeadline = "Table of Contents";
PBP_SHARED.specialHeadline = "Special Content";

PBP_SHARED.hideAllBookContent = function() {
	$$('.bookPageContent').each(function(i){ i.hide(); });
	$$('.bookcontentPageContent').each(function(i){ i.hide(); });
	$$('.buyPageContent').each(function(i){ i.hide(); });
	$$('.excerptPageContent').each(function(i){ i.hide(); });
	$$('.reviewsPageContent').each(function(i){ i.hide(); });
	$$('.tocPageContent').each(function(i){ i.hide(); });
	$$('.specialPageContent').each(function(i){ i.hide(); });
	$$('#resourcesPageContent').each(function(i){ i.hide(); });

	$$('#aboutLink a').each(function(i){ i.style.color=''; i.style.textDecoration=''; });
	$$('#reviewsLink a').each(function(i){ i.style.color=''; i.style.textDecoration=''; });
	$$('#buyLink a').each(function(i){ i.style.color=''; i.style.textDecoration=''; });
	$$('#rlLink a').each(function(i){ i.style.color=''; i.style.textDecoration=''; });
	$$('#tocLink a').each(function(i){ i.style.color=''; i.style.textDecoration=''; });
	$$('#tocLink a').each(function(i){ i.style.color=''; i.style.textDecoration=''; });
	$$('#tocLink a').each(function(i){ i.style.color=''; i.style.textDecoration=''; });
	$$('#tocLink a').each(function(i){ i.style.color=''; i.style.textDecoration=''; });
	$$('#tocLink a').each(function(i){ i.style.color=''; i.style.textDecoration=''; });
	$$('#tocLink a').each(function(i){ i.style.color=''; i.style.textDecoration=''; });
	$$('#tocLink a').each(function(i){ i.style.color=''; i.style.textDecoration=''; });

	$$('#resourcesLink a').each(function(i){i.className='';});


} // end hideAllBookContent

PBP_SHARED.gotoBuyPage = function(standardBodyIds) {
	PBP_SHARED.hideAllBookContent();
	$$('.buyPageContent').each(function(i){
		i.show();
	});
	document.body.id = "buy";
	document.body.id += standardBodyIds ? "Page" : "";
	if ($('bookHead') && PBP_SHARED.buyHeadline) {
		$('bookHead').update(PBP_SHARED.buyHeadline);
	}
	if ($('flashcontentHead') && PBP_SHARED.buyHeadline) {
		var src = "";
		var width;
		var height;
		if ($$('#flashcontentHead embed').length > 0) {
			src = $$('#flashcontentHead embed')[0].src;
			width = $$('#flashcontentHead embed')[0].width;
			height = $$('#flashcontentHead embed')[0].height;
		} else if ($$('#flashcontentHead object').length > 0) {
			src = $$('#flashcontentHead object')[0].src;
			width = $$('#flashcontentHead object')[0].width;
			height = $$('#flashcontentHead object')[0].height;
		}
		if (src != "") {
			var so = new SWFObject(src, PBP_SHARED.buyHeadline, width, height, 8, '#FFFFFF');
			so.addParam('wmode', 'transparent');
			so.addParam('FlashVars', 'headline=' + escape(PBP_SHARED.buyHeadline));
			so.write('flashcontentHead');
		}			
	} // end if
	PBP_SHARED.adjustJacketImage(standardBodyIds);
} // end gotoBuyPage

PBP_SHARED.gotoBookPage = function(standardBodyIds) {
	PBP_SHARED.hideAllBookContent();
	$$('.bookPageContent').each(function(i){
		i.show();
	});
	document.body.id = "book";
	document.body.id += standardBodyIds ? "Page" : "";
	if ($('bookHead') && PBP_SHARED.bookHeadline) {
		$('bookHead').update(PBP_SHARED.bookHeadline);
	}
	if ($('flashcontentHead') && PBP_SHARED.bookHeadline) {
		var src = "";
		var width;
		var height;
		if ($$('#flashcontentHead embed').length > 0) {
			src = $$('#flashcontentHead embed')[0].src;
			width = $$('#flashcontentHead embed')[0].width;
			height = $$('#flashcontentHead embed')[0].height;
		} else if ($$('#flashcontentHead object').length > 0) {
			src = $$('#flashcontentHead object')[0].src;
			width = $$('#flashcontentHead object')[0].width;
			height = $$('#flashcontentHead object')[0].height;
		}
		if (src != "") {
			var so = new SWFObject(src, PBP_SHARED.bookHeadline, width, height, 8, '#FFFFFF');
			so.addParam('wmode', 'transparent');
			so.addParam('FlashVars', 'headline=' + escape(PBP_SHARED.bookHeadline));
			so.write('flashcontentHead');
		}
	} // end if
	PBP_SHARED.adjustJacketImage(standardBodyIds);
} // end gotoBookPage

PBP_SHARED.adjustJacketImage = function(standardBodyIds) {
	if($('jacketImage') && $('jacketImage').up().tagName == "A") {
		var imageAnchorTag = $('jacketImage').up();
		imageAnchorTag.href = "#";
		var buyPattern = new RegExp("buy", "gi");
		if (buyPattern.match(document.body.id)) {
			imageAnchorTag.onclick = function() {
				PBP_SHARED.gotoBookPage(standardBodyIds);
			}
		} else {
			imageAnchorTag.onclick = function() {
				PBP_SHARED.gotoBuyPage(standardBodyIds);
			}
		} // end if
	}	
}

PBP_SHARED.changeBookContent = function(standardBodyIds) {
	// disable right-clicks for artwork that is not final
	$$('img.fpo').each(function(i){
		i.oncontextmenu = function(){
			return false;	
		}
	});
	
	if (
	      $('bookPage') ||
		 $('bookcontentPage') ||
		 $('buyPage') ||
		 $('excerptPage') ||
		 $('reviewsPage') ||
		 $('tocPage') ||
		 $('specialPage') ||
		 $('book') ||
		 $('bookcontent') ||
		 $('buy') ||
		 $('excerpt') ||
		 $('reviews') ||
		 $('toc')
	) {
		
		PBP_SHARED.adjustJacketImage(standardBodyIds);
		
		if($('aboutLink')) {
			$$('#aboutLink a')[0].href = "#";
			$$('#aboutLink a')[0].onclick = function() {
				PBP_SHARED.gotoBookPage(standardBodyIds);
			}
		} // end if
		
		if($('bookcontentLink')) {
			$$('#bookcontentLink a')[0].href = "#";
			$$('#bookcontentLink a')[0].onclick = function() {
				PBP_SHARED.hideAllBookContent();
				$$('.bookcontentPageContent').each(function(i){
					i.show();
				});
				document.body.id = "bookcontent";
				document.body.id += standardBodyIds ? "Page" : "";
				if ($('bookHead') && PBP_SHARED.bookcontentHeadline) {
					$('bookHead').update($$('#bookcontentLink a')[0].innerHTML);
				}
				if ($('flashcontentHead') && PBP_SHARED.bookcontentHeadline) {
					var src = "";
					var width;
					var height;
					if ($$('#flashcontentHead embed').length > 0) {
						src = $$('#flashcontentHead embed')[0].src;
						width = $$('#flashcontentHead embed')[0].width;
						height = $$('#flashcontentHead embed')[0].height;
					} else if ($$('#flashcontentHead object').length > 0) {
						src = $$('#flashcontentHead object')[0].src;
						width = $$('#flashcontentHead object')[0].width;
						height = $$('#flashcontentHead object')[0].height;
					}
					if (src != "") {
						var so = new SWFObject(src, PBP_SHARED.bookcontentHeadline, width, height, 8, '#FFFFFF');
						so.addParam('wmode', 'transparent');
						so.addParam('FlashVars', 'headline=' + escape(PBP_SHARED.bookcontentHeadline));
						so.write('flashcontentHead');
					}			
				} // end if
			} // end loop
		} // end if
		
		if($('buyLink')) {
			$$('#buyLink a')[0].href = "#";
			$$('#buyLink a')[0].onclick = function() {
				PBP_SHARED.gotoBuyPage(standardBodyIds);
			}
		} // end if
		
		if($('excerptLink')) {
			$$('#excerptLink a')[0].href = "#";
			$$('#excerptLink a')[0].onclick = function() {
				PBP_SHARED.hideAllBookContent();
				$$('.excerptPageContent').each(function(i){
					i.show();
				});
				document.body.id = "excerpt";
				document.body.id += standardBodyIds ? "Page" : "";
				if ($('bookHead') && PBP_SHARED.excerptHeadline) {
					$('bookHead').update(PBP_SHARED.excerptHeadline);
				}
				if ($('flashcontentHead') && PBP_SHARED.excerptHeadline) {
					var src = "";
					var width;
					var height;
					if ($$('#flashcontentHead embed').length > 0) {
						src = $$('#flashcontentHead embed')[0].src;
						width = $$('#flashcontentHead embed')[0].width;
						height = $$('#flashcontentHead embed')[0].height;
					} else if ($$('#flashcontentHead object').length > 0) {
						src = $$('#flashcontentHead object')[0].src;
						width = $$('#flashcontentHead object')[0].width;
						height = $$('#flashcontentHead object')[0].height;
					}
					if (src != "") {
						var so = new SWFObject(src, PBP_SHARED.excerptHeadline, width, height, 8, '#FFFFFF');
						so.addParam('wmode', 'transparent');
						so.addParam('FlashVars', 'headline=' + escape(PBP_SHARED.excerptHeadline));
						so.write('flashcontentHead');
					}			
				} // end if
			} // end loop
		} // end if
		
		if($('reviewsLink')) {
			$$('#reviewsLink a')[0].href = "#";
			$$('#reviewsLink a')[0].onclick = function() {
				PBP_SHARED.hideAllBookContent();
				$$('.reviewsPageContent').each(function(i){
					i.show();
				});
				document.body.id = "reviews";
				document.body.id += standardBodyIds ? "Page" : "";
				if ($('bookHead') && PBP_SHARED.reviewsHeadline) {
					$('bookHead').update(PBP_SHARED.reviewsHeadline);
				}
				if ($('flashcontentHead') && PBP_SHARED.reviewsHeadline) {
					var src = "";
					var width;
					var height;
					if ($$('#flashcontentHead embed').length > 0) {
						src = $$('#flashcontentHead embed')[0].src;
						width = $$('#flashcontentHead embed')[0].width;
						height = $$('#flashcontentHead embed')[0].height;
					} else if ($$('#flashcontentHead object').length > 0) {
						src = $$('#flashcontentHead object')[0].src;
						width = $$('#flashcontentHead object')[0].width;
						height = $$('#flashcontentHead object')[0].height;
					}
					if (src != "") {
						var so = new SWFObject(src, PBP_SHARED.reviewsHeadline, width, height, 8, '#FFFFFF');
						so.addParam('wmode', 'transparent');
						so.addParam('FlashVars', 'headline=' + escape(PBP_SHARED.reviewsHeadline));
						so.write('flashcontentHead');
					}			
				} // end if
			} // end loop
		} // end if
		
		if($('tocLink')) {
			$$('#tocLink a')[0].href = "#";
			$$('#tocLink a')[0].onclick = function() {
				PBP_SHARED.hideAllBookContent();
				$$('.tocPageContent').each(function(i){
					i.show();
				});
				document.body.id = "toc";
				document.body.id += standardBodyIds ? "Page" : "";
				if ($('bookHead') && PBP_SHARED.tocHeadline) {
					$('bookHead').update(PBP_SHARED.tocHeadline);
				}
				if ($('flashcontentHead') && PBP_SHARED.tocHeadline) {
					var src = "";
					var width;
					var height;
					if ($$('#flashcontentHead embed').length > 0) {
						src = $$('#flashcontentHead embed')[0].src;
						width = $$('#flashcontentHead embed')[0].width;
						height = $$('#flashcontentHead embed')[0].height;
					} else if ($$('#flashcontentHead object').length > 0) {
						src = $$('#flashcontentHead object')[0].src;
						width = $$('#flashcontentHead object')[0].width;
						height = $$('#flashcontentHead object')[0].height;
					}
					if (src != "") {
						var so = new SWFObject(src, PBP_SHARED.tocHeadline, width, height, 8, '#FFFFFF');
						so.addParam('wmode', 'transparent');
						so.addParam('FlashVars', 'headline=' + escape(PBP_SHARED.tocHeadline));
						so.write('flashcontentHead');
					}
				} // end if
			return false;
			} // end loop

		} // end if
		
		if($('specialLink')) {
			$$('#specialLink a')[0].href = "#";
			$$('#specialLink a')[0].onclick = function() {
				PBP_SHARED.hideAllBookContent();
				$$('.specialPageContent').each(function(i){
					i.show();
				});
				document.body.id = "specialPage";
				if ($('bookHead') && PBP_SHARED.tocHeadline) {
					$('bookHead').update(PBP_SHARED.specialHeadline);
				}
				if ($('flashcontentHead') && PBP_SHARED.specialHeadline) {
					var src = "";
					var width;
					var height;
					if ($$('#flashcontentHead embed').length > 0) {
						src = $$('#flashcontentHead embed')[0].src;
						width = $$('#flashcontentHead embed')[0].width;
						height = $$('#flashcontentHead embed')[0].height;
					} else if ($$('#flashcontentHead object').length > 0) {
						src = $$('#flashcontentHead object')[0].src;
						width = $$('#flashcontentHead object')[0].width;
						height = $$('#flashcontentHead object')[0].height;
					}
					if (src != "") {
						var so = new SWFObject(src, PBP_SHARED.specialHeadline, width, height, 8, '#FFFFFF');
						so.addParam('wmode', 'transparent');
						so.addParam('FlashVars', 'headline=' + escape(PBP_SHARED.specialHeadline));
						so.write('flashcontentHead');
					}			
				} // end if
			} // end loop
		} // end if
		
	} // end pageId if
	
} // end changeBookContent

function resourcesShow () {

	if( location.href.indexOf("http://www.westviewpress.com") == 0 ) var color='#462073'; else var color = '#000066'
	PBP_SHARED.hideAllBookContent()
	var r = document.getElementById('resourcesPageContent');
	r.style.display='block';
	$$('#resourcesLink a').each(function(i){ 
	 i.className='thisSelected';
	});
	$$('.merchLinks li a').each(function(i){ 
	 if(i.className) return false;
	 i.style.textDecoration='underline';
	 i.style.color=color;
	});
}

