$().ready(function() {
	$('#careers-popup .close, #careers-popup-overlay').click(function() {
		$('#careers-popup').fadeOut('fast', function() {
			$('#careers-popup-overlay').fadeOut('slow'); 
		});
	});
	$('#whats-popup .close, #careers-popup-overlay').click(function() {
		$('#whats-popup').fadeOut('fast', function() {
			$('#careers-popup-overlay').fadeOut('slow'); 
		});
	});

	$('.careers-popup-button').click(function() {
		$index = parseInt($(this).attr('rel'), 10);			
		$data = $('#careers-popup-data').find('li').eq($index - 1).find('.lightbox-content').html();
		$popup = $('#careers-popup');
		$popup.find('.popup-middle').html($data);

		$i = 1;
		$popup.find('.navigation a').each(function() { this.index = $i; $i++; });
		$popup.find('.navigation a').click(function() {
				if ($(this).hasClass('apply')) return;
				$popup.find('.navigation a').removeClass('active');
				$(this).addClass('active');
				$items = $popup.find('.navigation-content-item');
				$items.hide();
				$items.eq(this.index - 1).fadeIn('slow');
		});
		
		$overlay = $('#careers-popup-overlay');
		$overlay.show();
		$overlay.fadeTo(0, 0);
		$overlay.fadeTo('fast', 0.8, function() {
			$popup.fadeIn('slow'); 
		});

		$(window).trigger('resize');
	});
	$('.whats-popup-button').click(function() {
		$index = parseInt($(this).attr('rel'), 10);			
		$data = $('#whats-popup-data').find('li').eq($index - 1).find('.lightbox-content').html();
		$popuptwo = $('#whats-popup');
		$popuptwo.find('.popup-middle').html($data);

		$i = 1;
		$popuptwo.find('.navigation a').each(function() { this.index = $i; $i++; });
		$popuptwo.find('.navigation a').click(function() {
				if ($(this).hasClass('apply')) return;
				$popuptwo.find('.navigation a').removeClass('active');
				$(this).addClass('active');
				$items = $popuptwo.find('.navigation-content-item');
				$items.hide();
				$items.eq(this.index - 1).fadeIn('slow');
		});
		
		$overlay = $('#careers-popup-overlay');
		$overlay.show();
		$overlay.fadeTo(0, 0);
		$overlay.fadeTo('fast', 0.8, function() {
			$popuptwo.fadeIn('slow'); 
		});

		$(window).trigger('resize');
	});


	$(window).bind('resize scroll', function() {
		if (!$.browser.msie || $.browser.version >= 7) return;

		//$offset = Math.round($(window).height() / 2) + $(window).scrollTop();

		$popup = $('#careers-popup');
		$popuptwo = $('#whats-popup');
		//$popup.css('top', $offset);
		//$popuptwo.css('top', $offset);
		$('#careers-popup-overlay').css('top', $(window).scrollTop());
	});
});
