$(document).ready(function() {
    
	var clickID = $("#clickID").html();
	
    $("#popBox").hide();
	/*$("#popBox .content").load("pages/prl.php",{},function(){
			$('#popBox').show();
			$('#libs').animate({ 
				marginTop: "190px"
			}, 0 );
		});*/
	
	
	$("#libsmenu").jqDock({size:55, duration:250, align:'middle'});
	
	$("#libsmenu2").jqDock({size:50, duration:250, align:'middle'});
	
	$("#libs li img").mouseover(function(){
			 $('#libsname').fadeIn('fast')
			 var title = $(this).attr("rel");
			 var name = $(this).attr("name");
			 $("#libsname").html(title);
			 //removed buy now button +"<br><span><a href='http://store.biblesoft.com/ProductDetails.asp?ProductCode="+name+"'><img src='http://pcstudybible.com/images/button_buynow_small.gif'></a></span>"
      });
	

	
	$("#libs").mousemove(function(){
								  
			clearTimeout(t);		  
		
		}).mouseout(function(){
		  
		 	t = setTimeout("$('#libsname').fadeOut('fast')", 100);
		  });

	$("#libsBuy").click(function() {
		//alert(clickID);						 
		fadein("pages/libraries_buy.php?click=" + clickID);		
		return false;
    });
	
	//PRL
	$("li#lib_prl").click(function() {
		fadein("pages/prl.php?click=" + clickID);		
		return false;
    });
	
	//ARL
	$("li#lib_arl").click(function() {
		fadein("pages/arl.php?click=" + clickID);		
		return false;
    });
	
	//CRL
	$("li#lib_crl").click(function() {
		fadein("pages/crl.php?click=" + clickID);		
		return false;
    });
	
	//RLP
	$("li#lib_rlp").click(function() {
		fadein("pages/rlp.php?click=" + clickID);		
		return false;
    });
	
	//NRL
	$("li#lib_nrl").click(function() {
		fadein("pages/nrl.php?click=" + clickID);		
		return false;
    });
	
	//DRL
	$("li#lib_drl").click(function() {
		fadein("pages/drl.php?click=" + clickID);		
		return false;
    });
	
	//Watch the demo
	$("a.viewDemo").click(function() {
		fadeinmovie("videos/generaloverview/GeneralOverview_small.html");
		return false;
    });

	//Watch the demo
	$("li#watchDemo").click(function() {
		fadeinmovie("videos/generaloverview/GeneralOverview_small.html");
		return false;
    });
	
	//Comparison Chart
	$("li#comparisonChart").click(function() {
		fadein("pages/compChart.php");	 	
		return false;
    });
	
	//Learn More
	$("li#learnMore").click(function() {	
		fadein("pages/learnMore.php");		
		return false;
    });
	
	$("#popBox img.close").click(function() {
		fadeOut();
		return false;
    });
	
	$("#logo").click(function() {
		fadeOut();
		return false;
    });
	
	
	
	
	
	/*$("a.fancybox").fancybox({ 
      'frameWidth': 750, 
      'frameHeight': 550, 
      'overlayShow': false 
    }); */
  }); 

function fadeOut(){
	$('#popBox').fadeOut("fast");
		$('#libs').animate({ 
			marginTop: "40px"
		}, 500 );
}

function fadein(pagename){
	
	//fadeOut popbox to make smoother transition
	$('#popBox').fadeOut(100, function(){
										   
	loadcontent(pagename);
		
	   });
}

function loadcontent(pagename){
	$("#popBox .content").load(pagename,{},function(){
				$('#popBox').fadeIn(200);
				
				if($.browser.msie && $.browser.version.substr(0,1) == 7){
					$('#libs').animate({ 
						marginTop: "210px"
					}, 500 );
					
					//alert($.browser.msie + ", " + $.browser.version.substr(0,1));
				}
				else{
					$('#libs').animate({ 
						marginTop: "190px"
					}, 500 );
	
				}
				
			//learnmore functions
			learnmorePage()
			//set css for .content to start scrolling - already specified in the stylesheet?
			$("#popBox .content").css("overflow-y","auto");
			
			});
	
	
}


function fadeinmovie(pagename){

//create random variable for IE caching
var currentTime = new Date();
var RandomVariable = currentTime.getTime();


//pop this individually so that we can piggy-back the loading of the first video
		$("#popBox .content").load("videos/index.php?date="+RandomVariable,{},function(){
			$('#popBox').fadeIn("slow");
			
			if($.browser.msie && $.browser.version.substr(0,1) == 7){
				$('#libs').animate({ 
					marginTop: "210px"
				}, 500 );
				
				//alert($.browser.msie + ", " + $.browser.version.substr(0,1));
			}
			else{
				$('#libs').animate({ 
					marginTop: "190px"
				}, 500 );

			}
			
			//show first movie
				loadmovie(pagename+"?date="+RandomVariable);
			//add selected class to first movie
				$(".demothumb:eq(0)").addClass("selectedthumb");
			//load movie functions
				moviefunctions();
			//set css for .content to stop scrolling
				$("#popBox .content").css("overflow-y","hidden");
				
		});
}

function loadmovie(demopage){
	$("#MoviePlayer").load(demopage,{},function(){
													   
		});
}

function moviefunctions(){
	
	
	$(".demothumb").click(function(){
								   
		//remove all selectedthumb classes
		$(".demothumb").removeClass("selectedthumb");
		
		//find index of thumb clicked
		var index = $(".demothumb").index(this);
		
		//set selectedthumb class to new thumb
		$(".demothumb:eq("+index+")").addClass("selectedthumb");
							   
	});	
	
}

function learnmorePage(){
	
$("ul li div").slideUp();

$("ul li a").click(function(){
							
		$(this).next("div").slideToggle();
		$(this).parent().toggleClass("active");
		
		//$("ul li:nth-child("+index+") div").slideDown();
		
							});
	
}

function scrolltome(loc){
	
	$("#popBox .content").scrollTo('+=130px',800);
}
function OpenNewWindow(url, width, height) { 

	var randomnumber=Math.floor(Math.random()*5001);
	window.open(url, randomnumber, "top=10,left=10,menubar=0,resizable=1,scrollbars=1,width=" + width + ",height=" + height);

}