﻿var shareUrls = new Array();
shareUrls["facebook"] = "http://www.facebook.com/sharer.php?u=__URL__";
shareUrls["twitter"] = "http://twitter.com/home?status=__URL__";
shareUrls["digg"] = "http://digg.com/submit?url=__URL__";
shareUrls["reddit"] = "http://reddit.com/submit?&url=__URL__";
shareUrls["myspace"] = "http://www.myspace.com/Modules/PostTo/Pages/?u=__URL__";
shareUrls["delicious"] = "http://www.delicious.com/post?url=__URL__";
shareUrls["buzz"] = "http://www.google.com/reader/link?url=__URL__";

var shareImagesUrl = "__BASE__/?t=__TYPE__&id=__IMAGE__";

var defaultTitle = "Qpiz";

function shareSite(socialNetwork, langCode) {
    var url = shareUrls[socialNetwork];
    var siteUrl = getCurrentBaseUrl();
    url = url.replace("__URL__", encodeURIComponent(siteUrl + "/index.php?lang=" + langCode));
    popupCenter(url, 'Qpiz', 900, 600);
}

function shareUrl(url, network) {
    var url = shareUrls[network];
    var siteUrl = getCurrentBaseUrl();
    var imageUrl = shareImagesUrl.replace("__IMAGE__", idPic.toString());
    imageUrl = imageUrl.replace("__BASE__", siteUrl);
    imageUrl = imageUrl.replace("__TYPE__", "0");
    url = url.replace("__URL__", encodeURIComponent(imageUrl + "&lang=" + langCode));
    popupCenter(url, 'Qpiz', 900, 600);
}

function sharePic(idPic, langCode) {
    var url = shareUrls['facebook'];
    var siteUrl = getCurrentBaseUrl();
    var imageUrl = shareImagesUrl.replace("__IMAGE__", idPic.toString());
    imageUrl = imageUrl.replace("__BASE__", siteUrl);
    imageUrl = imageUrl.replace("__TYPE__", "0");
    url = url.replace("__URL__", encodeURIComponent(imageUrl + "&lang=" + langCode));
    popupCenter(url, 'Qpiz', 900, 600);
}

function shareImageGallery(idFoto, lang) {
    sharePic(idFoto, lang);
}

function shareSound(suono, langCode) {
    var url = shareUrls['facebook'];
    var siteUrl = getCurrentBaseUrl();
    var imageUrl = shareImagesUrl.replace("__IMAGE__", suono.toString());
    imageUrl = imageUrl.replace("__BASE__", siteUrl);
    imageUrl = imageUrl.replace("__TYPE__", "1");
    url = url.replace("__URL__", encodeURIComponent(imageUrl + "&lang=" + langCode));
    popupCenter(url, 'Qpiz', 900, 600);
}

function getCurrentBaseUrl() {
    var siteUrl = location.href;
    return siteUrl.substring(0, siteUrl.lastIndexOf("/"));
}

function popupCenter(pageURL, title, w, h) {
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 
