// Main Page Functions;
$(function () {
	// case study resize initialize;

	$(".returnCase").fadeOut();
	$(".casewrapper").slideUp();
	$(".logo").css("opacity", .05);
	
	// case button background;
	var objCase = $("body").find(".caseButton");
	var objArray = $.makeArray(objCase);
	$.each(objArray, function(i) { 
		var caseIdenBG = $(".caseButton").eq(i).attr("panel");
		$(".caseButton").eq(i).css("background", "url(./pics/case/case-"+caseIdenBG+"-feature.jpg)");
	});
	


	// Show Case Study hover effect;
	$(".caseButton").hover(
	function () {
	$(".serviceType", this).stop().animate({ "padding-bottom": "6" }, 300);
	},
	function () {
	$(".serviceType", this).stop().animate({ "padding-bottom": "0" }, 300);
	});
			
	// Show Case Study on click;
	$(".caseButton").click(	function () {
		var caseIden = $(this).attr("panel");
		if (caseIden != null) { 
			var $thisExpand = $(".casewrapper["+caseIden+"]");
				$thisExpand.slideDown();			
				$(".returnCase", $thisExpand).fadeIn();
			$("#caseMenu").slideUp();
			window.location.hash = "#casestudies?"+caseIden;
		}
	});
	
	$(".returnCase").click( function () {
		window.location.hash = "#casestudies?main";
		clearAll();
		return false;
	});

	// Centers content
	centerIncr();
	$(window).resize(function() {
			centerIncr();		
	});

	
	// Highlights Selected Link;
	$("#buttonController").bind("click", function (e) {
	$("#buttonController").find("a").removeClass("buttonactive");
	$(e.target).closest("a").addClass("buttonactive");
    });
	
	//Fade Rollover;
	$("img.a").hover(
	function() {
	$(this).stop().animate({
	"opacity": "0"
	}, 200);
	},
	function() {
	$(this).stop().animate({
	"opacity": "1"
	}, 1200);
	});
	
	
	
	// Show Menu on click;
	$(".buttons").click(function () {
	$("#content").find(".link").removeClass("active");
	$("#menuarea").show("500", 'easeOutQuad');
	});

	// Menu Control;
	$("#menuarea").bind("click", function (e) {

		$("#menuarea").find(".link").removeClass("active");
		$(e.target).closest(".link").addClass("active");

    });
	$(".casebutton").click(function () {
		$(".casestudies").show("500", 'easeOutQuad');
		$(".casebutton").toggleClass("active");
		$(".home, .services, .people, .blog").hide();
		window.location.hash = "#casestudies?main";
		clearAll();
	});    
	$(".servbutton").click(function () {
		$(".services").show("500", 'easeOutQuad');
		$(".servbutton").toggleClass("active");
		$(".home, .casestudies, .people, .blog").hide();
		window.location.hash = "#services";
		clearAll();
	});
	$(".cghelp").click(function () {
		$("#content").find(".link").removeClass("active");
		$("#menuarea").show("500", 'easeOutQuad');
		$(".services").show("500", 'easeOutQuad');
		$(".servbutton").toggleClass("active");
		$(".home, .casestudies, .people, .blog").hide();
		clearAll();
		window.location.hash = "#services";
	}); 
	$(".peopbutton").click(function () {
		$(".people").show("500", 'easeOutQuad');
		$(".peopbutton").toggleClass("active");
		$(".home, .services, .casestudies, .blog").hide();
		window.location.hash = "#people";
		clearAll();
	}); 
	$(".blogbutton").click(function () {
		$(".blog").show("500", 'easeOutQuad');
		$(".blogbutton").toggleClass("active");
		$(".home, .services, .casestudies, .people").hide();
		window.location.hash = "#blog";
		clearAll();
	}); 
	$(".close").click(function () {
		$(".services, .casestudies, .people, #menuarea, .blog").hide();
		$("#content").find(".link").removeClass("active");
		$(".home").show("500");
		window.location.hash = "#home";
		clearAll();
	});
	
	// Expand people block;
			$(".bioBox").hoverIntent({
				over: makeTall, 
				timeout: 500, 
				out: makeShort
			});

		function makeTall(){  
			$("div.bioBody", this).show(800);
			$(".bioImage", this).stop().animate({
				"height":246
				},600, 'easeOutBack');
		}
		function makeShort(){ 
			$("div.bioBody", this).hide(600);
			$(".bioImage", this).stop().animate({"height":120},600, 'swing');
		}
		
	// Contact Area
	$(".contactlink").click(function () {
	var $contact = $('body').find("#location");
	$contact.show();
	$contact.animate({
		"height": "100%",
		"width": "100%",
		"left": "0",
		"top": "0"
		}, 200);
	});
	$("#location").click(function () {
	var $contact = $('body').find("#location");
	$contact.animate({
		"height": "0",
		"width": "0",
		"left": "50%",
		"top": "50%"
		}, 200, function(){
		$contact.hide();
		});
	});
	// tooltip
	$(".tooltiplink").click(function () {
	$(this).next(".tooltip").slideToggle("600", 'easeOutBack');
	});
	$(".tooltip").click(function () {
	$(this).slideToggle("600", 'easeInBack');
	});	
	// colorbox definitions
	$(".contactlink").colorbox({inline:true, href:"#contactwrapper"});
	$(".processlink").colorbox({inline:true, href:"#process"});
	
	//email handling
	var e2 = 'comgroup-inc';
	var e3 = '.com';
	var e3x = '?subject=Website';
	var e1 = 'info2012@';
	var e4 = e1+e2+e3;
	var e5 = 'mailto:';
	$(document).find('span.email').html('<a href='+e5+e4+e3x+'>'+'e-mail us'+'</a>');
	

	
	// escape handling
	$(document).keydown(handleEscape);
	function handleEscape(e){
		if (e.keyCode == 27){
		clearAll();
			}
		}
	
	
}); // close document.ready

