$(function() {
	function strpos (haystack, needle, offset) {
		var i = (haystack+'').indexOf(needle, (offset || 0));
		return i === -1 ? false : i;
	}
	$('a.grouped_elements').fancybox({padding:0});
	$('.fancy').fancybox({padding:0});
	$('div.hero').cycle();
	$('.papa').cycle();
	//$('input[title!=""]').hint();
	//$('textarea[title!=""]').hint();
	
	$('.leader_info').css('display', 'none');
	
	function Footer_Height(content_name) {
		footer_height = (orig_doc_height - 380) - ($('#grad').height() + $('.' + content_name).height());
		if(footer_height <= 250) { footer_height = 250; }
		footer_pos = $('.' + content_name).height() + 150;
		$('#footer').css({'height': footer_height, 'top': footer_pos});
	}
	
	$('.leader_cont span.view').click(function() {
		$('.leader_info').stop(true, true);
		$('.leader_info').css('display', 'none');
		$('.leader_cont span.view').css('display', 'inline');
		$(this).parent('h3').siblings('.leader_info').slideDown('slow');
		Footer_Height('about_content');
		
	});
	
	$('#work_categories li a').mouseover(function() {
		$(this).stop().addClass($(this).attr('hover'));
	});
	
	$('#work_categories li a').mouseout(function() {
		$(this).removeClass($(this).attr('hover'));
	});
	
	$('#logo_categories li a').mouseover(function() {
		$(this).addClass($(this).attr('hover'));
	});
	
	$('#logo_categories li a').mouseout(function() {
		$(this).removeClass($(this).attr('hover'));
	});
	
	$('#logo_categories_s li a').mouseover(function() {
		$(this).addClass($(this).attr('hover'));
	});
	
	$('#logo_categories_s li a').mouseout(function() {
		$(this).removeClass($(this).attr('hover'));
	});
	
	
	
	function Team_In() {
		$('#meet_team img').stop(true, true);
		var orig = $(this).children('img').attr('src');
		var pos = strpos(orig, '.jpg', 0);
		var root = orig.substr(0, pos);
		thumb = root + '.jpg';
		var full = root + '_b.jpg';
		
		$(this).children('img').attr('src', full);
		$(this).parent('li').css('z-index', 5);
		$(this).children('img').css({'z-index' : 5});
		
		if($(this).children('img').attr('class') == 'dr') {
			$(this).animate({top:0, left:0, width: 146,height: 167}, 200);
		}
		else if($(this).children('img').attr('class') == 'dl') {
			$(this).animate({top:0, right:0, width: 146,height: 167}, 200);
		}
		else if($(this).children('img').attr('class') == 'ur') {
			$(this).animate({bottom:0, left:0, width: 146,height: 167}, 200);
		}
		else if($(this).children('img').attr('class') == 'ul') {
			$(this).animate({bottom:0, right:0, width: 146,height: 167}, 200);
		}
		
		
		$(this).children('img').animate({width: 146,height: 167}, 200, 'linear', function() {
			$(this).siblings('span').css({bottom:0, left:0}).slideDown('fast');
		});
	}
	
	function Team_Out() {
		$('#meet_team img').stop(true, true);
		$('#meet_team ul li').css('z-index', 1);
		$('#meet_team img').css({width : '69px', 'height' : '80px', 'z-index' : 1});
		$(this).css({'width' : '69px', 'height' : '80px'});
		$(this).children('img').attr('src', thumb);
		$(this).children('img').css({'width' : '69px', 'height' : '80px'});
		$(this).children('span').css('display', 'none');
	}
	
	$("#meet_team div").hoverIntent( Team_In, Team_Out );
	
	$('#meet_team').mouseout(function() {
		$('#meet_team img').css({width : '69px', 'height' : '80px', 'z-index' : 1});
	});
	
	$("ul#industries li").hoverIntent( Industries_In, Industries_Out );
	
	function Industries_In() {
		$('ul#industries li ul').stop(true, true);
		$(this).children('ul').slideDown('fast');
	}
	
	function Industries_Out() {
		$('ul#industries li ul').stop(true, true);
		$(this).children('ul').slideUp('fast');
		
	}
	
	$('p.view').click(function() {
		$(this).siblings('div.case_study').slideDown('slow');
		Footer_Height('about_content');
	});
	
	$('a.grouped_elements').mouseenter(function() {
		$('a.grouped_elements img').stop(true, true);
		$(this).append('<img src="/images/roll_red.png" class="roll" style="display:none;" />');
		$('img.roll', this).fadeIn(300);
	});
	
	$('a.grouped_elements').mouseleave(function() {
		$('img.roll', this).remove();
	});
	
});
