var index = 0;
var urlS3 = "http://public-assets.s3.amazonaws.com/";
var pathLogos = "images/logos_clients/";

var aFeatured = new Array();
aFeatured.push({url:"http://www.cookhousesf.com",urlImage:"http://public-assets.s3.amazonaws.com/images/cookhouse_logo_700x250.gif",caption:'<a href="{url}" target="_blank">Cookhouse, San Francisco CA</a> - Branding and Web Development'});
aFeatured.push({url:"http://www.vwlabs.com",urlImage:"http://public-assets.s3.amazonaws.com/images/vwlabs_nc_700x250.jpg",caption:'<a href="{url}" target="_blank">VWLabs.com</a> - Is this what the people want?'});
aFeatured.push({url:"http://www.midstateprecast.com",urlImage:"http://public-assets.s3.amazonaws.com/images/msp_branding.jpg",caption:'<a href="{url}" target="_blank">MidState Precast, Corcoran CA</a> - Branding and Web Development'});

var aClients = new Array();
aClients.push({name:"Bertelsmann Music Group",url:"http://	www.sonybmg.com",urlLogo:"logo_bmg_35.png"});
aClients.push({name:"Cookhouse",url:"http://www.cookhousesf.com",urlLogo:""});
aClients.push({name:"Cornell University",url:"http://www.cornell.edu",urlLogo:"logo_cornell_35.jpg"});
aClients.push({name:"Corsis",url:"http://www.corsis.com",urlLogo:""});
aClients.push({name:"Evite",url:"http://www.evite.com",urlLogo:"logo_evite_35.png"});
aClients.push({name:"Exponent",url:"http://www.exponent.com",urlLogo:""});
aClients.push({name:"Intertox",url:"http://www.intertox.com",urlLogo:""});
aClients.push({name:"iVillage.com",url:"http://www.ivillage.com",urlLogo:""});
aClients.push({name:"Kraft Foods",url:"http://www.kraft.com",urlLogo:"logo_kraft_35.png"});
aClients.push({name:"Kyphon",url:"http://www.kyphon.com",urlLogo:""});
aClients.push({name:"Loomis Industries",url:"http://www.loomisinc.com",urlLogo:""});
aClients.push({name:"McDonald's",url:"http://www.mcdonalds.com",urlLogo:"logo_mcd_35.png"});
aClients.push({name:"Microsoft",url:"http://www.microsoft.com",urlLogo:"logo_microsoft_35.png"});
aClients.push({name:"Mytrus",url:"http://www.mytrus.com",urlLogo:""});
aClients.push({name:"Noontide Filmworks",url:"http://www.noontidefilmworks.com",urlLogo:""});
aClients.push({name:"Pankow",url:"http://www.pankow.com",urlLogo:""});
aClients.push({name:"People Magazine",url:"http://www.people.com",urlLogo:"logo_people_35.png"});
aClients.push({name:"Plastic &amp; Reconstructive Surgeons",url:"http://www.prsurgeons.com",urlLogo:""});
aClients.push({name:"Priceline.com",url:"http://www.priceline.com",urlLogo:""});
aClients.push({name:"Promotions.com",url:"http://www.promotions.com",urlLogo:""});
aClients.push({name:"The Rockport Group",url:"http://www.therockportgroup.com",urlLogo:""});
aClients.push({name:"San Mateo Public Library",url:"http://www.cityofsanmateo.org/index.aspx?nid=507",urlLogo:""});
aClients.push({name:"Sparkfactor Design",url:"http://www.sparkfactordesign.com/",urlLogo:""});
aClients.push({name:"Synarc",url:"http://www.synarc.com/",urlLogo:""});
aClients.push({name:"UHMWPE Lexicon",url:"http://www.uhmwpe.org",urlLogo:""});
aClients.push({name:"Universal Music Group",url:"http://new.umusic.com/",urlLogo:"logo_universal_35.png"});
aClients.push({name:"Volkswagen",url:"http://www.vwerl.com",urlLogo:"logo_vw_35.png"});
aClients.push({name:"Watermark",url:"http://www.watermark-design.com/",urlLogo:""});
aClients.push({name:"WhittmanHart",url:"http://www.whittmanhart.com",urlLogo:""});
aClients.push({name:"Xenoport",url:"http://www.xenoport.com",urlLogo:""});
aClients.push({name:"Zuma Capital Partners",url:"",urlLogo:""});

$(document).ready(function() {
	buildSlideshow();
	
	$('#main-image').cycle({
		timeout: 5000,
		speed: 500,
		fx: 'fade',
		after: onAfter
	});
	
	buildClients();
});

function buildSlideshow() {
	aFeatured = randomize(aFeatured);
	var s = '';
	for (var i=0;i<aFeatured.length;i++) {
		s += '<a href="' + aFeatured[i].url + '" target="_blank"><img src="' + aFeatured[i].urlImage + '" width="700" height="250" border="0"/></a>';
	}
	$('#main-image').html(s);
}

function onAfter() {
	currentIndex = index % aFeatured.length;
	
	var pattern = /{url}/g;
	var caption = aFeatured[currentIndex].caption.replace(pattern,aFeatured[currentIndex].url);
	// Change caption
	$('#main-caption').html(caption);
	
	index++;
}

function buildClients() {
	var r = new String();

	// Build logos
	var aLogos = new Array();
	
	for (var i=0;i<aClients.length;i++) {
		if (aClients[i].urlLogo != "") {
			aLogos.push(aClients[i]);
		}
	}
	
	if (aLogos.length > 0) {
		//aLogos = randomize(aLogos);
		for (var j=0;j<aLogos.length;j++) {
			r += '<a href="' + aLogos[j].url + '" target="_blank"><img src="' + urlS3 + pathLogos + aLogos[j].urlLogo + '" border="0" /></a>'; //" width="{width}" height="{height}"
		}
		$('#clients1').html(r);
	}
	
	var s = new String();
	
	s += "<p>";
	
	var pre;
	var suf;
	
	for (i=0;i<aClients.length-1;i++) {
		pre = (aClients[i].url == "")?"":"<a class='subtle' href='" + aClients[i].url + "' target='_blank'>";
		suf = (aClients[i].url == "")?"":"</a>";
		
		s += pre + aClients[i].name + suf + ", ";
	}
	s += aClients[i].name + "</p>";
	
	s += '<p><img src="images/icon_arrow_red.gif" width="8" height="12" border="0" />&nbsp;<a href="http://pcd.basecamphq.com" target="_blank">Review the status of your project(s) here</a>.</p><p>';
	
	$('#clients2').html(s);
}

function randomize(a) {
	var aTemp = new Array();
	var k;
	while (a.length > 0) {
		k = Math.floor(Math.random()*a.length)
		aTemp.push(a.splice(k,1)[0]);
	}
	return aTemp;
}