// JavaScript Document

(function($) {
	$.fn.equalHeights = function() {
		var maxheight = 0;
		$(this).each(function(){
			maxheight = ($(this).height() > maxheight) ? $(this).height() : maxheight;
		});
		$(this).css('height', maxheight);
	}
})(jQuery);

$(document).ready(function() {

	$('body').addClass('js');

	if ($('.home .myslider').length > 0) {
	
		var imgs = [];
		$('.home .myslider div img').each(function (index) {
			var i = new Image();
			i.onload = function () {
				var h = i.height;
				var w = i.width;
				imgs[index] = [w, h];
				$(window).trigger('resize');
			}
			i.src = $(this).attr('src');
		});

		
		$(window).resize(function () {
			
			var height = $(window).height() - ($('.header').outerHeight());

			var width = $('.home').width();
			$('.home .myslider').height(height);
			
			$('.home .myslider').css({
				'width': width,
				'height': height
			});
			
			$('.home .myslider img').each(function (index) {
				var self = this;
				
				if (imgs[index] && imgs[index].length === 2) {
					var w = imgs[index][0];
					var h = imgs[index][1];
					
					if ((height/width) > (h/w)) {
						$(self).css({
							'width': (w/h) * height,
							'height': height
						});
						
					} else {
						$(self).css({
							'width': width,
							'height': (h/w) * width
						});
					}
				}
				
				
			});
			
		}).trigger('resize');
	}
	
});


