$(function(){
    $('a.ro').mbRollover();
    
    $("a[rel^='lightbox']").prettyPhoto({
	 animationSpeed: 'slow',
	 padding: 40,
	 opacity: 0.85,
	 showTitle: false,
	 allowresize: true,
	 counter_separator_label: '/',
	 theme: 'light_square'
    });
   
    $("#tray-wrapper").mbBookShowcase({
         showDetails: false,
         targetTray: 'featuredTrays', //div id of tray in your php fetch file trays.php
         trayOffset: 20,
         itemClass: 'book',
         imgClass: 'bookImg',
         mOvrClass: 'book-ovr',
         selClass: 'book-sel',
         followLink: true,
         loadTrayFromExternalFile: true,
         phpFetchFile: 'trays.php',
         phpFetchUrlValue: $('#showcaseCategoryId').val()
    }, function(){
    	 // optional callback function on click of each item
         // returns this.event ("load" or "click") and this.clickid (element id of the clicked book)
    });
   
    $('#tNavDD').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
    });
    $('#lNavDD').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
    });
     
    $('a.top').click(function(){
    	$('html,body').animate({scrollTop: 0}, 1500, 'easeOutBack');
    	return false;
    });
    
    initStaffPicks();
});

function initStaffPicks()
{
	var pCnt = new Array();
	var x = 1;
	
	var imgs = new Array(" ", "/images/circle-one.png", "/images/circle-two.png", "/images/circle-three.png", "/images/circle-four.png", "/images/circle-five.png");
	var imgs2 = new Array(" ", "/images/circle-one1.png", "/images/circle-two1.png", "/images/circle-three1.png", "/images/circle-four1.png", "/images/circle-five1.png");

	$("a.changePick[rel=1]").removeClass("ro").removeClass("mbRollover").undelegate("img", "mouseenter mouseleave");
	$("a.changePick[rel=1]").children("img").attr("src", imgs2[1]);
	
	$("div.pick:odd").addClass("pick-odd");
    
    $("div.pick div.pick-content-wrapper").each(function(){
    	pCnt[x] = parseInt($("div.pick"+x+" li.numPicks").attr("rel"));
    	if(pCnt[x] <= 1){
        	//alert("pick#"+x+"numPicks="+pCnt[x]);
    		$("div.pick"+x+" li a.changePick[rel^='"+pCnt[x]+"']").addClass("remove");
    	}
    	x++;
    });
    var prevTemp = 1;
    $("a.changePick").click(function(){
    	var temp = parseInt($(this).attr("rel"));
    	grandparent = $(this).parent().parent().parent().parent();
    	mom = $(this).parent().parent();
    	$(mom).children("li:visible").each(function(a,b){
    		var c = a+1;
    		$(this).children("a.changePick").addClass("ro").mbRollover();
    		$(this).children("a.changePick").children("img").attr("src",imgs[c]);
    	});
    	$(this).children("img").attr("src", imgs2[temp]);
    	$(this).removeClass("ro").removeClass("mbRollover").undelegate("img", "mouseenter mouseleave");
    	changePick(temp, grandparent);
    	prevTemp = temp;
    });
    
    
}
var prevPNum = 1;
function changePick(pNum, par)
{
	if(prevPNum != pNum)
	{
		if(prevPNum>pNum)
		{
			var pos = 245 * ( prevPNum - pNum );
			
			$(par).children("div.pick-content").children("div.pick-tray").animate({
				top: "+="+pos+"px"
			}, 1300, function(){
			
			});
		}else{
			var pos = 245 * ( pNum - prevPNum );
			$(par).children("div.pick-content").children("div.pick-tray").animate({
				top: "-="+pos+"px"
			}, 1300, function(){
			
			});
		}
	}

	prevPNum = pNum;
	
}
