// JavaScript Document

google.setOnLoadCallback(function(){	
	
	//insert custom product/author info in page
	$("#moreInfo").each(function(){
	prodID = $(this).attr("class");
	var infoURL = "http://" + location.host + "/xml/moreProductInfo.asp #" + prodID +" .academic";
	//alert (infoURL);
	$(this).load(infoURL);							 
								 
								 });
	
	
	$(".authorThm").each(function(){
		authorImage = $(this).text();
		findImg(authorImage,$(this));
		
								  })
	
	
	
	//main menu operation
	/*$("#list a").click(function(){
			
			$("#details>div").hide();
			var prodID = $(this).attr("class");
			showInfo(prodID);
			$("#"+prodID).fadeIn("slow");
									 
									 
									 }) */
	
	
var vidPosTop=($(window).height()/2)-(505/2);
var vidPosLeft=($(window).width()/2) - (853/2);

var youTubeVid = "kz2BnLwVAA";	
	
// hide HD video	
$(".hideVid").live("click", function(){
		$("#HDvid").empty();
		$("#player").hide();
		return false;
});

// pop out HD video

$(".videolinks a").live("click", function(){
	var scrY = window.pageYOffset || document.body.scrollTop;
	var urlArr = $(this).attr("href").split("=");
	youTubeVid = urlArr[urlArr.length-1];
	$("#player").fadeIn("slow");
	$("#playerbg").css("height",($(document).height()));
	$("#HDvid").css("top",vidPosTop + scrY);
	$("#HDvid").css("left",vidPosLeft);
	$("#HDvid").html('<embed src="http://blip.tv/play/'+youTubeVid+'" type="application/x-shockwave-flash" width="853" height="510" allowscriptaccess="always" allowfullscreen="true" autostart="true"></embed><p align="center"><a href="#" class="hideVid">Close Video</a></p>');
	return false;
		
});		

$(window).resize(function() {

vidPosTop=($(window).height()/2)-(510/2);
vidPosLeft=($(window).width()/2) - (853/2); 
$("#HDvid").css("top",vidPosTop);
$("#HDvid").css("left",vidPosLeft);
//$("#content").css("min-height",($(window).height()-55));

});	
	
	

// get params from url
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}


function findImg(aName,domNode){
	var xmlResult;
	var xmlURL = "http://" + location.host + "/img/authorImages.asp?a=" + aName;
	//alert(xmlURL);
	 $.ajax({
			type: "GET",
			url: xmlURL,
			dataType: "xml",
			success: function(xml){
				//alert("XML successfully loaded");
				$(xml).find("image").each(function(){	
					imageDescription = $(this).find("desc").text();
					imageLink = $(this).find("location").text();
					if (imageDescription == "Author Thumbnail"){
					xmlResult = '<img src="' + imageLink + '" border="0" alt="' + aName.replace("_"," ") + '"/>';
					$(domNode).html(xmlResult).show();
					}
					
				})
			}
		
		});
	
	
	
}

// load enhanced buy button
$("#buybtn").buynow();


//end jQuery
});


function showHide(obj) {
	 	 if (document.getElementById(obj).style["display"] == "none") {
	 	document.getElementById(obj).style["display"] = "";
			}
		else
			{document.getElementById(obj).style["display"] = "none";}
		}
		
function dualTabs(obj1,obj2) {
	 	 if (document.getElementById(obj1).style["display"] == "none") {
	 	document.getElementById(obj2).style["display"] = "none";
		document.getElementById(obj1).style["display"] = "";
			}
		//else {
		//document.getElementById(obj1).style["display"] = "none";
		//document.getElementById(obj2).style["display"] = "";
		//	}
			
		}
		
		
		
		
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function redir(isbn13){
                 window.location='books.asp?p=' + isbn13;
                    
                    }



function switchtabs(tabID){ 

// Detail Tabs Array
var tabMenu = document.getElementById("detailsmenu");
var tabList = tabMenu.getElementsByTagName("li");

// Detail Content Array
var tabContentDiv = document.getElementById("detailcontent");
var tabContent1 = tabContentDiv.getElementsByTagName("div");

// get only Tab class
var tabContent = new Array()
var classname="tab"
var inc=0
for (i=0; i<tabContent1.length; i++){
	//alert(tabContent1[i].className)
		if (tabContent1[i].className==classname){
		//alert(tabContent1[i].id);
		tabContent.push(tabContent1[i]);
		
		}
}
//cycle through tabs, show only selected, hide all others, highlight current menu tab
for(i=0; i<tabContent.length; i++){
	//alert(tabContent[i].id);
	if(tabContent[i].id != tabID){
		tabContent[i].style["display"]="none";
		tabList[i].setAttribute("class","");
		tabList[i].setAttribute("className","");	
		//alert(tabID + " != " + tabContent[i].id);
	}
	
	else{ 
		tabContent[i].style["display"]="block";
		tabList[i].setAttribute("class","current");
		tabList[i].setAttribute("className","current");
		//alert(tabID + " = " + tabContent[i].id);
	}
  }

}