/* Author: 

*/

$(function(){
  $("#slides").slides({
    preload: true,
    play: 8000,
    pause: 4000,
	generatePagination: false
  });
});

// Make all the footer-items the same height so that the white lines are all the same 
var max = 0;    
$('footer .footer-item').each(function() {
    max = Math.max($(this).height(), max);
}).height(max);

//--------------------------------------------------------------------------- Toggling banner ->>

jQuery.fn.hoverAOP = function(options) {
	var originalImage = $('.attachment-post-thumbnail').attr("src");
	$(this).hover(function() { // on hover, do this when the mouse enters
		var settings = jQuery.extend({
			}, options);
		
			var fullPath = '/wp-content/themes/moyleslaw/img/banner-aop/' + options.imageName + '.jpg';
			
			$('.attachment-post-thumbnail').attr( {
							src: fullPath
						});
		
		$('.banner ul ul li a').removeClass("current");
		$(this).addClass("current");
		} /* do you want it to revert to the page's original image upon mouseleave? uncomment this!
			, function() { //do this when the mouse leaves
				$(this).removeClass("current");
				$('.attachment-post-thumbnail').attr("src", originalImage);
			} 
			*/
			)
	};

$('#menu-item-519 a').hoverAOP({imageName: 'personal-injury'});

$('#menu-item-522 a').hoverAOP({imageName: 'tractor-trailer'});

$('#menu-item-525 a').hoverAOP({imageName: 'perscription-drug-injury'});

$('#menu-item-520 a').hoverAOP({imageName: 'medical-malpractice'});

$('#menu-item-523 a').hoverAOP({imageName: 'motorcycle-accidents'});

$('#menu-item-526 a').hoverAOP({imageName: 'products-liability'});

$('#menu-item-521 a').hoverAOP({imageName: 'automobile-accidents'});

$('#menu-item-524 a').hoverAOP({imageName: 'nursing-home'});

$('#menu-item-527 a').hoverAOP({imageName: 'premises-liability'});

//--------------------------------------------------------------------------- Randomly loading banner ->>
//--------------------- Courtesy of http://www.robwalshonline.com/posts/jquery-plugin-random-image-on-page-load/ ->>

(function($){
	
	$.randomImage = {
		defaults: {
			
			//you can change these defaults to your own preferences.
			path: '/wp-content/themes/moyleslaw/img/banner-aop/', //change this to the path of your images
			myImages: ['tractor-trailer', 'personal-injury', 'perscription-drug-injury', 'medical-malpractice', 'motorcycle-accidents', 'products-liability', 'automobile-accidents', 'nursing-home', 'premises-liability'] //put image names in this bracket, minus banner- prefix and .jpg suffix.
			
		}			
	}
	
	$.fn.extend({
			randomImage:function(config) {
				
				var config = $.extend({}, $.randomImage.defaults, config); 
				
				 return this.each(function() {
						
						var imageNames = config.myImages;
						
						//get size of array, randomize a number from this
						// use this number as the array index

						var imageNamesSize = imageNames.length;

						var lotteryNumber = Math.floor(Math.random()*imageNamesSize);

						var winnerImage = imageNames[lotteryNumber];

						var fullPath = config.path + winnerImage + '.jpg';
						
						
						//put this image into DOM at class of randomImage
						// alt tag will be image filename.
						$(this).attr( {
										src: fullPath
									});
						$("#icon-" + winnerImage).addClass("current");
				
						
				});	
			}
			
	});
	
})(jQuery);

//--------------------------------------------------------------------------- Call randomly loading banner ->>
$('#aop-image').randomImage();
