
/* 	Function: 	Enlarge an image when it is hovered over
	Author: 	Justin Farmer 
	Modified by Ryan Lepinski
*/

$(document).ready(function(){
	
	$('a.link').each(function() {
		
		
		var bHeight = $(this).children().attr('bHeight') *1;
		var sHeight = $(this).children().attr('sHeight') *1;

		if(this.href == window.location){
			$(this).children().addClass('active');
			var thesrc = $(this).children().attr('src');
			var name = thesrc.substring(0, thesrc.lastIndexOf('.') -3 );
			var extension = thesrc.substring(thesrc.lastIndexOf('.'));
		
			$(this).children().attr('src', name + "_lg" + extension )
				.css({
					paddingTop: 25-(bHeight-sHeight)+"px" ,
					width: $(this).children().attr('bWidth')+"px",
					height: bHeight + "px",
				})
		} else {

				$(this).children().css({
					paddingTop: 25 + "px" ,
					width: $(this).children().attr('sWidth')+"px",
					height: sHeight + "px",
				})
		}
		
	});
 

	//run a function when the image is hovered over
	$('img.resize')
		//mouseOver effect
		.hover(function(){
			if($(this).hasClass('active'))
				return true;
			//take the currently targeted img
			var thesrc = $(this).attr('src');
			var name = thesrc.substring(0, thesrc.lastIndexOf('.') -3 );
			var extension = thesrc.substring(thesrc.lastIndexOf('.'));
			var bHeight = $(this).attr('bHeight') *1;
			var sHeight = $(this).attr('sHeight') *1;
			 $(this).parent().addClass('active');
			$(this).attr('src', name + "_lg" + extension )
				//stops the event from happening in case of an abrupt mouseOut
				.stop()
				//custom animation effect to change the width and height of the img
				.animate({
					//take the original width/height X multipler and tag on the 'px'
					paddingTop: (25-(bHeight-sHeight))+"px" ,
					width: $(this).attr('bWidth')+"px",
					height: bHeight + "px",
				//space the animation out over 1 sec (deals in milliseconds)
				},100);

		},
		//this is just like a mouseOut effect to take the img back to the original size
		function(){
			if($(this).hasClass("active"))
				return true;
			var thesrc = $(this).attr('src');
			var name = thesrc.substring(0, thesrc.lastIndexOf('.')-3);
			var extension = thesrc.substring(thesrc.lastIndexOf('.'));
			$(this)
				//stops the event from happening in case of an abrupt mouseOut
				.stop()
				.animate({
					paddingTop: "25px",
					width: $(this).attr('sWidth')+"px",
					height: $(this).attr('sHeight')+"px"
				},100, function() {
						// Animation complete.
						$(this).attr('src', name + "_sm" + extension );
					});
		});

});

