// sharehubber.js
// Stuff for shareHub users a.k.a. shareHubbers.
// jwm

// AddThis.com button config
var addthis_config = {
	username: "sharehub",
	ui_header_color: "#ffffff",
	ui_header_background: "#1a7eae",
	ui_cobrand: "shareHub",
	ui_hover_direction: -1,
	ui_offset_top: -5,
	ui_hover: false,
	data_track_linkback: true,
	services_expanded: "email,favorites,aim,amazonwishlist,ask,bebo,blogger,blogmarks,delicious,digg,dzone,email,evernote,facebook,fark,gmail,google,hackernews,hellotxt,hotmail,kaboodle,linkedin,live,livejournal,mixx,misterwong,myspace,netlog,netvibes,pingfm,plaxo,plurk,posterous,printfriendly,propeller,reddit,slashdot,sodahead,stumbleupon,technorati,tumblr,twitter,typepad,virb,wordpress,yahoobkm",
	templates: {
		twitter: 'Get "{{title}}" at shareHub: {{lurl}}'
	}
};

function scaleImages()
{
	//Configuration Options
	var max_width = 575;			// Sets the max width, in pixels, for every image
	var selector = 'img.userImage';		//Sets the syntax for finding the images.  Defaults to all images.
	
	$(selector).each(function() {
		var orig_width = $(this).width();
		var orig_height = $(this).height();
		if (orig_width > max_width) {
			//Set variables	for manipulation
			var ratio = (orig_height / orig_width );
			var new_width = max_width;
			var new_height = (new_width * ratio);
			
			//Shrink the image and add link to full-sized image
			$(this).height(new_height).width(new_width);
			
			$(this).attr("title", "The image has been scaled down to fit this page. Click to view the original version.");
			$(this).css("cursor", "pointer !important");

			/* 
				$(this).bind("click", function(e) {
					window.open($(this).attr("src").replace("/view/","/open/"));
					return false;
				});
			*/

		} //if
		$(this).css("visibility","visible");
	} //each
	);

}

function trackFileDownload(fileId,fileSize)
{
	if ( pageTracker ) {	
		pageTracker._trackEvent('Authenticated_Files', 'Download', fileId, fileSize);
	}
	return true;
}


// Lock n load...
$(document).ready(function() {
	var prefURL = $("#PreferredURL").val();
	var prefTitle = $("#PreferredTitle").val();
	var prefContent = $("#fileDescription").text();
 
	$("#fileRating").rating('/rate', {maxvalue:5} );

	addthis.toolbox('#addThis_widget', addthis_config,
		            {url: prefURL, title: prefTitle, content: prefContent, templates: addthis_config.templates});

});