function initDropdown() {
	var topnavOffset = -41;
	$('.topnav').each(function() {
		if(!$(this).hasClass('topnav-impl')) {
			var topnav = $(this);
			var topnavLi = $('li', topnav);
			topnavLi.each(function(topnavIndex) {
				var topnavItem = $(this);
				var topnavDrop = $('div.dropdown', topnavItem);
				var topnavDropUl = $('ul', topnavDrop);
				topnavDrop.addClass('show-drop');
				topnavDrop.css({
					width: parseInt(topnavDropUl.width()) + 55
				});
				topnavDrop.removeClass('show-drop');
				if(topnavDrop.length) {
					topnavDrop.css({
						left: parseInt(topnavItem.width())/2 + topnavOffset
					});
					if($.browser.msie) {
						topnavItem.hover(function() {
							$(this).addClass('hover');
						}, function() {
							$(this).removeClass('hover');
						});
						$('li', topnavDrop).eq(0).addClass('first-child');
					}
				}
			});
			topnav.addClass('topnav-impl');
		}
	});
}
function initStaffPromo() {
	var staffThumbAnimate = 200; // thumbs rollover animation speed
	var staffToggleTime = 400; // preload big images animation speed
	var staffSlideTime = 400; // thumbs carousel slide speed
	var staffCurrent = 'current'; // thumbs current className
	var staffPIcPrefix = 'staff_photo_id_'; // big images id prefix
	var staffStep = 18; // carousel slide step
	
	$('div.staff-presentation').each(function() {
		if(!$(this).hasClass('staff-impl')) {
			var staff = $(this);
			
			// quote
			var quote = $('div.employee-quote').eq(0);
			//var quotePos = $('div.page-width', quote);
			var quoteBlock = $('blockquote', quote);
			function quotePosition() {
			    return;
				quotePos.css({
					marginTop: - parseInt(quoteBlock.height())/2
				});
			}
			quotePosition();
			
			// skills
			// var skills = $('div.employee-skills').eq(0);
			
			// big image
			var staffImages = $('div.staff-image-holder').eq(0);
			
			// thumbs
			var staffCarousel = $('div.staff-promo-carousel', staff);
			var staffSlicer = $('div.slicer', staffCarousel);
			var staffNode = $('div.node', staffSlicer);
			var staffPane = $('div.pane', staffNode);
			var staffPaneCloneBefore = false;
			var staffPaneCloneAfter = false;
			var staffItem = $('div.item', staffPane);
			var staffItemLength = staffItem.length;
			var staffItemWidth = parseInt(staffItem.eq(0).outerWidth());
			if(parseInt(staffItem.eq(0).css('marginLeft'))) {
				staffItemWidth+=parseInt(staffItem.eq(0).css('marginLeft'));
			}
			if(staffItem.eq(0).css('marginRight')) {
				staffItemWidth+=parseInt(staffItem.eq(0).css('marginRight'));
			}
			var staffActive = staffItem.index(staffItem.filter('.' + staffCurrent).eq(0));
			if(staffActive==-1) {
				staffActive = 0;
				staffItem.eq(staffActive).addClass(staffCurrent);
			}
			var staffData = [];
			staffItem.each(function(i) {
				var staffIt = $(this);
				var staffDataItem = {};
				var staffItLink = $(' > a', staffIt);
				// var staffItSkills = $('div.skills', staffIt);
				var staffItQuote = $('div.quote', staffIt);
				if(staffItLink.length) {
					staffItLink.attr('rev', i);
					if(i==staffActive) {
						$('img', staffImages).eq(0).attr('id', staffPIcPrefix+staffActive);
						staffDataItem.image = '#' + staffPIcPrefix+staffActive;
						staffItLink.attr('href', staffDataItem.image);
					} else {
						staffDataItem.image = staffItLink.attr('href');
					}
				}
				/*
				if(staffItSkills.length) {
					staffDataItem.skills = staffItSkills.html();
				}
				*/
				if(staffItQuote.length) {
					staffDataItem.quote = staffItQuote.html();
				}
				staffData.push(staffDataItem);
			});
			// change active class
			function changeThumbs(activeThumb) {
				$('div.item', staffPane).each(function(i) {
					if(i==activeThumb) {
						$(this).addClass(staffCurrent);
					} else {
						$(this).removeClass(staffCurrent);
					}
				});
				if(staffPaneCloneBefore.length) {
					$('div.item', staffPaneCloneBefore).each(function(i) {
						if(i==activeThumb) {
							$(this).addClass(staffCurrent);
						} else {
							$(this).removeClass(staffCurrent);
						}
					});
				}
				if(staffPaneCloneAfter.length) {
					$('div.item', staffPaneCloneAfter).each(function(i) {
						if(i==activeThumb) {
							$(this).addClass(staffCurrent);
						} else {
							$(this).removeClass(staffCurrent);
						}
					});
				}
			}
			// carousel
			if(staffItem.length>19) {
				var staffCarouselAnimated = false;
				staffCarousel.addClass('staff-carousel-implemented');
				var staffLeft = $('a.promo-carousel-left', staffCarousel);
				var staffRight = $('a.promo-carousel-right', staffCarousel);
				staffPaneCloneBefore = staffPane.clone(true).insertBefore(staffPane);
				staffPaneCloneAfter = staffPane.clone(true).insertAfter(staffPane);
				staffNode.css({
					left: -staffItemWidth*staffItemLength
				});
				staffItem = $('div.item', staffNode);
				changeThumbs(staffActive);
				staffLeft.click(function() {
					if(!staffCarouselAnimated) {
						staffCarouselAnimated = true;
						if(parseInt(staffNode.css('left'))>-staffItemWidth*staffItemLength) {
							staffNode.css({
								left: parseInt(staffNode.css('left'))-staffItemWidth*staffItemLength
							});
						}
						staffNode.animate({
							left: '+=' + staffStep*staffItemWidth
						}, {
							duration: staffSlideTime,
							complete: function() {
								staffCarouselAnimated = false;
							}
						});
					}
					return false;
				});
				staffRight.click(function() {
					if(!staffCarouselAnimated) {
						staffCarouselAnimated = true;
						if(parseInt(staffNode.css('left'))<-staffItemWidth*staffItemLength) {
							staffNode.css({
								left: parseInt(staffNode.css('left'))+staffItemWidth*staffItemLength
							});
						}
						staffNode.animate({
							left: '-=' + staffStep*staffItemWidth
						}, {
							duration: staffSlideTime,
							complete: function() {
								staffCarouselAnimated = false;
							}
						});
					}
					return false;
				});
			}
			// click thumb
			$(' > a', staffItem).click(function() {
				var staffThumbClicked = $(this);
				if(!$(this).hasClass(staffCurrent)) {
					var activeIndex = $(this).attr('rev');
					if(staffData[activeIndex].image.indexOf('#')==-1) {
						// preload and change
						quoteBlock.fadeOut(staffToggleTime/2);
						// skills.fadeOut(staffToggleTime/2);
						staffImages.animate({
							opacity: 0
						}, {
							duration: staffToggleTime/2,
							complete: function() {
								var newEmployeePic = new Image();
								$(newEmployeePic)
									.load(function () {
										$('img', staffImages).hide();
										staffImages
											.append(this)
											.animate({
												opacity: 1
											}, {
												duration: staffToggleTime/2,
												complete: function() {
													if($.browser.msie) {
														staffImages.css({
															opacity: 'auto'
														});
													}
													staffData[activeIndex].image = '#' + staffPIcPrefix + activeIndex;
													staffThumbClicked.attr('href', staffData[activeIndex].image);
													quoteBlock
														.html(staffData[activeIndex].quote)
														.fadeIn(staffToggleTime/2);
													/*	
													skills
														.html(staffData[activeIndex].skills)
														.fadeIn(staffToggleTime/2);
													*/	
													changeThumbs(activeIndex);
													quotePosition();
												}
											});
									})
									.error(function () {})
									.attr('src', staffData[activeIndex].image)
									.attr('id', staffPIcPrefix + activeIndex);
							}
						});
					} else {
						// change
						quoteBlock.html(staffData[activeIndex].quote);
						
						// skills.html(staffData[activeIndex].skills);
						
						$('img', staffImages).hide();
						$(staffData[activeIndex].image).show();
						changeThumbs(activeIndex);
						quotePosition();
					}
				}
				return false;
			});
			staff.addClass('staff-impl');
		}
	});
}
/**
 * jQuery IE6 PNG fix
 * Copyright: htmlReligion Team
 * Version: 1.0.0 (2011-apr-21)
 * Requires: jQuery v1.3+
 * License: MIT (http://www.opensource.org/licenses/mit-license.php)
*/
(function($){var g=function(b,c){var d=b;var e=this;var f=$.extend({transparentImage:'transparent.gif'},c||{});e.replace=function(){var a=d.src;if(a.toLowerCase().indexOf('.png')!=-1){d.style.width=d.offsetWidth;d.style.height=d.offsetHeight;d.src=f.transparentImage;d.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+a+"',sizingMethod='scale')"}}()};$.fn.urPNG=function(c){return this.each(function(){var a=$(this);if(a.data('urPNG'))return;var b=new g(this,c);a.data('urPNG',b)})}})(jQuery);

function initPeople() {
	var peopleHoverSpeed = 150;
	
	$('div.people-item').each(function() {
		if(!$(this).hasClass('people-item-implemented')) {
			var peopleItem = $(this);
			var peopleItemWidth = parseInt(peopleItem.width());
			var peopleItemHeight = parseInt(peopleItem.height());
			var peopleBox = $('div.people-item-container', peopleItem);
			var peopleShadow = $('div.people-shadow', peopleItem);
			var peopleShadowC = $('div.c', peopleShadow);
			var peoplePic = $('img', peopleShadowC);
			var peoplePicWidth = parseInt(peoplePic.width());
			var peoplePicHeight = parseInt(peoplePic.height());
			var peopleL = $('i.l', peopleShadowC);
			var peopleR = $('i.r', peopleShadowC);
			peopleL.css({height: parseInt(peopleShadowC.height())-6});
			peopleR.css({height: parseInt(peopleShadowC.height())-6});
			peopleShadow.css({
				width: peoplePicWidth+14,
				marginLeft: -(peoplePicWidth+14)/2,
				marginTop: -(peoplePicHeight+14)/2
			});
			var peopleTxt = $('div.txt', peopleShadowC);
			var peopleTxtPos = parseInt($('div.txtbg', peopleTxt).outerHeight());
			peopleTxt.css({
				bottom: -peopleTxtPos
			});
			var peopleBoxMinWidth = parseInt(peopleBox.width());
			var peopleBoxMinHeight = parseInt(peopleBox.height());
			var peopleBoxMaxWidth = peoplePicWidth+14;
			var peopleBoxMaxHeight = peoplePicHeight+14;
			var peopleBoxMaxLeft = (peopleBoxMinWidth-peopleBoxMaxWidth)/2;
			var peopleBoxMaxTop = (peopleBoxMinHeight-peopleBoxMaxHeight)/2;
			
			peopleItem
				.mouseenter(function() {
					$(this).addClass('people-item-hover');
					peopleBox
						.stop()
						.animate({
							left: peopleBoxMaxLeft,
							top: peopleBoxMaxTop,
							width: peopleBoxMaxWidth,
							height: peopleBoxMaxHeight
						}, {
							duration: peopleHoverSpeed
						});
					peopleTxt
						.stop()
						.animate({
							bottom: -1
						}, {
							duration: peopleHoverSpeed
						});
				})
				.mouseleave(function() {
					var peopleItemObj = $(this);
					peopleBox
						.stop()
						.animate({
							left: 0,
							top: 0,
							width: peopleBoxMinWidth,
							height: peopleBoxMinHeight
						}, {
							duration: peopleHoverSpeed,
							complete: function() {
								peopleItemObj.removeClass('people-item-hover');
							}
						});
					peopleTxt
						.stop()
						.animate({
							bottom: -peopleTxtPos
						}, {
							duration: peopleHoverSpeed
						});
				});
			peopleItem.addClass('people-item-implemented');
		}
	});
}
function resetFooterIE() {
	var footer = $('div.footer');
	if($.browser.msie) {
		footer
			.css({
				position: 'static'
			})
			.css({
				position: 'absolute'
			});
	}
}
function initVacancy() {
	$('div.resume-list').each(function() {
		if(!$(this).hasClass('resume-list-implemented')) {
			var resumeList = $(this);
			var resumeListItem = $('div.resume-item', resumeList);
			var resumeListExpander = $('div.h-resume a', resumeListItem);
			resumeListItem.each(function(i) {
				if($('div.h-resume a', resumeListItem).length) {
					$(this).addClass('list-resume-item-link');
					$('div.resume-text-more', this).hide();
				}
			});
			resetFooterIE();
			var resumeListAnimated = false;
			resumeListExpander.click(function() {
				if(!resumeListAnimated) {
					var clickParent = $(this).parents('.resume-item').eq(0);
					clickParent.addClass('click-parent');
					resumeListAnimated = true;
					if(clickParent.hasClass('list-resume-item-link')) {
						resumeListItem.each(function() {
							var resumeListIt = $(this);
							if(resumeListIt.hasClass('click-parent')) {
								resumeListIt.removeClass('list-resume-item-link');
								$('div.resume-text-more', resumeListIt).slideDown(200, function() {
									resumeListIt.removeClass('click-parent');
									resetFooterIE();
								});
							} else {
								resumeListIt.addClass('list-resume-item-link');
								$('div.resume-text-more', resumeListIt).slideUp(200, function() {
									resumeListAnimated = false;
									resumeListIt.removeClass('click-parent');
								});
							}
						});
					} else {
						clickParent.addClass('list-resume-item-link');
						$('div.resume-text-more', clickParent).slideUp(200, function() {
							resumeListAnimated = false;
							clickParent.removeClass('click-parent');
							resetFooterIE();
						});
					}
				}
				return false;
			});
			
			resumeList.addClass('resume-list-implemented');
		}
	});
}

function memberHoverIE() {
	if($.browser.msie) {
		$('.num-member').hover(function() {
			$(this).addClass('num-member-hover');
		}, function() {
			$(this).removeClass('num-member-hover');
		});
	}
}
$(function() {
	initDropdown();
	initStaffPromo();
	initVacancy();
	memberHoverIE();

    var s = '';	
	
	$('table.special tr').each(function(){
	    var html = $(this).html();
        s = s + '<table><tr>'+html+'</tr></table>';
	});
	$('table.special').before(s);
	$('table.special').remove();
	
	
	
	
});

$(window).load(function() {
	initPeople();
});
