$(document).ready(function() {
// functions for product pages

// initialize tabs for product pages	
		$("ul.detailsmenu:first").tabs("div.detailcontent:first > div").history();

// find author thumbnails
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();
					}
					
				})
			}
		
		});
}	
	
//display author thumbnail on product page
	
	$(".authorThm").each(function(){
		authorImage = $(this).text();
		findImg(authorImage,$(this));
	  })
	

// get ISBN from post class
reviewISBN = $("#bookreviews>div").attr("class");

if(typeof reviewISBN!='undefined'){
	// check if blog is empty before loading
authorBlog = $.ajax({
										url:thisServer + "reviewfeeds.asp?r="+ reviewISBN,
										success:function(blog){
																if(blog=="empty"){
																var buzzLog = $("#blogContent>#buzzlog_btm").html();
																$("#bookreviews").html();
																$("#blogs").css("min-height","50px").height(50);
																}
																else {
																$("#bookreviews").html(blog);
																}
																
															}
											
									});
	
	
}

//insert custom product/author info in page
	$("#moreInfo").each(function(){
	prodID = $(this).attr("class");
	var infoURL = "http://" + location.host + "/xml/moreProductInfo.asp #" + prodID;
		$(this).load(infoURL);							 
								 
								 });	
	
// HD video player							 
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));

});									
			
// load enhanced buy button
var expose = $("#buycontent").expose({
							
							// return exposing API 
    						api: true, 
 
    						// use our customized mask 
   							 maskId: 'popover', 
 
    						// mask opacity
   							 opacity: 0.5, 
 
    						// close expose slowly 
    						closeSpeed: 'slow', 
 

});

$("#buybtn").click(function(){
			expose.load();
				var scrY = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
				var vidPosTop=($(window).height()/2)-(400/2);
				//var vidPosLeft=($(window).width()/2) - (400/2);
				var vidPosLeft= 200;
			$("#buycontent").css("top",vidPosTop + scrY).css("left",vidPosLeft).fadeIn("slow");
			return false;
});

$("#closebutton").click(function(){
			$("#buycontent").hide();
			expose.close();
});

// remove font tags from product descriptions
$("font").each(function(){
	$(this).replaceWith($(this).html());
});



//end jQuery
}); 