var popup = {};

function doPopup(url, name, width, height, winparams) {
	if (!width) width = screen.availWidth;
	if (!height) height = screen.availHeight;
	if (!name) name = 'popup';
	if (!url) return;

	var leftX = (screen.availWidth - width) / 2;
	var topY = (screen.availHeight - height) / 2;
	if (leftX < 0) leftX = 0;
	if (topY < 0) topY = 0;

	if (!(name in popup) || popup[name].closed) {
		popup[name] = window.open(url, name, 'width=' + width + ',height=' + height +
				',left=' + leftX + ',top=' + topY + (winparams?','+winparams:''));
	}
	if (window.focus) popup[name].focus();
	if (popup[name].opener == null) popup[name].opener = self;
	return popup[name];
}

function extLink(sWin) {
    switch (sWin) {
        case 'signup':
			doPopup('/2011fiesta/signup/', sWin, 595, 711, 'scrollbars=yes,resizable=no,menubar=no,toolbar=no');
			break;
		 case 'fiestamovementPromo':
			mContentActivity('referral:fvm:fiestamovement');
			location.href = 'http://www.fiestamovement.com/ride-and-drive/events';
			break;
		case 'fiestamovement':
			mContentActivity('referral:fvm:fiestamovement');
			location.href = 'http://www.fiestamovement.com/';
			//goexternal('http://www.fiestamovement.com/')
			break;
		case 'forddotcom':
			mContentActivity('referral:fv:home');
			location.href = 'http://www.fordvehicles.com/';
			break;	
		case 'privacy':
			doPopup('/help/privacy/', sWin, 750, 800, 'scrollbars=yes,resizable=no,menubar=no,toolbar=no');
			break;
		case 'sharethis':
			mContentActivity('global:sharethis');
			socialShare();
			break;
    }
}

//share on social networking site
function socialShare()
{
	ShareThis_set("title", "http://www.fordvehicles.com/2011Fiesta/");
	ShareThis_set("url", "http://www.fordvehicles.com/2011Fiesta/");
	//ShareThis_set("icon", "http://pittsburghdish.typepad.com/pittsburgh_dish/images/2008/05/08/onion_logo.jpg");
	//ShareThis_set("summary", "Some Summary");
	//ShareThis_set("content", "<span>My content</span>");
	ShareThis_share();
}

function openLinkWrapper(link) {
	mContentActivity("2011 fiesta reveal:buzz:exit:" + link);

	//openLinkInNewWindow(link);
	doPopup(link, 'link', 800, 638, 'scrollbars=yes,resizable=no,menubar=yes,toolbar=yes');
}


function mContentListExtra(sPageName, sTag, sList) {
	if (sPageName=="summary") {
		var arL = sList.split(':');
		sList = arL.slice(0,3).join(":");
	}
	
	mContentViewAnd48_49 (sPageName, sTag, sList) 
}

function downloadZip(name) {
	mContentActivity("2011 fiesta reveal:download:"+name);
	document.getElementById("downloadIframe").src="/assets/modules/2011fiesta/images/"+name+".zip";
}

function shareImage(name, id) {
	var url = '/2011fiesta/tellafriend/?image=' + encode(name) + '&id=' + encode(id);
	//mContentActivity("2011 fiesta reveal:share:"+name);
	doPopup(url, 'share', 576, 638, 'scrollbars=no,resizable=no,menubar=no,toolbar=no');
}

function emailFiesta(style, color, trans, opt1, opt2, opt3) {
	opt1 = opt1.replace(/\u00ae/g, '&reg;');
	opt2 = opt2.replace(/\u00ae/g, '&reg;');
	opt3 = opt3.replace(/\u00ae/g, '&reg;');
	//mContentActivity('fv:reveal:2011:fiesta:reserve');
	var url = '/2011fiesta/emailfiesta/?style=' + encode(style) + '&color=' + encode(color) + '&trans=' +
			encode(trans) + '&opt1=' + encode(opt1) + '&opt2=' + encode(opt2) + '&opt3=' + encode(opt3);
	doPopup(url, 'emailfiesta', 575, 570, 'scrollbars=yes,resizable=yes,menubar=no,toolbar=no');
}

function reserveFiesta(style, color, trans, opt1, opt2, opt3) {
	//mContentActivity('fv:reveal:2011:fiesta:share');
	var url = '/2011fiesta/reserve/?style=' + encode(style) + '&color=' + encode(color) + '&trans=' +
			encode(trans) + '&opt1=' + encode(opt1) + '&opt2=' + encode(opt2) + '&opt3=' + encode(opt3);
	doPopup(url, 'reserve', 800, 600, 'scrollbars=yes,resizable=yes,menubar=no,toolbar=no');
}

function encode(s) {
	if (typeof encodeURIComponent === 'function') {
		return encodeURIComponent(s);
	} else {
		return escape(s);
	}
}

