
jQuery(document).ready(function() {
carousel_data = [
    {
      name: "Brad Keywell",
      title: "Director, Co-Founder",
      company: "Groupon",
      company_link: "http://groupon.com"
    },
    {
      name: "Steve Huffman",
      title: "Co-Founder",
      company: "Reddit, Hipmunk",
      company_link: "http://www.reddit.com/"
    },    
    {
      name: "Scott A. Jones",
      title: "Founder & CEO",
      company: "ChaCha",
      company_link: "http://chacha.com/"
    },    
    {
      name: "Jim Dugan",
      title: "CEO, Co-Founder",
      company: "OCA Ventures",
      company_link: "http://ocaventures.com/"
    },    
    {
      name: "Ellen Carnahan",
      title: "Principal",
      company: "Machrie Enterprises",
      company_link: "#"
    },
    {
      name: "Kevin Willer",
      title: "Head of Technology",
      company: "Google",
      company_link: "http://google.com"
    },
    {
      name: "Genevieve Thiers",
      title: "Founder",
      company: "Sittercity.com",
      company_link: "http://uchicago.edu"
    },    
    {
      name: "Steven Kaplan",
      title: "Faculty Director",
      company: "Booth School of Business",
      company_link: "http://uchicago.edu"
    },    
    {
      name: "Adam Koopersmith",
      title: "Partner",
      company: "New World Ventures",
      company_link: "http://www.newworldvc.com/"
    },
    {
      name: "David K. Michaels",
      title: "VP Engineering",
      company: "Mint.com",
      company_link: "http://mint.com"
    },        
    {
      name: "Zee Kane",
      title: "Editor-in-Chief",
      company: "TheNextWeb",
      company_link: "http://thenextweb.com"
    },        
    {
      name: "Charley Cassell",
      title: "CFO",
      company: "Vibes Media",
      company_link: "http://www.vibes.com/"
    },    
    {
      name: "Rob Schultz",
      title: "Managing Director",
      company: "illinoisVENTURES",
      company_link: "http://www.illinoisventures.com/"
    },    
    {
      name: "Chuck Templeton",
      title: "Founder",
      company: "OpenTable",
      company_link: "http://www.opentable.com"
    },    
    {
      name: "Eric Lunt",
      title: "CTO",
      company: "BrightTag",
      company_link: "http://thebrighttag.com"
    },    
    {
      name: "Mark Walsh",
      title: "Founder",
      company: "GeniusRocket.com",
      company_link: "http://www.geniusrocket.com"
    }  ,    
      {
        name: "Sam Yagan",
        title: "Founder",
        company: "OKCupid.com",
        company_link: "http://www.okcupid.com"
      }
     ,    
     {
       name: "Shawn Bercuson",
       title: "Principal",
       company: "Lightbank",
       company_link: "http://www.lightbank.com"
     },
      {
        name: "Adam Coomes",
        title: "President",
        company: "Infegy",
        company_link: "http://www.infegy.com"
      },
      {
        name: "Adam Goldstein",
        title: "Co-Founder",
        company: "Hipmunk",
        company_link: "http://www.hipmunk.com"
      },
      {
        name: "Brian Gorbett",
        title: "Architect",
        company: "Microsoft",
        company_link: "http://www.microsoft.com"
      },
      {
        name: "Fred Hoch",
        title: "President",
        company: "Ill. Tech. Association",
        company_link: "http://www.illinoistech.org"
      },
      {
        name: "Ross Kimbarovsky",
        title: "Co-Founder",
        company: "crowdSPRING",
        company_link: "http://www.crowdspring.org"
      },          
      {
        name: "Jeff Leitner",
        title: "Senior Strategist",
        company: "Manifest Digital",
        company_link: "http://www.manifestdigital.com"
      },     
      /*{
        name: "Sean Corbett",
        title: "Founder",
        company: "HaveMyShift",
        company_link: "http://www.havemyshift.com"
      },    */
      {
        name: "Brenden Mulligan",
        title: "VP Strategic Devel",
        company: "Sonicbids",
        company_link: "http://www.sonicbids.com"
      },    
      {
        name: "Adam Siegel",
        title: "Founder",
        company: "InklingMarkets",
        company_link: "http://www.inklingmarkets.com"
      },      
      {
        name: "Desiree Vargas",
        title: "President &amp; Founder",
        company: "GiveForward",
        company_link: "http://www.giveforward.com"
      },    
      {
        name: "Mark Wilson",
        title: "Contributor",
        company: "Gizmodo",
        company_link: "http://www.gizmodo.com"
      }   
      ,    
      /*{
        name: "Barbara Goodman",
        title: "Executive Director",
        company: "iBIO",
        company_link: "http://www.ibio.org"
      }      
      ,   */ 
      {
        name: "Joe Banks",
        title: "Senior Consultant",
        company: "Obtiva",
        company_link: "http://obtiva.com"
      }   
      ,
      {
        name: "Thomas Cushing",
        title: "Frmr. Senior VP",
        company: "Chicago Climate Exchng",
        company_link: "http://chicagoclimatex.com"
      }   
      ,      
      {
        name: "Amy Francetic",
        title: "Executive Director",
        company: "Clean Energy Trust",
        company_link: "http://www.cleanenergytrust.org"
      }   
      ,      
      {
        name: "Devin Gross",
        title: "CEO",
        company: "Emmi Solutions",
        company_link: "http://www.emmisolutions.com"
      }   
      ,    
      {
        name: "Janet Huber",
        title: "Founder, CEO",
        company: "HealthCodex",
        company_link: "http://www.healthcodex.com"
      }    
      ,  
      {
        name: "James Hussey",
        title: "CEO",
        company: "NanoInk",
        company_link: "http://www.nanoink.net"
      }    
      ,
      {
        name: "Seth Kravitz",
        title: "Founder",
        company: "InsuranceAgents.com",
        company_link: "http://www.insuranceagents.com"
      }    
      ,              
      {
        name: "Tom Lee",
        title: "Founder &amp; CEO",
        company: "SA Ignite",
        company_link: "http://www.saignite.com"
      }            
      ,
      {
        name: "Justin Massa",
        title: "Director of Project Dev",
        company: "Metro Chicago Info Ctr",
        company_link: "http://www.mcic.org"
      }            
      ,          
      {
        name: "Daniel X. O'Neil",
        title: "Co-Founder",
        company: "Everyblock",
        company_link: "http://www.everyblock.com"
      }            
      ,          
      {
        name: "Jonathan Pasky",
        title: "Founder & Principal",
        company: "PaskyIP",
        company_link: "http://www.paskyip.com"
      }      
      ,          
      {
        name: "Julian Pretto",
        title: "Founder &amp; President",
        company: "ChicagoMicro",
        company_link: "http://www.chicagomicro.com"
      }      
      ,          
      {
        name: "Sarah Reedy",
        title: "Senior Reporter",
        company: "LightReading",
        company_link: "http://www.chicagomicro.com"
      }      
      ,          
      {
        name: "Chirag Patel",
        title: "Co-Founder/Senior VP",
        company: "Halo Monitoring",
        company_link: "http://www.halomonitoring.com"
      }  
      ,    
      {
        name: "Sunir Shah",
        title: "Chief Handshaker",
        company: "FreshBooks",
        company_link: "http://www.freshbooks.com"
      }
      ,    
      {
        name: "Rishi Shah",
        title: "CEO",
        company: "ContextMedia",
        company_link: "http://www.contextmediainc.com"
      }
      ,    
      {
        name: "Kevin Taylor",
        title: "President & Founder",
        company: "Obtiva",
        company_link: "http://www.obtiva.com"
      }
      ,    
      {
        name: "John Tolva",
        title: "Citizenship & Tech",
        company: "IBM Corporation",
        company_link: "http://www.ibm.com"
      }        
      ,    
      {
        name: "Jake Trussell",
        title: "Creative Director",
        company: "World Business Chicago",
        company_link: "http://www.worldbusinesschicago.com"
      }   
      ,    
      {
        name: "Todd Webb",
        title: "Dir. of Client Services",
        company: "Obtiva",
        company_link: "http://www.obtiva.com"
      },
      {
      name: "Ted Widen",
      title: "Founder & Publisher",
      company: "Chicago Scene",
      company_link: "http://chicago-scene.com"
    }

  ];
	
	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>"+
	"<div class=\"caption\">" +
	"<h3>" + v.name + "</h3>" +
	"<h4>" + v.title + "</h4>" +	
	"<h5>" + v.company + "</h5>" +
	"</div>" +
	"<a href=\"/speakers-panelists\" class=\"image\" style=\"background-image: url(" + image_url(v.name) + "); text-decoration: none;\"></a>" +
	"</li>";
	
	jQuery("#carousel ul").append(html);
	
	
	return;
	
}

function image_url(string) {
	var server_prefix = "http://midventureslaunch.com/img/";
	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 -= 645
	},
	700,
	function() {
		//jQuery("#arrow-left").hide();
		//jQuery("#arrow-right").css('display', 'block');	
	}
	);
}
function carousel_right(evt) {
  if (window.carouselLeft >= (645 * 7)) {
    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 += 645
	},
	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'));
}
