// JavaScript Document

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

$(document).ready(function() {
	
	$("#topMenu > ul > li:last-child").addClass("withOutBackground").css("padding-right", "0");
	$(".subMenu > ul > li:last-child").addClass("withOutBackground").css("padding-right", "0");
	
	$("#footerLegal ul li:last-child").css("margin-right", "0").css("border-right", "0");
	$("#footerLinks ul li:last-child").css("margin-right", "0").attr("style", "border-right: 0; background:none;");
	$("#topMenu ul li ul li").hover(
	  function () {
		$(this).parent().parent().children("a").addClass("hover");
	  }, 
	  function () {
		$(this).parent().parent().children("a").removeClass("hover");
	  }
	);
	
	//Homepage Photogallery Connector
	$('#slider').html('');
	
	$.ajax({
    	type: "GET",
        url: "/index.cfm?method=pages.showPhotoGalleryXML&photogalleryid=f4ff24b0-fd81-c9ec-afa9-036eea831c6a", // replace with absolute URL of your gallery's xml file
        dataType: "xml",
        success: function(xml) {
			$(xml).find('img').each(function() {
			   var location = '/assets/images/photogallery/images/large/';
			   var photo = $(this).attr('src');
			   var alt = $(this).attr('caption');
			   var url = $(this).attr('link');
				if (url == undefined) 
					{
						$('#slider').append('<img src="'+location+''+photo+'" alt="'+alt+'"/>');
					}
				else
					{
						$('#slider').append('<a href="'+url+'"><img src="'+location+''+photo+'" alt="'+alt+'"/></a>');	
					}
			});

		}

   	});
	
	setTimeout ( "showSlider()", 1000 );
	
	getTwitters('tweets', { 
		id: 'langmeilwinery', 
		count: 2, 
		enableLinks: true, 
		ignoreReplies: true, 
		clearContents: true,
		template: '<a href="http://twitter.com/%user_screen_name%/statuses/%id_str%/">%time%</a> %text%'
	});
	
	jQuery('#homepageCarousel').jcarousel({
        wrap: 'circular',
		scroll: 1,
		animation: 'slow',
		auto: 5,
        initCallback: mycarousel_initCallback
    });
	
});


function showSlider() {
	
	$('#slider').nivoSlider({
		effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
		slices:15, // For slice animations
		animSpeed:500, // Slide transition speed
		pauseTime:5000, // How long each slide will show
		startSlide:0, // Set starting Slide (0 index)
		directionNav:false, // Next & Prev navigation
		controlNav:false // 1,2,3... navigation
	});
	
}



