/*
	toolbag for this design.

*/

// dummy object to hold config
var config = new Object();

function zoomFont(elm,factor) {
    //alert('hi');
    var fs = jQuery(elm).css('font-size');
    var fsnum = parseFloat(fs, 10);
    var newfs = fsnum*factor;
    var lh = jQuery(elm).css('line-height');
    var lhnum = parseFloat(lh, 10);
    //alert(lh+":"+lhnum);
    var newlh = lhnum*factor;
   	//alert(currentFontSize);
   	jQuery(elm).css('font-size', newfs+'px').css('line-height',newlh+'px');
}

jQuery(document).ready(function () {
	jQuery( '#share-box #tool-share' ).bind( 'click', ShareThisItem );
	jQuery( '#share-box-popup a.popup' ).bind( 'click', PopThisItem );
	jQuery( '#share-box-popup a.twitterbox' ).bind( 'click', TwitterBox );
});

/**
 * Share items! This function displays the popupbox for the #tool-share link
 * @access public
 * @return void
 **/
function ShareThisItem(f){
	f.preventDefault();
	jQuery('#share-box #share-box-popup').toggle();
}

/**
 * Popup this item instead of _top linking
 * @access public
 * @return void
 **/
function PopThisItem(f){
	f.preventDefault();
	window.open(jQuery(this).attr('href'),'shareItem','status=0,toolbar=0,width=800,height=500,scrollbars=1');

}

/**
 *
 * @access public
 * @return void
 **/
function TwitterBox(f){
	f.preventDefault();
	jQuery('body').prepend('<div id="alphalayer"></div><div id="alphalayer_content"></div><div id="alphalayer_close"><a class="close" href="javascript:closeAlphaLayer();">close this window</a></div>');
	jQuery('#alphalayer').bind('click',closeAlphaLayer);

	/*
	jQuery.ajax({
				type: "GET",
				url: "http://api.bit.ly/v3/shorten?login=contactivity&apiKey=R_778f7fe3ca8b663f2bc39dc45e01904f&format=json&longUrl="+location.href,
				dataType: "json",
				success: bitlysucceeded
	});
	*/
	bitlysucceeded({});

}

/**
 *
 * @access public
 * @return void
 **/
function bitlysucceeded(result){
	var thelink=location.href;
	if(result.status_code==200) {
		thelink = result.data.url;
	}

	writeTwitterBox(jQuery('#share-box-popup a.twitterbox').attr('title'),thelink);

}

/**
 *
 * @access public
 * @return void
 **/
function writeTwitterBox(thetext,thelink){
	if(twttr) {
		twttr.anywhere(function (T) {
			T("#alphalayer_content").tweetBox({
				height: 100,
				width: 400,
				defaultContent: thetext + " - " + thelink,
				onTweet:TweetSucceeded
			});
		});
	} else {
		// apparently not loaded. remove the alphabox
		closeAlphaLayer();
	}
}

/**
 * Closes the semi-transparent layer
 * @access public
 * @return void
 **/
function closeAlphaLayer(){
	jQuery('#alphalayer_close').remove();jQuery('#alphalayer_content').remove();
	jQuery('#alphalayer').fadeOut(500,function() {
		jQuery('#alphalayer').remove();
	});
}

/**
 * Tweet succeeded!
 * @access public
 * @return void
 **/
function TweetSucceeded(twplain,twhtml){
	jQuery('#alphalayer_content').html("Your tweet '"+twhtml+"' was succesfully posted!<br />You can now <a href='javascript:closeAlphaLayer();'>close this window</a>.");
}

