
if(typeof ($.AWA) == "undefined") {
	jQuery.AWA = Object;
}

//Create the hompage carousel
jQuery.AWA.buildCarousel = {
	init: function(){
		jQuery('.showcase').append('<ul class="controls"><li class="previous"><a href="#">Previous</a></li><li class="pause">Pause</li><li class="resume">Play</li><li class="next"><a href="#">Next</a></li></ul>')

		jQuery('.carousel').cycle({ 
		    fx:     'scrollHorz', 
		    next:   '.next a', 
		    pause:   1,
		    prev:   '.previous a',
		    //random: 1,
		    speed:  '2000', 
		    timeout: 8000
		});
		
		jQuery('.showcase .resume').hide();
		
		jQuery('.pause').click(function() { 
		    jQuery('.carousel').cycle('pause'); 
		    jQuery('.showcase .pause').hide();
		    jQuery('.showcase .resume').show();
		});
		
		jQuery('.resume').click(function() { 
		    jQuery('.carousel').cycle('resume', true);
		    jQuery('.showcase .resume').hide();
		    jQuery('.showcase .pause').show();
		});
		
	} // End init
}

//Inject HTML into each dropdown nav for curved corners
jQuery.AWA.addNavFooter = {
	init: function(){
		jQuery('.primary ul li').children('div').append('<div class="nav-bottom"><span class="l"></span><span class="r"></span></div>');
		
	} // End init
}

//Remove the margin from the 4th item of every thumbnail row to stop it wrapping onto the next line
jQuery.AWA.removeNthThumbnailMargin = {
	init: function(){
		jQuery('.landing-page .thumbnails ul li:nth-child(4n)').addClass('no-margin');
		
	} // End init
}

jQuery.AWA.buildEqmsTour = {
	init: function(){
		jQuery('.screens').cycle({ 
		    fx:     'scrollHorz', 
		    speed:  '2000', 
		    timeout: 0, 
		    pager:  '.pages div ul', 
		    pagerAnchorBuilder: function(idx, slide) { 
		        // return selector string for existing anchor 
		        return '.pages li:eq(' + idx + ') a'; 
		    } 
		});
	} // End init
}



jQuery(document).ready(function(){
	jQuery.AWA.buildCarousel.init();
	jQuery.AWA.buildEqmsTour.init();
	jQuery.AWA.addNavFooter.init();  
	jQuery.AWA.removeNthThumbnailMargin.init();
	jQuery.gaTracker('UA-10792175-1'); //Initialise Google Analytics tracking
});	
