var debug = function(what){
	if(window.console && window.console.firebug){
		//console.log(what);
	}       
	else{
		//alert(what);
	}
}
$(document).ready(function() {
	debug('dom ready');
	emailLinkCoupon();
	facebookLinkCoupon();
	twitterLinkCoupon();
	diggLinkCoupon();	
	deliciousLinkCoupon();
});


//SHARE LINK FUNCTIONS

var emailLinkCoupon = function()
{
	pageInfo = shareLink();
	var subject = "Get $4 off any one bag of ULTRA(TM) holistic food for dogs.";
	var body = "Only ULTRA(TM) holistic dog products contain a unique combination of nutrient-dense superfoods in our new ULTRASSENTIAL(R) Superfood Blend. These high quality ingredients work together to promote a long and healthy life for your dog. Try a bag today!\n\nGet $4 off any one bag of ULTRA(TM) holistic food for dogs\n\nUse this coupon and pass it along!\n\n";
	var linkFormat = ['mailto:?Subject=', encodeURL(subject), '&Body=', encodeURL(body) + pageInfo.linkURL];
	addLink('#emailCoupon', linkFormat); 
}

var facebookLinkCoupon = function()
{
	pageInfo = shareLink();
	var text = "Nourish your whole dog from head to paw with ULTRA(TM) holistic food for dogs. And now Get $4 off any one bag of ULTRA(TM) holistic food for dogs. Get the coupon here.";
	var linkFormat = ['http://www.facebook.com/share.php?u=', pageInfo.linkURL, '&t=', encodeURL(text)];
	addLink('#facebookCoupon', linkFormat); 
}

var twitterLinkCoupon = function()
{
	pageInfo = shareLink();
	var text = "Get $4 off any one bag of ULTRA(TM) holistic food for dogs. Go to http://bit.ly/7XhVhD to get your coupon now! Pass it on!";
	var linkFormat = ['http://twitter.com/home?status=', encodeURL(text)];
	addLink('#twitterCoupon', linkFormat);
}

var diggLinkCoupon = function()
{
	pageInfo = shareLink();
	var text = "Title text: Get $4 off any one bag of ULTRA(TM) holistic food for dogs.";
	var desc = "ULTRA(TM) food for dogs can be found at your local pet retail store."
	var linkFormat = ['http://digg.com/submit?url=', pageInfo.linkURL, "&title=", encodeURL(text), "&bodytext=", encodeURL(desc)];
	addLink('#diggCoupon', linkFormat);
}

var deliciousLinkCoupon = function()
{
	pageInfo = shareLink();
	var text = "Get $4 off any one bag of ULTRA(TM) holistic food for dogs.";
	var linkFormat = ['http://del.icio.us/save?url=', pageInfo.linkURL, "&title=", encodeURL(text)];
	addLink('#deliciousCoupon', linkFormat);
}

var myspaceLinkCoupon = function()
{
	pageInfo = shareLink();
	var linkFormat = ['http://www.myspace.com/Modules/PostTo/Pages/?l=3&u=', pageInfo.linkURL, '&t=', 'NUTRO+ULTRA'];
	addLink('myspaceCoupon', linkFormat);
}

var shareLinkCoupon = function()
{
	var linkURL = encodeURL(getURL());
	var linkTitle = encodeURL(getTitle());
	var linkDescription = encodeURL('NUTRO(R) ULTRA(TM)');

	return {'linkURL': linkURL, 'linkTitle':linkTitle, 'linkDescription':linkDescription}
}

var addLink = function(linkSelector, linkArray)
{
	var linkString = linkArray.join('');
	debug('linkString : ' + linkString);
	var selectorString = linkSelector + ' > a'; 
	$(selectorString).attr('href', linkString);
}


var getURL = function()
{
	return location.href;
}

var getTitle = function()
{
	return document.title;
}

var getDescription = function()
{
	return document.getElementsByName('meta')['description'].content;
}

var encodeURL = function(urlString)
{
	return escape(urlString);
}

