jQuery(document).ready(function() 
{
	/**
	 * set up the carousel btns
	 **/
	buildRotatorBtns('#articlelist_blog li', ".jcarousel-control", 3);
	buildRotatorBtns('#articlelist_news li', ".jcarousel-controlNews", 3);

	jQuery("#carouselNews").jcarousel({
        scroll: 1,
        auto: 0,
        wrap: 'last',
		initCallback: function(carousel){ carousel_initCallback(carousel, '.jcarousel-controlNews')},
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
	
	jQuery("#mycarousel").jcarousel({
        scroll: 1,
        auto: 0,
        wrap: 'last',		
		initCallback: function(carousel){ carousel_initCallback(carousel, '.jcarousel-control')},
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
	
	jQuery("#homeTabs").tabs({ fx: { opacity: 'toggle', duration: 'normal' } });
	

});

/*
 * Carousel functions
 **/ 
// Function to build the yellow rotator btn, allowing a ratio of 1 btn per <ratio number> of items
function buildRotatorBtns(src, dest, ratio)
{
	src 		= jQuery(src);
	dest		= jQuery(dest);
	var size	= src.size();
	var opts	= Math.ceil(size / ratio);
	var	n		= 1;

	for (i=1 ; i<=opts ; i++)
	{
		
		if (i == 1) {	
		dest.append("<a href='#' id='" + n + "' class='controls active'>" + i +"</a>");	
		}else{
		dest.append("<a href='#' id='" + n + "' class='controls'>" + i +"</a>");
		}
		
		n = n + ratio;
	}
}

//callback function so we can set special settings
function carousel_initCallback(carousel, controls) 
{
	
	jQuery(controls + ' a').bind('click', function()
	{
		var el = jQuery(this);
		var id = jQuery.jcarousel.intval(el.attr('id'));
		
		//set the selected btn
		jQuery(controls + ' a.active').removeClass('active');
		el.addClass('active');
		
		carousel.scroll(id);
        return false;
	});
	
	// 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();
    });
};



jQuery(document).ready(function() {	

	//Show Banner
	
	//get first image 
	
	var firstImage = jQuery('.image_thumb ul li:first').find('a').attr("rel"); 
	var firstLink = jQuery('.image_thumb ul li:first').find('a').attr("href"); 
	jQuery('#mainRotator .main_image').append('<a href="' + firstLink + '"> <img src="' +firstImage + '" /> </a>' );
	
	jQuery("#mainRotator .main_image").fadeIn(2500); //Show Banner
	
	
	
	
	//Click and Hover events for thumbnail list
	jQuery(".image_thumb ul li:first").addClass('active'); 
	jQuery(".image_thumb ul li").click(function(){ 
		//Set Variables
		var neededinfo = jQuery(this);
		var imgAlt = jQuery(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = jQuery(this).find('a').attr("rel"); //Get Main Image Pic
		var imgLink = jQuery(this).find('a').attr("href"); //Get Main Image URL
		//var imgDescHeight = jQuery(".main_image").find('.block').height();	//Calculate height of block	
		
		if (jQuery(neededinfo).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
		
			
			jQuery("#mainRotator .main_image img").animate({ opacity: 0 }, 250 , function() {
					

					 	 jQuery("#mainRotator .main_image a").attr({ href: imgLink});
						 jQuery("#mainRotator .main_image img").attr({ src: imgTitle , alt: imgAlt});
						 jQuery("#mainRotator .main_image img").animate({ opacity:1 }, 400 , function() {
																											
							jQuery(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
							jQuery(neededinfo).addClass('active');  //add class of 'active' on this list only	// 
						 });
					
			});
			
		}
		
		
		jQuery(this).addClass('active');  //add class of 'active' on this list only
		return false;
		
	}) .hover(function(){
		jQuery(this).addClass('hover');

		}, function() {
		jQuery(this).removeClass('hover');
	});
			
	
	
});//Close Function
