// 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 +" .fidelis";
	//alert (infoURL);
	$(this).load(infoURL);							 
								 
								 });
	
	
	$(".authorThm").each(function(){
		authorImage = $(this).text();
		findThm(authorImage,$(this));
		
								  });
	
		$(".authorImg").each(function(){
		authorImage = $(this).text();
		findImg(authorImage,$(this));
		
								  });
	
	
	
	//main menu operation
	$("#detailsmenu a").click(function(){
			
			$("#detailcontent>div").hide();
			$("#detailsmenu .current").removeClass("current");
			var tabID = $(this).attr("href");
			$(this).parent().addClass("current");
			$(tabID).fadeIn("fast");
			return false;
									 
									 
									 });

 //Jquery load video into tab

	$(".vidmenu li a").click(function(){
			
			$(".player").html("");
			$("#homevideo .active").removeClass("active");
			$(this).addClass("active");
			// get video name from URL
			var urlArr = $(this).attr("href").split("=");
			showVid = urlArr[urlArr.length-1];
			// replace current video contents with new video
		
			if (showVid == "g6AUgYmGOgA" ){
				
			// youtube Code for Armed With Truth
			//embedCode = "http://www.youtube.com/v/" + showVid +"&ap=%2526fmt%3D18&rel=0&fs=1&color1=0x4A1900&color2=0x4A1900&border=0&loop=0&hl=en&feature=player_embedded";
			
			strNewVid = '<object width="420" height="276"><param name="movie" value="http://www.youtube.com/v/Wrw9l_wr6R8&hl=en&fs=1&color1=0x000000&color2=0x000000&rel=0&loop=0&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Wrw9l_wr6R8&hl=en&fs=1&color1=0x000000&color2=0x000000&rel=0&loop=0&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="420" height="276"></embed></object>';	
				
				
			}
			
			else if  (showVid == "tPFXXpFGVEo" ){
				// Samaritan YouTube Trailer
				strNewVid = '<object width="420" height="276"><param name="movie" value="http://www.youtube.com/v/'+ showVid+'&hl=en&fs=1&color1=0x000000&color2=0x000000&rel=0&loop=0&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+ showVid+'&hl=en&fs=1&color1=0x000000&color2=0x000000&rel=0&loop=0&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="420" height="276"></embed></object>';	
			}
			
			else {
			
			//blip.tv code
			strNewVid = '<embed src="http://blip.tv/play/'+ showVid+'" type="application/x-shockwave-flash" width="420" height="276" allowscriptaccess="always" allowfullscreen="true"></embed>';
		}
			
			$(".player").html( strNewVid);
			
			
			return false;
			});


// 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 findThm(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();
					}
					
				});
			}
		
		});
}

	 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 Image"){
					xmlResult = '<img src="' + imageLink + '" border="0" alt="' + aName.replace("_"," ") + '"/>';
					$(domNode).html(xmlResult).show();
					}
					
				});
			}
		
		});
}
	 

//hide all but first tab on load
			$("#detailcontent>div").hide();
			$("#detailsmenu li:first").addClass("current");
			$("#detailcontent>div:first").fadeIn("fast");
			$("#homevideo li:first a").addClass("active");

//get author photo on product page
			//authorName = $("#author").attr("class");
			//$("#author").css("backgroundImg","url(img/authors/" + authorName + ".jpg)","backgroundRepeat","none");

// 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);
	}
  }

}