// for quick search at top
var inputText = "Quick Search";

$(function()
{
    $('.ro').mbRollover({
	endStr: '_o'
    });
    
    $('.popWin').click(function(){
    	popWindowMenus($(this).attr('href'), '_new', '900', '800');
    	return false;
    });
	
    $("a[rel^='lightbox']").prettyPhoto({
	animationSpeed: 'slow',
	padding: 40,
	opacity: 0.85,
	showTitle: false,
	allowresize: true,
	counter_separator_label: '/',
	theme: 'light_rounded'
    });
    
    $('#nav').superfish({
    	delay:       1000,                            // one second delay on mouseout 
        animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
        speed:       'fast',                          // faster animation speed 
        autoArrows:  false,                           // disable generation of arrow mark-up 
        dropShadows: false                            // disable drop shadows
    });


    $(".qsrch-input").val(inputText); 
    
    $(".qsrch-input").click(function(){
        if(inputText == $(this).val()){
           $(this).val("");
           $(this).css("color","#333");
        }
    });
    
    $(".qsrch-input").blur(function(){
        if($(this).val() == "" ){
             $(this).val(inputText);
             $(this).css("color","#a4a3a3");
        }
    });
    
    
    $("#topSearchForm").submit(function(){
      var inptxt = $("#qsrchInputID").val();
    
      //alert(inptxt + "|" + inputText);
    
      if(inptxt==inputText)
         $("#qsrchInputID").val("");
    });
    
    
    /* Video JS */
    $("#video-multiple .video-link").live("click", function(e){
    	e.preventDefault();
    	var video = $(this).attr("title");
    	$('#modalVideo').mbModal({
            createDiv: '<div class="video-lyr"><div id="videoCloseWrap"><a href="javascript:;" id="videoClose"><img src="/images/videoClose.png" alt="Close" width="29" height="26" border="0" /></a></div><iframe width="560" height="315" src="http://www.youtube.com/embed/'+video+'" frameborder="0" allowfullscreen></iframe></div>',
            buttonClose: 'videoClose',
            zIndexStart: 2000
        }, function () {
           $(".video-lyr").children("iframe").attr("src", "http://www.youtube.com/embed/"+video);
        }, function () {
           $(".video-lyr").children("iframe").attr("src", "");
        });
    });
    
    $(".videoIcon a").live("click", function(e){
    	e.preventDefault();
    	var video = $(this).attr("rel");
    	$('#modalVideo').mbModal({
            createDiv: '<div class="video-lyr"><div id="videoCloseWrap"><a href="javascript:;" id="videoClose"><img src="/images/videoClose.png" alt="Close" width="29" height="26" border="0" /></a></div><iframe width="560" height="315" src="http://www.youtube.com/embed/'+video+'" frameborder="0" allowfullscreen></iframe></div>',
            buttonClose: 'videoClose',
            zIndexStart: 2000
        }, function () {
           $(".video-lyr").children("iframe").attr("src", "http://www.youtube.com/embed/"+video);
        }, function () {
           $(".video-lyr").children("iframe").attr("src", "");
        });
    });

    $(".video-wrapper:odd").addClass("odd");
    $(".video-book:odd").addClass("odd");
    
    $(".video-description-inner").each(function(){
	$inner = $(this).children("div");
	if($inner.height() < $(this).height())
	{
		$(this).parent().children(".video-description-more").remove();		
	}
    });

    $('.video-description-more').live("click", function(e){
    	var _thischild = $(this).children("a");
    	$inner = $(this).prev("div.video-description-inner");
    	var innerheight = $inner.children("div").height();
    	
    	if(_thischild.html() == "(more)"){
    		$inner.animate({height: innerheight+'px'}, 600, 'linear', function(){
    			_thischild.html("(less)");
	    	});
	}else{
    		$inner.animate({height: '98px'}, 600, 'linear',  function(){
    			_thischild.html("(more)");
	    	});
	}
    });
    
    $(".video-more").each(function(){
    	var w = $(this).children("a").width()+7;
    	$(this).width(w);
    });
    
    $(".video-more").live("click", function(e){
    	var w = $(this).children("a").width()+7;
    	$(this).width(w);

    	var _this = $(this);
    	$books = $(this).prev("div.book-limit");
    	var _thischild = _this.children("a");
    	
    	if(_thischild.html() == "Show more items"){
    		$books.slideDown("normal", "linear", function(){
    			_thischild.html("Show fewer items");
    			_this.addClass("less");
	    	});
	}else{
    		$books.slideUp("normal", "linear",  function(){
    			_thischild.html("Show more items");
    			_this.removeClass("less");
	    	});
	}
    	    	
    });
    
    $(".video-more a").live("click", function(e){
    	e.preventDefault();
    });
    
    $("#videoFilterBtn").click(function(e){
    	var record = $("#record").val();

    	if(record == ""){
    		$("#feedback").html('<div class="error">Please enter a Book ID or Catalog No.</div>');
    		return false;
	}else{
    		$("#feedback").html('');
		$.ajax({
			type: "POST",
			url: "pjp_lib_ajax.php",
			data: "record="+record,
			success: function(msg){
				if(msg == "null")
				{
					$("#feedback").html('<div class="error">Sorry, we did not find a video with the value you entered.</div>');
				}else{
					var records = msg.split(",");
					$("#showall").show();
					$(".video-wrapper").hide();
					$.each(records, function(a, b){
						$("#video-"+b).show();
					});
				}
			},
			error: function(msg){
				$("#feedback").html('<div class="error">Sorry, we could not process your request.  Please try again.</div>');
			}
		});
    		return false;
	}
    });
    
    $("#showallvids").click(function(){
    	$(".video-wrapper").show();
    	$("#showall").hide();
    });
});

function checkSrchFrmSbmt()
{
	var inptxt = $("#qsrchInputID").val();

	//alert(inptxt + "|" + inputText);

	if(inptxt==inputText)
	   $(".qsrch-input").val("");

	document.qSearchForm.submit();
}
