// JavaScript Document

//Publish to facebook wall
function Publish(name, href, description, imageSrc, imageHref, actionText, actionHref) {
	
	//alert ('Name = '+name);
	//alert ('href = '+href);
	//alert ('description ='+description);
	//alert ('imageSrc = '+imageSrc);
	//alert ('imageHref = '+imageHref);
	//alert ('actionText = '+actionText);
	//alert ('actionHref = '+actionHref);

	
    var attachment = {
        'name':name,
        'href':href,
        'description':description,
        'media':[{
             'type':'image',
             'src':imageSrc,
             'href':imageHref
        }]
    };
    
    var action_link = [{
        'text':actionText,
        'href':actionHref
    }];
    
    FB.ensureInit(function () {
        FB.Connect.streamPublish('', attachment, action_link);
    });
}

//Publish to twitter wall
function twitterPublish (Title, Url) {
    //alert (Title);
    //alert (Url);
    //set twitter max string length
    var maxLength = 140 - (Url.length + 1);
    
    if (Title.length > maxLength) {
        Title = Title.substr(0, (maxLength - 3))+'...';
    }
    
    //create our url, with our injected variables
    var Link = 'http://twitter.com/home?status='+encodeURIComponent(Title + ' ' + Url);
    
    //open a new window with our target url
    window.open(Link) 
}

//
function sendToJavaScript(milkType, imageURL){
   	//alert('output passed from flash to Jscript');
   	//alert('Celebrity Management Style:'+milkType);
    //alert('Celebrity Management Image:'+imageURL);
	//name, href, description, imageSrc, imageHref, actionText, actionHref
    Publish('Take the Milk Quiz','http://makeminemilk.co.uk/',milkType,imageURL,'http://makeminemilk.co.uk/','Take the Milk Quiz','http://makeminemilk.co.uk/');
}

