
var currClick;
var exp_admiss = new Array();
var exp_career = new Array();
var exp_profes = new Array();

var i=-1;
exp_admiss[++i] = {'name':'Pankaj Agarwal', 'quote':'<div class="top5bot2">"Wanna get into a top business school? Lets get started!"</div>', 'info':'Harvard MBA', 'id':952, 'widgetid':202};
exp_admiss[++i] = {'name':'Ronald Anguas',  'quote':'<div class="top3bot3">"I can help you get into Harvard"<br/>&nbsp</div>', 'info':'Admitted to 3 Harvard Programs', 'id':273, 'widgetid':203};
exp_admiss[++i] = {'name':'Peggy Hanefors', 'quote':'<div class="top3bot3">"Let my experience guide you"<br/>&nbsp</div>', 'info':'Former Ivy League Admissions Officer', 'id':347, 'widgetid':204};
exp_admiss[++i] = {'name':'Ryan Downer',    'quote':'<div class="top4bot3">"I can help you get into a top 5 law school"</div>', 'info':'Admitted to Harvard, Columbia et al.', 'id':873, 'widgetid':205};
exp_admiss[++i] = {'name':'Yuanxia Ding',	'quote':'<div class="top3bot3">"I specialize in MBA admissions"<br/>&nbsp</div>', 'info':'McKinsey and Wharton Alum', 'id':241, 'widgetid':206};
//exp_admiss[++i] = {'name':'', 'quote':'', 'info':'', 'id':, 'widgetid':};

i=-1;
exp_career[++i] = {'name':'<span style="font-size:11px;">Ben Schumacher</span>', 'quote':'<div class="top4bot3">"Let me teach you the art of interviewing a cut above"</div>', 'info':'Fmr Deloitte & Mc-<br/>Kinsey Consultant', 'id':381, 'widgetid':207};
exp_career[++i] = {'name':'Rebecca S.', 'quote':'<div class="top4bot3">"I can help you fulfill your career dreams"</div>', 'info':'Founder, Compass Career Strategies', 'id':833, 'widgetid':208};
exp_career[++i] = {'name':'<span style="font-size:11px;">Meredith Hodges</span>', 'quote':'<div class="top4bot3">"I&#39;ll help you land a high impact non-<br/>profit job"</div>', 'info':'Project Director at MoMA', 'id':407, 'widgetid':209};
exp_career[++i] = {'name':'Scott Hartley', 'quote':'<div class="top4bot3">"I&#39;m excited to help you get into venture capital"</div>', 'info':'Sand Hill Venture Capitalist', 'id':734, 'widgetid':210};
exp_career[++i] = {'name':'Patrick Lutfy', 'quote':'<div class="top4bot3">"Sharpen your case inter-<br/>viewing skills with me"</div>', 'info':'Five Years as a Consultant at BCG', 'id':492, 'widgetid':211};
exp_career[++i] = {'name':'Lisa	Sun',   'quote':'<div class="top4bot3">"Ace your Investment Banking or PE interview"</div>', 'info':'4 years at Goldman Sachs and TPG', 'id':640, 'widgetid':212};
exp_career[++i] = {'name':'Kate	Kohler', 'quote':'<div class="top4bot3">"I can teach you the finance inter-<br/>view drill"</div>', 'info':'Fmr Army Captain and iBanker', 'id':979, 'widgetid':213};
//exp_career[++i] = {'name':'Agustin Costa', 'quote':'<div class="top5bot2">"I can help you crack the consulting case interview"</div>', 'info':'Five Years at BCG', 'id':112, 'widgetid':};
exp_career[++i] = {'name':'John Hotard', 'quote':'<div class="top5bot2">"Let me help transform your career goals into reality"</div>', 'info':'Career Counselor', 'id':868, 'widgetid':214};
//exp_career[++i] = {'name':'', 'quote':'', 'info':'', 'id':, 'widgetid':};

i=-1;
exp_profes[++i] = {'name':'David Ronick',	'quote':'<div class="top4bot3">"I love help-<br/>ing build successful companies"</div>', 'info':'Co-founder at Upstart Bootcamp', 'img':'expert.png', 'id':771, 'widgetid':215};
exp_profes[++i] = {'name':'Justin Klosky',	'quote':'<div class="top4bot3">"I can help you get your business organized"</div>', 'info':'CEO of O.C.D. Experience', 'id':616, 'widgetid':216};
exp_profes[++i] = {'name':'Sean	Cameron',	'quote':'<div class="top5bot2">"Call me for insights into institutional investing"<br/>&nbsp</div>', 'info':'Professional Investor', 'id':134, 'widgetid':217};
exp_profes[++i] = {'name':'Mollie Chen',	'quote':'<div class="top4bot3">"I can give you a crash course in social media"</div>', 'info':'Chief Content Officer at Birchbox', 'id':276, 'widgetid':218};
exp_profes[++i] = {'name':'John	Johnson',	'quote':'<div class="top4bot3">"I can help small busi-<br/>nesses avoid IT mistakes"</div>', 'info':'IT Director, Practice Greenhealth', 'id':1023, 'widgetid':219};
exp_profes[++i] = {'name':'<span style="font-size:11px;">Richard Boadway</span>', 'quote':'<div class="top4bot3">"Need a trans-<br/>actions based IP & financing professional?"</div>', 'info':'VP, Patent Broker-<br/>age and Fmr CFO', 'id':748, 'widgetid':220};
exp_profes[++i] = {'name':'<span style="font-size:11px;">Michelle Edwards</span>','quote':'<div class="top4bot3">"Let me help you build a brand with a conscience"</div>', 'info':'Founder and CEO of Haughty, LLC', 'id':909, 'widgetid':221};
exp_profes[++i] = {'name':'Andrew Chen',	'quote':'<div class="top4bot3">"Ask me about starting a technology start-up"</div>', 'info':'VP Media/Tech, NYC Development Corp', 'id':783, 'widgetid':222};
//exp_profes[++i] = {'name':'', 'quote':'', 'info':'', 'id':, 'widgetid':};


function flipCatwalk(direction){

	if(direction == 'next')
		currClick++;
	if(direction == 'prev'){
		if(currClick == 0)
			currClick = Math.max(Math.max(exp_admiss.length, exp_career.length), exp_profes.length);
		else
			currClick--;
	}

	replaceExpert(exp_admiss[currClick%exp_admiss.length], '#admissCell');
	replaceExpert(exp_career[currClick%exp_career.length], '#careerCell');
	replaceExpert(exp_profes[currClick%exp_profes.length], '#profesCell');

}

function replaceExpert(expertJson, strCell){

	$(strCell+' .leftCell a').attr('href', '/widgets/dispatcher.php?referrerid=0&widgetid='+expertJson.widgetid+'&redirect='+encodeURIComponent('http://www.evisors.com/expert/'+expertJson.id));
	$(strCell+' .leftCell img').attr('src', '/asset/images/metapage/experts/'+expertJson.id+'.jpg');
	$(strCell+' .rightCell .expPitch').html(expertJson.quote);
	$(strCell+' .rightCell .expName').html(expertJson.name);
	$(strCell+' .rightCell .expInfo').html(expertJson.info);
	
}



$(document).ready(function(){

	dummyEmail = $("#emailTxt").val();

	currClick = Math.floor(Math.random()*Math.max(Math.max(exp_admiss.length, exp_career.length), exp_profes.length));
	flipCatwalk('');


	//Catwalk binds
	$('#flipLeft a').click(function(event){
		event.preventDefault();
		flipCatwalk('prev');
	});

	$('#flipRight a').click(function(event){
		event.preventDefault();
		flipCatwalk('next');
	});

	var brain = new Image(357,269);
	brain.src="/asset/images/metapage/brainplay_hover.png";

	//preload catwalk images.
	setTimeout(function(){
		var arrs = [exp_admiss, exp_career, exp_profes];
		for (var j=0; j<arrs.length; j++)
		    for (var i=0; i<arrs[j].length; i++){
			var im = new Image(76,126);
			if(undefined!=arrs[j][i].id && arrs[j][i].id>0)
			    im.src="/asset/images/metapage/experts/"+arrs[j][i].id+".jpg";
		    }
	 },1000);


	//tool tip
	$('#guarantee').qtip({
		content : 'End any phone consultation within 10mins and it will be fully refunded',
		position : {
			corner: { target: 'topLeft', tooltip: 'bottomLeft' }
		},
		style: { name: 'green' },
		show : "mouseover",
		hide : "mouseout"
	});


	//Email address disappearing act
	$("#emailTxt").focus(function(){
    	if($("#emailTxt").val()==dummyEmail)
    		$("#emailTxt").val("");
	});

	$("#emailTxt").blur(function(){
    	if($("#emailTxt").val()=="")
    		$("#emailTxt").val(dummyEmail);

	});

	$("#frmSearch").submit(function(){
		if($("#emailTxt").val()==dummyEmail)
			$("#emailTxt").val("");
	});



	//Quotation Rotation!
	$('#quote_circles a').bind('custom_qu', function(event, rotate){
		//update selected circle
		$('#quote_circles a > div').removeClass('selected');
		$(this).children('div').addClass('selected');

		//show quote
		$('#pressQuotes > div.pressQuote').hide();
		
		$($(this).attr('href')).fadeIn(1500)
		//stop timer if clicked, not if from rotate
		if(!rotate) clearInterval(timerId_quotes);
	});

	$('#quote_circles a').click(function(event){
		event.preventDefault();
		$(this).trigger('custom_qu', [false]);
	});

	var i = 1;
	var timerId_quotes = setInterval(function() {
		var id = '#q'+i;
		$(id).trigger('custom_qu', [true]);
		i = (i==$('#quote_circles a').length-1) ? 0 : i+1;
	}, 5000);

});



/**
 * Email capture.
 *
 */
$(document).ready(function(){

	//Set up the textarea with hint and content.
	var textareaText = "I need an expert to... \n- help me prep for my job interview with company x\n- help me with my application to school y\n- help me start my own company\n- give me insights into the oil & gas industry\n- help tutor me in Spanish";

	$("textarea#recruit_seeking").val(textareaText);
	$("textarea#question_seeking").val(textareaText);

	$("textarea#recruit_seeking,textarea#question_seeking").focus(function(){
		$(this).removeClass("greyText");
		if($(this).val() == textareaText) $(this).val("");
	});

	$("textarea#recruit_seeking,textarea#question_seeking").blur(function(){
		
		if($.trim($(this).val()) == ""){
			$(this).val(textareaText);
			$(this).addClass("greyText");
		}
	});
	/**
	 * Handle initial email submit.
	 *
	 */
	$("input#signup_button").click(function (event){

		$("#recruit_email").val( $("#emailTxt").val() );

		event.preventDefault();

		//Test that an email was given, and submit that email.
		var emailtest = $.trim($("#emailTxt").val());

		if(null==emailtest.match(/^\w(\+?\.?-?\w)*\-?@\w(\.?[\-\w])*\w\.[a-z]{2,4}$/))
			
			alert("Strange... that doesn't look like an email.");
		
		else if (emailtest=="name@email.com"){

			//do nothing.

		}else {
			
			$.ajax({
				url : "/recruit/",
				data : {
				    email : emailtest,
					source : "mainemail1"
				},
				method : "post",
				dataType : "json",
				complete : function(){

					$("#recruitContainer").dialog({
						modal : true,
						width : 400,
						height: 550,
						title : "Thanks!"
					});

				}

			});

		}	
	});


	/**
	 * Handle survey submit.
	 *
	 */
	$("form#recruit").submit(function (event){

		event.preventDefault();
		
		var flag = true;
						
		if($('ul.topics input:checked',this).length == 0){
			flag = false;
			alert('Please select at least one topic you\'re interested in.');
		}
		
		if(flag && ($.trim($('#recruit_seeking',this).val()) == '' || $.trim($('#recruit_seeking',this).val()) == textareaText)){
			flag = false;
			alert('Please describe the expertise you\'re looking for.');
		}
		
		if(flag){
		
			$("#recruitContainer").block("");

			$.ajax({
				url : "/recruit/",
				data : $("form#recruit").serialize(),
				method : "post",
				dataType : "json",
				complete : function(){

					$("#recruitContainer").unblock();
					$("#recruitContainer").html($("#recruitComplete").html());

				}
			});

		}
	});
	
	$("form#question").submit(function(event){
		event.preventDefault();
		
		var flag = true;
		
		var emailtest = $("input#question_email").val();
		
		if(null==emailtest.match(/^\w(\+?\.?-?\w)*\-?@\w(\.?[\-\w])*\w\.[a-z]{2,4}$/)){
			flag = false;
			alert("Strange... that doesn't look like an email.");
		
		}
		
		if(flag && $('ul.topics input:checked',this).length == 0){
			flag = false;
			alert('Please select at least one topic you\'re interested in.');
		}
		
		if(flag && ($.trim($('#question_seeking',this).val()) == '' || $.trim($('#question_seeking',this).val()) == textareaText)){
			flag = false;
			alert('Please describe the expertise you\'re looking for.');
		}
		
		if(flag){
			
			$("#questionContainer").block("");
	
			$.ajax({
				url : "/recruit/",
				data : $("form#question").serialize(),
				dataType : "json",
				method : "post",
				complete : function(){
	
					$("#questionContainer").unblock();
					$("#questionContainer").html($("#questionComplete").html());
	
				}
			});
		}
	});
	

	$("form#rfpRequest").submit(function(event){
		event.preventDefault();

		var emailtest = $("input#rfp_email").val();

		if(null==emailtest.match(/^\w(\+?\.?-?\w)*\-?@\w(\.?[\-\w])*\w\.[a-z]{2,4}$/)){
			alert("Please enter a valid email address.");
		}

		else if($.trim($('#rfp_title',this).val()).length < 4){
			alert('Please provide a title for your project.');
		}

		else if($('#rfp_category',this).val() < 0){
			alert('Please select a category that best describes the advice you seek.');
		}

		else if($.trim($('#rfp_details',this).val()).length < 10){
			alert('Please describe your project.');
		}

		else if($.trim($('#rfp_budget',this).val()).length < 2){
			alert('Please give a budget and currency.');
		}

		else if($.trim($('#rfp_deadline',this).val()) < 0){
			alert('Please select a deadline.');
		}

		else{
			$("#rfpContainer").block("");

			$.ajax({
				url : "/projects/formSubmit.php",
				data : $("form#rfpRequest").serialize(),
				dataType : "json",
				method : "post",
				complete : function(){
					$("#rfpContainer").unblock();
					$("#rfpContainer").html($("#questionComplete").html());
				}
			});
		}
	});


	$("a#questionActivate").click(function (event){
		
		event.preventDefault();
		
		$("#questionContainer").dialog({
			modal : true,
			width : 400,
			height: 490,
			method : "post",
			title : "Contact Us"
		});
		
	});

	$("a#rfpActivate").click(function (event){

		event.preventDefault();

		$("#rfpContainer").dialog({
			modal : true,
			width : 450,
			height: 540,
			method : "post",
			title : "Submit a Request"
		});

	});

	$("a#pophowto,a#watchhow").click(function (event){
		event.preventDefault();
			$("#howtovideo").dialog({
			modal : true,
			width: 670,
			height: 424,
			open: function() {
				$('#howtoiframe').attr('src', 'http://www.youtube.com/embed/_cz3_s3IFKc?autoplay=1&rel=0&amp;hd=1');
			},
			close: function() {
				$('#howtoiframe').attr('src', 'http://www.youtube.com/embed/_cz3_s3IFKc?autoplay=0&rel=0&amp;hd=1');
				var tempTxt = $('#howtovideo').html();
				$('#howtovideo').html(tempTxt);
			}
		});
	});

	//remove dotted outline for active image link in ie8
	if (document.documentElement.attachEvent)
    document.documentElement.attachEvent('onmousedown',function(){
         event.srcElement.hideFocus=true
    });
	
});

/**
 * End Email capture.
 *
 */
