try {
if (!cllc.exists) { throw "cllcObjUndefined"; }

cllc.social = {
	
	/***** Social media site IDs / links *****/
	config: {
		flickr : {
			jeep : "52240685006@N01",
			dodge : null,
			chrysler : "77757594@N00",
			ram : "1288957@N21",
			chryslerllc : null,
			mopar : null
		},
		youtube : {
			jeep : "thejeepchannel",
			dodge : "dodge",
			chrysler : "chrysler",
			ram : "ram",
			chryslerllc : null,
			mopar : null
		},
		twitter : {
			jeep : "jeep",
			dodge : "dodgeautos",
			chrysler : null,
			ram : "ramtrucks",
			chryslerllc : "chrysler",
			mopar : null
		},
		facebook : {
			jeep : "jeep",
			dodge : "dodge",
			chrysler : "chrysler",
			ram : "ramtrucks",
			chryslerllc : "chryslercommunitcations",
			mopar : null
		},
		blog : {
			jeep : {
				name : null,
				url : null,
				numArticles : 0
			},
			dodge : {
				name : "Red Letter Dodge",
				url : "http://feeds.feedburner.com/RedLetterDodge?format=xml",
				homeUrl : "http://www.redletterdodge.com",
				numArticles : 3
			},
			chrysler : {
				name : null,
				url : null,
				numArticles : 0
			},
			ram : {
				name : "Ram Zone",
				url : "http://feeds.feedburner.com/RamZone?format=xml",
				homeUrl : "http://www.ramzone.com",
				numArticles : 3
			},
			chryslerllc : {
				name : "Chrysler Group LLC",
				url : "http://blog.chryslergroupllc.com",
				homeUrl : "http://blog.chryslergroupllc.com",
				numArticles : 0
			},
			mopar : {
				name : null,
				url : null,
				numArticles : 0
			}
		}
	},

	init: function() {
		/***** Are we on the Our Brands page? *****/
		var currPage = "home";
		if(location.href.lastIndexOf('/') != -1){
			var firstPos = location.href.lastIndexOf('/') + 1;
			var lastPos = location.href.length;
			currPage = location.href.substring(firstPos, lastPos);
		}
		if(currPage == "brands"){
			$('.expando').each(function(){
				var links = new Array('Flickr', 'YouTube', 'Twitter', 'Facebook', 'blog');
				var hrefs = new Array();
					hrefs.flickr = 'http://www.flickr.com/groups/';
					hrefs.youtube = 'http://www.youtube.com/';
					hrefs.twitter = 'http://www.twitter.com/';
					hrefs.facebook = 'http://www.facebook.com/';
					
				/***** Which brand is this? *****/
				var divId = $(this).attr('id');
				var idSplit = divId.split('_');
				var brand = idSplit[1];
				
				/***** Detect mouse events *****/
				$(this).find('#expando_social_'+brand).mouseenter(function(){
					$('#expando_'+brand).css('z-index','2');
					$('#expando_social_'+brand+' ul').slideDown('fast');
				})
				.mouseleave(function(){
					$('#expando_'+brand).css('z-index','1');
					$('#expando_social_'+brand+' ul').slideUp('fast');
				});
				
				/***** Construct links to social sites *****/
				for(var i=0, len=links.length; media=links[i], i<len; i++){
					var socSite = media.toLowerCase();
					var val = cllc.social.config[socSite][brand];
					
					/***** Is this a blog site? *****/
					if(socSite == 'blog' && brand != "mopar" && brand != "gem"){
						if(val.name != null && val.homeUrl != null){
							var blogName = val.name;
							var blogUrl = val.homeUrl;
							var exitLink = 'javascript:flexWin(&quot;/exit?tname=blog_'+brand+'&exitMsg=yes&dynamicUrl='+blogUrl+'&quot;,&quot;yes&quot;,&quot;1024&quot;,&quot;768&quot;,&quot;blog_'+brand+'&quot;,&quot;all&quot;)';
							$(this).find('ul.links li.first ul').append('<li><a name="&lpos='+brand+'_content&lid=blog" href="'+exitLink+'" class="blog">'+blogName+' Blog</a></li>');
						}
					
					/***** All other sites *****/
					} else {
						if(cllc.social.config[socSite][brand] != null){
							var exitLink = 'javascript:flexWin(&quot;/exit?tname='+socSite+'_'+brand+'&exitMsg=yes&dynamicUrl='+hrefs[socSite]+cllc.social.config[socSite][brand]+'&quot;,&quot;yes&quot;,&quot;1024&quot;,&quot;768&quot;,&quot;'+socSite+'_'+brand+'&quot;,&quot;all&quot;)';
							$(this).find('ul.links li.first ul').append('<li><a name="&lpos='+brand+'_content&lid='+socSite+'" href="'+exitLink+'" class="'+socSite+'">'+media+'</a></li>');
						}
					}
				}
			});
			
		/***** We're on the homepage *****/
		} else if(currPage = "home") {
	
			/***** Hide any visible panels when the brand is switched *****/
			$('#brand_names li').click(function(){
				$("#brand_social div").not(":hidden").each(function(){
					$(this).find('div div').hide();
					$(this).slideUp('fast');
				});
			});
			
			/***** Flickr *****/
			$.each(cllc.social.config.flickr, function(brn,v){
				if(v != null){
					$('#social_'+brn).append('<div class="flickr"><h3>Latest Flickr</h3><div class="images loading"><p>Loading...</p></div></div>');
					$('#'+brn+'-social').append('<span class="flickr">Flickr</span>');
				}
			});
			
			/***** Twitter *****/
			$.each(cllc.social.config.twitter, function(brn,v){
				if(v != null){
					$('#social_'+brn).append('<div class="twitter"><h3>Latest Tweet</h3><div class="content loading"><p>Loading...</p></div></div>');
					$('#'+brn+'-social').append('<span class="twitter">Twitter</span>');
				}
			});
			
			/***** Facebook *****/
			$.each(cllc.social.config.facebook, function(brn,v){
				if(v != null){
					var link = 'http://www.facebook.com/'+v;
					var exitLink = cllc.social.makeLink(brn, 'facebook', link);
					$('#social_'+brn).append('<div class="facebook"><h3>Latest Facebook Update</h3>' +
						'<a name="&lpos='+brand+'_community&lid=facebook" href="'+exitLink+'"><img src="/img/homepage/fb_'+brn+'.jpg" /></a> ' +
						'<p><a name="&lpos='+brand+'_community&lid=facebook" href="'+exitLink+'">Find us on<br />Facebook</a></p></div>');
					$('#'+brn+'-social').append('<span class="facebook">Facebook</span>');
				}
			});
			
			/***** YouTube *****/
			$.each(cllc.social.config.youtube, function(brn,v){
				if(v != null){
					$('#social_'+brn).append('<div class="youtube"><h3>Latest YouTube</h3><div class="content loading"><p>Loading...</p></div></div>');
					$('#'+brn+'-social').append('<span class="youtube">YouTube</span>');
				}
			});
			
			/***** Blog sites *****/
			$.each(cllc.social.config.blog, function(brn,values){
				if((values.name != null) && (values.url != null)){
					var contents = $('#social_'+brn).html();
					$('#social_'+brn).html('<div class="twocol">'+contents+'</div>');
					$('#social_'+brn).append('<div class="blog"><h3>'+values.name+'</h3><div class="content loading"><p>Loading...</p></div></div>');
					$('#'+brn+'-social').append('<span class="blog">Blog</span>');
				}
			});
			
			/***** Detect mouse events *****/
			$(".social").not("#mopar-social").mouseenter(function(){
				$(this).addClass('active');
			})
			.mouseleave(function(){	
				$(this).removeClass('active');
			})
			.click(function(){
				var brand = $(this).parents().attr('class').replace('brand_content ','');
				var showContents = $("#social_"+brand).is(":hidden");
				$("#social_"+brand).slideToggle('fast');
					cllc.social.get_feeds(brand);
			});
		}
	},
	
	get_feeds: function(brand) {
		/***** If an ID doesn't exist for a site, hide it *****/
		if(cllc.social.config.flickr[brand]===null) $('#social_'+brand+' .flickr').hide();
			else {
				cllc.social.flickr(brand);
				cllc.social.clearLoaders(brand);
			}
		if(cllc.social.config.youtube[brand]===null) $('#social_'+brand+' .youtube').hide();
			else {
				cllc.social.youtube(brand);
				cllc.social.clearLoaders(brand);
			}
		if(cllc.social.config.twitter[brand]===null) $('#social_'+brand+' .twitter').hide();
			else {
				cllc.social.twitter(brand);
				cllc.social.clearLoaders(brand);
			}
		if(cllc.social.config.facebook[brand]===null) $('#social_'+brand+' .facebook').hide();
			else $('#social_'+brand+' .facebook').show();
		if(cllc.social.config.blog[brand].name == null || cllc.social.config.blog[brand].url == null) $('#social_'+brand+' .blog').hide();
			else {
				cllc.social.blog(brand);
				cllc.social.clearLoaders(brand);
			}
	},
	
	clearLoaders: function(brand){
		/***** Don't want to look at loading text all day... *****/
		setTimeout(function(){ $('#social_'+brand+' div .loading').each(function(){ $(this).parent().hide(); }); }, 8000);
	},
	
	makeLink: function(brand, target, url, showMsg){
		url = url.replace('?','%3F').replace('=','%3D');
		
		/***** Construct links to exit page *****/
		showMsg = (showMsg?showMsg:'false');
		var tname = target+'_'+brand;
		return 'javascript:flexWin(&quot;/exit?tname='+tname+'&exitMsg=yes&dynamicUrl='+url+'&quot;,&quot;yes&quot;,&quot;1024&quot;,&quot;768&quot;,&quot;'+tname+'&quot;,&quot;all&quot;)';
	},
	
	blog: function(brand) {
		var parentDiv = '#social_'+brand+' .blog';
		$(parentDiv+', '+parentDiv+' *').show();
		if($(parentDiv+' .content').html().toLowerCase() == "<p>loading...</p>"){
			var contents = ""
			var numToPull = cllc.social.config.blog[brand].numArticles;
			if(numToPull > 0){
				/***** Let's get some articles *****/
				$.get('shared/includes/proxy.php?url='+cllc.social.config.blog[brand].url, function(d){
					$('#social_'+brand+' .blog .content').empty().removeClass('loading');
					if(typeof(d) != "undefined"){
						for(var i = 0; i <= (numToPull - 1); i++){
							$(d).find('item:eq('+i+')').each(function(){
								var $item = $(this);
								var title = $item.find('title').text();
								var link = $item.find('link').text();
								var text = $item.find('description').text();
								var exitLink = cllc.social.makeLink(brand, 'blog', link);
								contents = '<h4>'+title+'</h4><p>'+text+' '+'<a name="&lpos='+brand+'_community&lid=blog" href="'+exitLink+'">more &#187;</a></p>';
								$('#social_'+brand+' .blog .content').append(contents);
							});
						}
					}
				});
			} else {
				/***** Just provide link to blog site *****/
				$('#social_'+brand+' .blog .content')
					.html('<a name="&lpos='+brand+'_community&lid=blog" href="'+cllc.social.config.blog[brand].url+'">Visit our blog site</a>')
					.removeClass('loading');
			}
		}
	},
	
	flickr: function(brand) {
		$('#social_'+brand+' .flickr').show();
		if($('#social_'+brand+' .flickr .images').html().toLowerCase() == "<p>loading...</p>"){
			$.getJSON("http://api.flickr.com/services/feeds/groups_pool.gne?id="+cllc.social.config.flickr[brand]+"&lang=en-us&format=json&jsoncallback=?", function(data){
			//$.get("http://api.flickr.com/services/feeds/groups_pool.gne?id="+cllc.social.config.flickr[brand]+"&lang=en-us&format=json&jsoncallback=?", function(data){
				$('#social_'+brand+' .flickr .images').empty().removeClass('loading');
				$.each(data.items, function(i,item){
					if(i==3) return false;
					var exitLink = cllc.social.makeLink(brand, 'flickr', item.link);
					$("<img/>").attr("src", item.media.m).appendTo("#social_"+brand+" .flickr .images")
					.wrap("<a name='&lpos="+brand+"_community&lid=flickr' href='" + exitLink + "' alt='" + item.title + "'></a>");
				});
			});
		}
		$('#social_'+brand+' .flickr *').show();
	},
	
	youtube: function(brand) {
		$('#social_'+brand+' .youtube').show();
		if($('#social_'+brand+' .youtube .content').html().toLowerCase() == "<p>loading...</p>"){
			$.getJSON('http://gdata.youtube.com/feeds/users/'+cllc.social.config.youtube[brand]+'/uploads?alt=json-in-script&callback=?', function(data) { 
				$.each(data.feed.entry, function(i, item) {
					if(i==1) return false;
					var title = item['title']['$t'];
					var video = item['id']['$t'];
					var published = item['published']['$t'].split('.');
					published = published[0]+"Z";
					var description = item['media$group']['media$description']['$t'];
					var rating = "";
					if(item['gd$rating']!=null)
						rating = item['gd$rating']['average'];
					var views = item['yt$statistics']['viewCount'];
					var thumbnail = item['media$group']['media$thumbnail'][0]['url'];
					if(views.length > 3) views = views.replace(/\B(?=(?:\d{3})+(?!\d))/g, ',');
					if(description.length > 80){
						/***** Truncate the description *****/
						description = description.substring(0, 80);
						description = description.replace(/\w+$/, '') + '...';
					}
					
					/***** Cool star rating thing *****/
					var stars = "00";
					if(rating>.25) stars = "05";
					if(rating>.75) stars = "10";
					if(rating>1.25) stars = "15";
					if(rating>1.75) stars = "20";
					if(rating>2.25) stars = "25";
					if(rating>2.75) stars = "30";
					if(rating>3.25) stars = "35";
					if(rating>3.75) stars = "40";
					if(rating>4.25) stars = "45";
					if(rating>4.75) stars = "50";
					video = video.replace('http://gdata.youtube.com/feeds/videos/','http://www.youtube.com/watch?v=');
					var exitLink = cllc.social.makeLink(brand, 'youtube', video);
					$('#social_'+brand+' .youtube .content').html(
						'<a name="&lpos='+brand+'_community&lid=youtube" href="'+exitLink+'"><img src="'+thumbnail+'" alt="'+title+'" /></a><div class="details">' +
						'<a name="&lpos='+brand+'_community&lid=youtube" href="'+exitLink+'">'+title+'</a><p>'+description+'</p>' +
						'<div class="rating rating-'+stars+'"></div> <span class="pubDate">'+$.timeago(published)+'</span> '+views+' views</div>')
						.removeClass('loading');
				});
			});
		}
		$('#social_'+brand+' .youtube *').show();
	},
	
	twitter: function(brand) {
		$('#social_'+brand+' .twitter').show();
		if($('#social_'+brand+' .twitter .content').html().toLowerCase() == "<p>loading...</p>"){
			$.getJSON("http://twitter.com/statuses/user_timeline/"+cllc.social.config.twitter[brand]+".json?callback=?", function(data){
				$('#social_'+brand+' .twitter .content').empty().removeClass('loading');
				$.each(data, function(i,tweet){
					if(i==1) return false;
					var tweet_text = tweet.text;
					var published = new Date(tweet.created_at);
					
					/***** Make some working links *****/
					tweet_text = tweet_text.replace(/((ftp|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm,'<a name="&lpos='+brand+'_community&lid=twitter" href="javascript:flexWin(&quot;/exit?tname=twitter_'+brand+'&dynamicUrl=$1&exitMsg=yes&quot;,&quot;yes&quot;,&quot;1024&quot;,&quot;768&quot;,&quot;twitter_'+brand+'&quot;,&quot;all&quot;)">$1</a>');
					tweet_text = tweet_text.replace(/([^\w]?)\@([\w\-]+)/gm,'$1<a name="&lpos='+brand+'_community&lid=twitter" href="javascript:flexWin(&quot;/exit?tname=twitter_'+brand+'&dynamicUrl=http://twitter.com/$2&exitMsg=yes&quot;,&quot;yes&quot;,&quot;1024&quot;,&quot;768&quot;,&quot;twitter_'+brand+'&quot;,&quot;all&quot;)">@$2</a>');
					tweet_text = tweet_text.replace(/([^\w]?)\#([\w\-]+)/gm,'$1<a name="&lpos='+brand+'_community&lid=twitter" href="javascript:flexWin(&quot;/exit?tname=twitter_'+brand+'&dynamicUrl=http://twitter.com/search?q=%23$2&exitMsg=yes&quot;,&quot;yes&quot;,&quot;1024&quot;,&quot;768&quot;,&quot;twitter_'+brand+'&quot;,&quot;all&quot;)">#$2</a>');
					$("#social_"+brand+" .twitter .content").html('<a name="&lpos='+brand+'_community&lid=twitter" href="javascript:flexWin(&quot;/exit?tname=twitter_'+brand+'&dynamicUrl=http://www.twitter.com/'+tweet.user.screen_name+'&exitMsg=yes&quot;,&quot;yes&quot;,&quot;1024&quot;,&quot;768&quot;,&quot;twitter_'+brand+'&quot;,&quot;all&quot;)">' +
						'@'+tweet.user.name+'</a> : '+tweet_text);
				});
			});
		}
		$('#social_'+brand+' .twitter *').show();
	}
};

} catch(e) { cllc.standard_error_handler(e); }

$(cllc.social.init);