/* ########################################################################### *
/* ***** DOCUMENT INFO  ****************************************************** *
/* ########################################################################### *
 * ##### NAME:  global.js
 * ##### VERSION: v1.0
 * ##### UPDATED: 23/06/09 (Jason Smale, Deloitte)
/* ########################################################################### *

/* ########################################################################### *
/* ***** INDEX *************************************************************** *
/* ########################################################################### *
/* ##### GLOBAL JS CONFIGURATION
/* ########################################################################### */

/* ########################################################################### *
/* ##### GLOBAL JS CONFIGURATION
/* ########################################################################### */

/* ########################################################################### *
/* ##### INITIALISATION
/* ########################################################################### */

$(document).ready(ecl_init_global);

function ecl_init_global()
{
	
	// Navigation
	ecl_navigation();
	
	//Expand clickable areas
	ecl_homepage();
	
	// Hide Show Member fieldsets;
	ecl_init_hide_show();
	
	// Form example text
	ecl_example_txt();
	
	// handle scrolling images in right panel
	scrollingImages();
	
	//Add Google Analytics Advertising tracking
	ecl_advertising_tracking();

}



/* ########################################################################### *
/* ##### PRESENTATION
/* ########################################################################### */

function ecl_navigation (){
	$("ul.sf-menu").superfish({speed: 1});
	
	$(".nav_primary ul li.active, .nav_primary ul li.trail").next().addClass('next');
	$(".nav_primary ul li").hover(function () {
		$(this).next().addClass("next");
	  },
	  function () {
		  if(!$(this).hasClass("active") && !$(this).hasClass("trail")){
			$(this).next().removeClass("next");
		  }
	  }
	)
}

function ecl_example_txt(){
	$('#form-search-01').example(function() {
	  return $(this).attr('title');
	});	
}

function scrollingImages() {
	
	//Randomly cycle through scrolling images.
	if($('.scrollingImages').length){
		$('.scrollingImages').cycle({
								 fx: 'fade',
								 timeout: 4000
								 });	
	}

}

function ecl_advertising_tracking(){
	
	//advert links have rel="advert" on them, each time it clicks, sends info to google
	$("a[rel='advert']").each(function(){
		   $(this).click(function(){
		      var href = $(this).attr("href");
		      pageTracker._trackEvent("Advert", "Click", href);
		      return true;
		   });
		});
}

function ecl_homepage() {
	//Expand clickable area
//	$('.newsItem').css('cursor','pointer')
//				  .hover(function(){
//					  $(this).find("a").css('text-decoration','underline');
//				  },function(){
//					  $(this).find("a").css('text-decoration','none');
//				  })
//				  .click(function(){
//				      window.location = $(this).find("a").attr("href");
//				  });
	
	//Randomly cycle through images on the home page.
	if($('#homeBannerImages').length){
		$('#homeBannerImages').cycle({
								 fx: 'fade',
								 timeout: 8000
								 });	
	}
	
	if($.browser.msie){
		//Fade images in and out on hover
		$('.logos a img').css("opacity", 0.5);
		$('.logos a img')	
		.hover(function(){
			$(this).css("opacity", 1);
		},function(){
			$(this).css("opacity", 0.5);
		});
	}else{
		//Fade images in and out on hover
		$('.logos a img').fadeTo("fast", 0.5);
		$('.logos a img')	
		.hover(function(){
			$(this).fadeTo("fast", 1);
		},function(){
			$(this).fadeTo("fast", 0.5);
		});
	}

	
	if (!((jQuery.browser.msie)&&(parseInt(jQuery.browser.version)<=6))) {
	if($('#scroller').length>0){
		$('#scroller').jcarousel({
			wrap: 'last',
			initCallback: mycarousel_initCallback
		});
	}
	}
	
	
}

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();
    });
};


function scrollingWidth(){
	$('#scroller')
	.css('width','30000px');
	
	$('#logoContainer')
	.css('position','relative')
	.css('overflow','hidden')
	.css('height','40px')
	.css('top','2px');
}

function scrollDivLeft(id){
  clearTimeout(timerRight) 
  document.getElementById(id).scrollLeft-=scrollStep
  timerRight=setTimeout("scrollDivLeft('"+id+"')",10)
}

function scrollDivRight(id){

  clearTimeout(timerLeft)
  document.getElementById(id).scrollLeft+=scrollStep
  timerLeft=setTimeout("scrollDivRight('"+id+"')",10)
}

function stopMe(){
  clearTimeout(timerRight) 
  clearTimeout(timerLeft)
}

function ecl_init_hide_show(){
	$('.form-container .memberHeading h2')	.css('cursor','pointer')
											.each(function(){
												if(!$(this).hasClass('active')){		   
													$(this).addClass('collapsed');
													$(this).parent().next('fieldset').hide();
												}
											})
											.hover(function(){
												$(this).css('text-decoration','underline');
											},function(){
												$(this).css('text-decoration','none');
											})
											.click(function(){
												if($(this).hasClass('collapsed')){	
													$(this).parent().next('fieldset').show();
													$(this).removeClass('collapsed');
												}else{
													$(this).parent().next('fieldset').hide();
													$(this).addClass('collapsed');
												}
											});		
}


/* FIN */