/* 
 * Левитация приборов и выравнивание списка приборов
 * по одной границе
 *
 * @author Alexeenko Igor (o0@artgorbunov.ru)
 * @requires jQuery (www.jquery.com)
 */

$().ready(function() {
	// Левитация приборов
	$('div.device a').hover(
		function() {
			$(this).find('img.device').stop().animate({ bottom:10 }, 'normal');
			$(this).find('img.shadow').stop().animate({ opacity:0 }, 'normal');
			$(this).find('img.shadow-1').stop().animate({ opacity:1 }, 'normal');
		},
		function() {
			$(this).find('img.device').stop().animate({ bottom:0 }, 'normal');
			$(this).find('img.shadow').stop().animate({ opacity:1 }, 'normal');
			$(this).find('img.shadow-1').stop().animate({ opacity:0 }, 'normal');
		}
	);

	// Выравнивание списка приборов
	$('.devices_large li').css('vertical-align', 'top');
	
	function align() {
		var obj;
		var offset = {};
		
		if ($('ul.devices_large').get(0)) {
			var elements = $('ul.devices_large').get(0).getElementsByTagName('li');
			
			for (i = 0, l = elements.length - 1 ; i < l ; i++) {
				if (!((current_offset = elements[i].offsetTop) in offset)) {
					offset[current_offset] = {
						height : 0,
						objects : []
					};
				}
				
				offset[current_offset].objects.push(obj = elements[i].getElementsByTagName('img')[0]);
				offset[current_offset].height = (typeof obj != 'undefined' && (ch = obj.clientHeight) > offset[current_offset].height) ? ch : offset[current_offset].height;
			}
			
			for (so in offset) {
				for (i = 0, l = offset[so].objects.length ; i < l ; i++) {
					$(offset[so].objects[i]).parent().parent().css('padding-top', offset[so].height - offset[so].objects[i].height);
				}
			}
		}
	}
	
	align();
	window.onresize = align;
	
	// Подсветка ссылкок
	$('.devices_large li img').hover(
		function() { $(this).parent().parent().find('a').css('color', 'red'); },
		function() { $(this).parent().parent().find('a').css('color', '#604080'); }
	);
	
	$('.devices_large a').hover(
		function() { $(this).css('color', 'red') },
		function() { $(this).css('color', '#604080') }
	);
});
