// Javascript specific to the home page.


$(document).ready(
	function(){

		// load the top carousel through ajax
		
		//$.get("/Carousel.aspx", 
		//	  { }, 
		//	  function(data){ 
		//	    alert(data);
		//		$('#topCarouselWrapper').html(data);
		//	} 
		//);

		$("#perspectiveCarousel_1").jCarouselLite({
				btnNext: "#perspectivePrev",
				btnPrev: "#perspectiveNext",
				btnDoubleNext: "#perspectivePrev2",
				circular: "true",
				visible:1,
				easing: "expoinout",
				speed: 500,
				scroll:1,
				onBuild : function(a,that){
					$(a).addClass('clickable');
					$(a[0]).click(function(){
						$('#perspectiveNext').click();					
					});
				},
				afterEnd : function(a){
					$(a).addClass('clickable');
					$(a).unbind();
					$(a[0]).click(function(){
						$('#perspectiveNext').click();					
					});
				}
			});

		$("#perspectiveCarousel_2").jCarouselLite({
				btnNext: "#perspectivePrev",
				btnPrev: "#perspectiveNext",
				btnDoubleNext: "#perspectivePrev2",
				circular: "true",
				visible:1,
				easing: "expoinout",
				speed: 500,
				scroll:1
			});

		$("#perspectiveCarousel_3").jCarouselLite({
			btnNext: "#perspectivePrev",
			btnPrev: "#perspectiveNext",
			btnDoubleNext: "#perspectivePrev2",
			circular: "true",
			visible:2,
			easing: "expoinout",
			speed: 500,
			scroll:1,
			onBuild : setupCarouselClicks,
			afterEnd : setupCarouselClicks
		});

		function setupCarouselClicks(a) {
			// clear any possibly conflicting actions
			$(a).unbind();
			// make sure the book panel appears clickable
			$(a).addClass('clickable');
			// set up the first book to move one step
			$(a[0]).click(function(){
				$('#perspectivePrev').click();
			});
			// set up the 2nd book to move two steps
			$(a[1]).click(function(){
				$('#perspectivePrev2').click();
			});
		}

		// and do a little cleanup for layout purposes
		$("#perspectiveCarousel_3").width(135);
		$("#featuredCollectionBanner").css("z-index","300");

		$("#voicesCarousel").jCarouselLite({
				btnNext: "#voicesPrev",
				btnPrev: "#voicesNext",
				circular: "true",
				visible:12,
				easing: "expoinout",
				speed: 500,
				scroll:3,
				afterEnd: function (a) {
					a.eq(a.length -1).addClass('noBorderItem');
				},
				beforeStart: function (a) {
					a.eq(a.length -1).removeClass('noBorderItem');
				},
				onBuild: function (a) {
					a.eq(a.length -1).toggleClass('noBorderItem');
					$("#voicesCarousel").css("left","-2px");
				}
			});

		// balance our columns
		balanceColumnsWithFooter("#colNewAtMacmillan,#colComingSoon");
		balanceColumnsWithFooter("#macmillanNews,#toursAndEvents");
	
		//setup the rollovers for the bottom of the page copy
		$('#voicesCarousel li').hover(
			function() {
				$('#voicesCarousel li').removeClass('hoverStyle');
				$(this).addClass('hoverStyle');
				$('body').append('<div id="publisherNameFloat">' + $(this).find('a').attr('title') +'</div>');
				$('#publisherNameFloat').css("top", $(this).offset().top + 65);
				$('#publisherNameFloat').css("left", $(this).offset().left - ($('#publisherNameFloat').width()/2) + 32);

			},
			function() {
				$(this).removeClass('hoverStyle');
				$('#publisherNameFloat').remove();
			}
		);
		
		$('#voicesCarousel li.noBorderItem').hover (
			function() {
				$(this).css("border-right","1px solid #74736f");
			},
			function() {
				$(this).css("border-right","1px solid #E9E7DF");
			}
		);

		// now make sure that any carousel copy is properly truncated
		truncateCopyToParent('#perspectiveCarousel_2 ul li .itemInfo .bookBlurb', 40);

	}
);


