// onchange event for select menu on stories leaf page
$('#stories_themes_select').change(function() {
    var selectedOption = $('option:selected',$(this));
    if (selectedOption.val()) { baseUrl += '&theme=' + selectedOption.val(); }
    document.location = baseUrl;
});

//resize large images in content to 80px width - not worrying about images that are much taller than wide (for now)
/*$('#featured div.itemjournal div.largeimagefix img, #results div.itemjournal div.largeimagefix img,').each(function() {
	var $img = $(this);
	var h = $img.height();
	var w = $img.width();

	var new_w = 100;
	var new_h = parseInt(new_w*h/w);

	if (w > new_w) { 
		$img.width(new_w); 
		$img.height(new_h);
	};	
});*/


//carousel items template
var jsonProcessor = function(v) {
	var html = new String();
				
	html += '<p class="userimage" style="background:url('+v['avatar']+') center center no-repeat"><img src="'+v['avatar']+'" class="photo"></p>';
	html +=		'<p class="title">' + v['title'] + '</p>';
	html +=		'<p class="snippet">' + v['snippet'] + '</p>';
	html +=		'<p class="info"><span class="username">' + v['username'] + '</span> '+ v['date'] +'</p>';
	html +=		'<div class="content">' + v['content'] + '</div>';
	return html;
};

//slider items template
var sliderProcessor = function(v){
	var html = new String();
	
	html += '<div class="itemgallery">';
	html += '<p class="userimage" style="background-image: url(' + v['image_url'] + ');">';
	html += '<a href="' + v['content_link'] + '" class="url" title="'+v['title']+'"></a>';
	html += '</p>';
	html += '</div>';
	html += '<div style="display: none;" class="content">';
	html += '<a href="' + v['content_link'] + '">';
	if (v['title'] == '') { html += 'Image'; } else { html += v['title']; }
	html += '</a>  by <a href="' + v['user_link'] + '">' + v['username'] + '</a> <span class="date"> ' + v['date'] + ' </span>';
	html += '</div>';
	
	return html;
};

var storyWallProcessor = function() {
	
	var dataSourceArgs = { 
		itemsToRetrieve: sw_itemsToRetrieve,
		fetches: sw_fetches,
		classname: sw_classname,
		cid: sw_cid,
		processType: sw_processType
	};
	
	$.getJSON(
		'_rpc/stories',
		dataSourceArgs,
		function(json) {
			sw_fetches++;

			$.each(json,function(i,v) {
				var html = new String();
				html += v['html'];
				$('#main #featured #contentPanel_dsstories_StoryWall').hide().html(html).animate({"opacity":"show"},"medium","easeInQuad");
			});
	
		}
	);
	

};

$('#featured .dsstories_StoryWall h4').prepend('<span><img src="/images/stories_refresh.gif">Refresh Wall</span>').find('span').click(storyWallProcessor);
$('#featured .dsstories_StoryWall h4').corner("5px").parent().corner("5px").find('.itemfooter').corner("3px");