var newSrc = '';
var cacheCount = 0;

jQuery(document).ready(function() {

	jQuery('.image_box').css('opacity',0.75);

	$(".carousel .jCarouselLite").jCarouselLite({
		btnPrev: ".carousel .jCarouselLite .prev",
		btnNext: ".carousel .jCarouselLite .next",
		auto: 10000,
		speed: 600
	});

	$(".carousel .jCarouselPapers").jCarouselLite({
		btnPrev: ".carousel  .prev",
		btnNext: ".carousel  .next",
		speed: 600
	});

	$(".jCarouselTestimonials").jCarouselLite({
		btnPrev: ".carousel #testimonials-controls .prev",
		btnNext: ".carousel #testimonials-controls .next",
		speed: 600
	});

	/* homepage centres widget */

	jQuery('#centres_nav a').removeClass('active');
	jQuery('#little-aston').addClass('active');
	jQuery("#c_intro").attr("href", "/little-aston/overview")
//	jQuery("#c_fac").attr("href", "/little-aston/facilities")
	jQuery("#c_gal").attr("href", "/little-aston/gallery")
	jQuery("#c_cons").attr("href", "/little-aston/consultants")
	jQuery("#c_cont").attr("href", "/little-aston/contact-us")
	jQuery('#centres_img').attr("src","/images/stories/centres-nav/main-image/centres_little-aston.jpg");
	jQuery("#readMoreLink").attr("href", "/little-aston/overview")

    jQuery('#centres_nav a').bind('click', function() {
		jQuery('#centres_nav a').removeClass('active');
		jQuery(this).addClass('active');
		switch(this.id){
		
			case 'little-aston':
				jQuery('#centres_right').css('background-position','0px 0px');
				break;
				
			case 'elstree-cancer-centre':
				jQuery('#centres_right').css('background-position','0px -213px');
				break;
			
			case 'southampton':
				jQuery('#centres_right').css('background-position','0px -426px');
				break;

			case 'south-downs':
				jQuery('#centres_right').css('background-position','0px -639px');
				break;
			
		}

		jQuery('#centres_img').attr("src","/images/stories/centres-nav/main-image/centres_"+this.id+".jpg");

		jQuery("#c_intro").attr("href", "/"+this.id+"/overview")
//		jQuery("#c_fac").attr("href", "/"+this.id+"/facilities")
		jQuery("#c_gal").attr("href", "/"+this.id+"/gallery")
		jQuery("#c_cons").attr("href", "/"+this.id+"/consultants")
		jQuery("#c_cont").attr("href", "/"+this.id+"/contact-us")

		jQuery('#readMoreLink').html('<strong>READ MORE :</strong> ' + this.id.toUpperCase().replace('-',' '));
		jQuery("#readMoreLink").attr("href", "/"+this.id+"/overview")
       return false;
	});

	/* centres menu dropdown */

	jQuery('.dd_centres li').css('background-color','transparent');
	jQuery('#elstree_menu_item').css('background-color','#005580');
	jQuery('.subCentres').hide();
	jQuery('#elstree_sub').show();
	
    jQuery('#elstree_menu_item').mouseover(function()  {
		jQuery('.dd_centres li').css('background-color','transparent');
		jQuery(this).css('background-color','#005580');
		jQuery('.subCentres').hide();
		jQuery('#elstree_sub').show();
        return false;
	});

    jQuery('#aston_menu_item').mouseover(function()  {
		jQuery('.dd_centres li').css('background-color','transparent');
		jQuery(this).css('background-color','#005580');
		jQuery('.subCentres').hide();
		jQuery('#aston_sub').show();
        return false;
	});

    jQuery('#ports_menu_item').mouseover(function()  {
		jQuery('.dd_centres li').css('background-color','transparent');
		jQuery(this).css('background-color','#005580');
		jQuery('.subCentres').hide();
		jQuery('#ports_sub').show();
        return false;
	});

    jQuery('#soton_menu_item').mouseover(function()  {
		jQuery('.dd_centres li').css('background-color','transparent');
		jQuery(this).css('background-color','#005580');
		jQuery('.subCentres').hide();
		jQuery('#soton_sub').show();
        return false;
	});
	
	// Get the Top News Items for the drop down menu
	$.post(
		'/newsfeed/index.php',
		{ action:'get' },
		function(data) {
			jQuery('#aboutUsNewsListWrapper').html(data);
		}
	);
	

	jQuery('.item img').each(function(index) {
		jQuery.preLoadImages(jQuery(this).attr('src').replace('thumbs/',''), jQuery(this).attr('src').replace('thumbs/',''));
		cacheCount++;
	});
	
	if (cacheCount < 4){ jQuery('.prev').addClass('disabled'); jQuery('.next').addClass('disabled'); }
	
	jQuery(".scrollable").scrollable({ vertical: true });

		jQuery('.item img').fadeTo(0, 0.7);
		
		
			jQuery(".item img").hover(
			  function () {
						jQuery(this).stop().fadeTo("fast", 1);
			  }, 
			  function () {
						jQuery(this).stop().fadeTo("fast", 0.7);
			  }
			);

		
		jQuery('.item img').bind('click',function(event) {

			newSrc = jQuery(this).attr('src').replace('thumbs/','')

			if ( $('#fullImage').attr('src') != newSrc) {
			
				$('#fullImage').stop().animate({ opacity: 0	}, 300, 'linear', function() {
					  jQuery('#fullImage').attr('src',newSrc);
					  $('#fullImage').animate({ opacity: 1	}, 300, 'linear', function() {
						 
					 });
				  });
			
			}
			
		});


});
	
	
 (function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

