﻿/// <reference path="~/scripts/jquery.js" />
var loginActionHiddenId;
var loginTitleId;
var recipeBoxAction;
var groceryListAction;
var registrationLinkId;
var recipeBoxRegistrationUrl;
var groceryListRegistrationUrl;


function shareSite(sUrl, site) {
    sUrl = sUrl.replace('THISURL', escape(document.location));
    window.open(sUrl, 'winShare', 'scrollbars=1,toolbar=0,width=800,height=600');
    if (site == "stumbleupon") {
        var axel = Math.random() + "";
        var a = axel * 10000000000000;
        document.getElementById('Iframe').innerHTML = '';
        document.getElementById('Iframe').innerHTML = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1869704;type=betty077;cat=stumb881;ord=1;num=' + a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';
    }

    if (site == "delicious") {
        var axel = Math.random() + "";
        var a = axel * 10000000000000;
        document.getElementById('Iframe').innerHTML = '';
        document.getElementById('Iframe').innerHTML = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1869704;type=betty077;cat=delic500;ord=1;num=' + a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';
    }

    if (site == "twitter") {

        var axel = Math.random() + "";
        var a = axel * 10000000000000;
        document.getElementById('Iframe').innerHTML = '';
        document.getElementById('Iframe').innerHTML = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1869704;type=betty077;cat=twitt917;ord=1;num=' + a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';

    }

    if (site == "reddit") {

        var axel = Math.random() + "";
        var a = axel * 10000000000000;
        document.getElementById('Iframe').innerHTML = '';
        document.getElementById('Iframe').innerHTML = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1869704;type=betty077;cat=reddi314;ord=1;num=' + a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';
    }

    if (site == "digg") {

        var axel = Math.random() + "";
        var a = axel * 10000000000000;
        document.getElementById('Iframe').innerHTML = '';
        document.getElementById('Iframe').innerHTML = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1869704;type=betty077;cat=diggb763;ord=1;num=' + a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';
    }

    return;
}

function shareFacebook(sTitle, sOverrideURL) {

    var axel = Math.random() + "";
    var a1 = axel * 10000000000000;
    document.getElementById('Iframe').innerHTML = '<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1869704;type=betty077;cat=email720;ord=1;num=' + a1 + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>';

    var d;
    var l;
    var ou;
    var f = 'http://www.facebook.com/share';

    var e = encodeURIComponent;
    var p;

    if (sOverrideURL === '') {
        d = document;
        l = d.location;
        p = '.php?src=bm&v=3&u=' + e(l.href) + '&t=' + e(sTitle);
    } else {
        p = '.php?src=bm&v=3&u=' + e(sOverrideURL) + '&t=' + e(sTitle);
    }

    a = function() {
        if (!window.open(f + 'r' + p, 'sharer', 'toolbar=0, status=0, resizable=0, width=626, height=436'))

            l.href = f + p;
    };

    if (/Firefox/.test(navigator.userAgent)) {
        setTimeout(a, 0);
    } else {
        a();
    }

    void (0);


}

var timer;


function hidePopup() {
    timer = setTimeout
                (
                  function() {
                      $(".share_panel_container")
                       .hide();
                  },
                      500
                );
}


jQuery(document).ready(function() {
    jQuery(".share").hover(
                                function() {
                                    if (timer) {
                                        clearTimeout(timer);
                                    }
                                    var pos = jQuery(this).position();
                                    var popupHeight = jQuery(this).parents(".utility_links").next(".share_panel_container").height();
                                    var popupWidth = jQuery(this).parents(".utility_links").next(".share_panel_container").width();
                                    jQuery(this).parents(".utility_links").next(".share_panel_container").show()
                                    .css("left", (pos.left - 56)).css("top", (pos.top + 20));
                                }
                                   ,
                          function() {
                              hidePopup();
                          }
                          );
    jQuery(".share_panel_container").hover(
                          function() {
                              if (timer) {
                                  clearTimeout(timer);
                              }
                          },
                          function() {
                              hidePopup();
                          }
                         );
});

function OpenPopup(sURL, sTitle, sParams) {
    var w = 660;
    var h = 480;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    var sParams2 = sParams + ",top=" + wint + ",left=" + winl;
    var PopUp = window.open(sURL, sTitle, sParams2);
    PopUp.focus();
}

function LoginRecipeBox() {
    ShowLogin("Please log in to save this recipe to your recipe box.", recipeBoxAction, recipeBoxRegistrationUrl);
}

function LoginGroceryList() {
    ShowLogin("Please log in to add this recipe to a Grocery List.", groceryListAction, groceryListRegistrationUrl);
}

function ShowLogin(message, action, registrationUrl) {
    $find('popupLoginBehavior').show();
    jQuery("#" + loginActionHiddenId).val(action);
    jQuery("#" + loginTitleId).text(message);
    jQuery("#" + registrationLinkId).attr("href", registrationUrl);
}