
jQuery(document).ready(function() {

function randOrd(){
return (Math.round(Math.random())-0.5); }

carousel_data = [
    {
      name: "Gian Fulgoni",
      title: "Co-Founder",
      company: "comScore",
      company_link: "http://comscore.com",
	  bio: "Fulgoni"
    },
	{
      name: "Seth Sternberg",
      title: "Co-Founder",
      company: "Meebo",
      company_link: "http://meebo.com",
	  bio: "Sternberg"
    },
	{
      name: "J&#46;B&#46; Pritzker",
      title: "Founder",
      company: "New World Ventures",
      company_link: "http://www.newworldvc.com/",
	  bio: "Pritzker"
	},
	{
      name: "Jeremy Hanks",
      title: "Co-Founder",
      company: "Doba.com",
      company_link: "http://www.doba.com/",
	  bio: "Hanks"
    },
    {
      name: "Gurbaksh Chahal",
      title: "CEO",
      company: "Radium One",
      company_link: "http://www.radiumone.com/",
	  bio: "Chahal"
    },    
    {
      name: "Dave McClure",
      title: "Founding Partner",
      company: "500 Startups",
      company_link: "http://500startups.com/",
	  bio: "McClure"
    },    
    {
      name: "Jeff Lawson",
      title: "CEO",
      company: "Twilio",
      company_link: "http://www.twilio.com",
	  bio: "Lawson"
    },   
    {
      name: "Vivek Sodera",
      title: "Co-Founder",
      company: "Rapleaf",
      company_link: "https://www.rapleaf.com/",
	  bio: "Sodera"
    },    
    {
      name: "Mike Evans",
      title: "Co-Founder & COO",
      company: "GrubHub",
      company_link: "http://grubhub.com/",
	  bio: "Evans"
    },    
    {
      name: "Brian Fitzpatrick",
      title: "Head Engineer",
      company: "Google",
      company_link: "http://google.com/",
	  bio: "Fitzpatrick"
    },       

    {
      name: "Matt Maloney",
      title: "Co-Founder & CEO",
      company: "GrubHub",
      company_link: "http://grubhub.com/",
	  bio: "Maloney"
    },     
    {
      name: "Matt Moog",
      title: "Founder & CEO",
      company: "Viewpoints Network",
      company_link: "http://viewpoints.com/",
	  bio: "Moog"
    },   
    {
      name: "Tom Sosnoff",
      title: "Founder",
      company: "thinkorswim",
      company_link: "http://thinkorswim.com/",
	  bio: "Sosnoff"
    },   
        {
      name: "Craig Newmark",
      title: "Founder",
      company: "Craigslist",
      company_link: "http://craigslist.org/",
	  bio: "Newmark"
    },
	 {
      name: "Aneesh Chopra",
      title: "CTO",
      company: "United States",
      company_link: "http://www.whitehouse.gov/administration/eop/ostp/about/leadershipstaff/chopra",
	  bio: "Chopra"
    },
	{
      name: "Penelope Trunk",
      title: "Founder",
      company: "Brazen Careerist",
      company_link: "http://brazencareerist.com",
	  bio: "Trunk"
    },
	{
      name: "Jory Des Jardins",
      title: "Co-Founder",
      company: "BlogHer",
      company_link: "http://blogher.com",
	  bio: "Des"
    },
	{
      name: "Jason Fried",
      title: "Founder & CEO",
      company: "37signals",
      company_link: "http://37signals.com",
	  bio: "Fried"
    }
  ];
  
  carousel_data.sort(randOrd);
  
  
  
	
	elements = {
		name: "#carousel h3",
		title: "#carousel h4",
		company: "#carousel h5",
		image: "#carousel .image"
	};
	
	feedbox();
	
	
	jQuery("#carousel").html('<ul></ul>');
	
	for (i = 0; i < carousel_data.length; i++) {
		populate(i);
	}
	
  jQuery("#carousel-wrap").append('');	
  window.carouselLeft = 0;
  jQuery("#arrow-left").click(carousel_left);
  jQuery("#arrow-right").click(carousel_right);

  var bios = jQuery(".bio");
   
  if (bios.length > 0) {
    truncateBios(bios);
  }
});

function populate(i) {
	var v = carousel_data[i];
	var html = "<li>"+
	"<a href=\"/speakers/#" + (v.bio) + "\" class=\"image\" style=\"background-image: url(" + image_url(v.name) + "); text-decoration: none;\"></a>" +
	"<div class=\"caption\">" +
	"<h3>" + v.name + "</h3>" +
	"<h4>" + v.title + "</h4>" +	
	"<h5>" + v.company + "</h5>" +
	"</div>" +
	"</li>";
	
	jQuery("#carousel ul").append(html);
	
	
	return;
	
}

function image_url(string) {
	var server_prefix = "/wp-content/themes/techweek/headshotscolor/";
	var space_pos = string.indexOf(" ") + 1;
	if (string.indexOf(".") > -1) {
	  space_pos = string.indexOf(".") + 1;
	}
	var re = server_prefix + string.substr(0, 1).toLowerCase() + string.substring(space_pos).replace(/[,']/, "").toLowerCase() + ".jpg";
	return re.replace(/ /gi, '');
}

function carousel_left(evt) {
  if (window.carouselLeft == 0) {
    return false;
  }  
	jQuery("#carousel-wrap").animate({
		scrollLeft: window.carouselLeft -= 725
	},
	700,
	function() {
		//jQuery("#arrow-left").hide();
		//jQuery("#arrow-right").css('display', 'block');	
	}
	);
}
function carousel_right(evt) {
  if (window.carouselLeft >= (200 * 6)) {
    jQuery("#carousel-wrap").animate({
  		scrollLeft: 0
  	},
  	700,
  	function() {
  	//	jQuery("#arrow-right").hide();
  	//	jQuery("#arrow-left").css('display', 'block');	
  	}
  	);
  	window.carouselLeft = 0;
  	return;
  }
	jQuery("#carousel-wrap").animate({
		scrollLeft: window.carouselLeft += 725
	},
	700,
	function() {
	//	jQuery("#arrow-right").hide();
	//	jQuery("#arrow-left").css('display', 'block');	
	}
	);	
}

/* Feedbox */

function feedbox() 
{
  var $ = jQuery;
  var box = $("#feedbox");
  var blogfeed = $("#blogfeed");
}

/* Bio Truncation */
function truncateBios(bios) {
  var len = 240;
  jQuery(bios).each(function(i,v) {
    var trunc = jQuery(v).html();
    if (trunc.match(/<br( \/|)>/) !== null) {
      jQuery(v).data('original', trunc);
      //trunc = trunc.substring(0, len);
      trunc = trunc.replace(/\n/gi, '');
      trunc = trunc.replace(/<br( \/|)>.*$/, '');
      trunc += '<br><br><a href="javascript:void(0);" onclick="expandAll(this);">click for more &raquo;</a>';
      jQuery(v).html(trunc);
    }
  });
}

function expandAll(el) {
  var link = el;
  var span = jQuery(el).parents('.bio');
  jQuery(span).html(jQuery(span).data('original'));
}

