//
/*
 * Global lime.js, included on every page.  Expects JQuery to be loaded.
 */

// Find city and lang
var p=location.pathname.split('/');
var city=p[1];
var lang=p[2];

$(document).ready(function() {

    // ----------------------------------------------------------------
    // Detect iOS and Android devices
    var ismobile=navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i)

    if (ismobile) {
        // position:fixed does not behave as expectedon iOS 4.x and older, and Android
        $("#footer_stripe").css("position", "static");
    };

    // ----------------------------------------------------------------
    // Header subscribe form
    $("form#header-signup").submit(function() {
      subscribe(city, lang, 'header-signup');
      return false;
    });

    // ----------------------------------------------------------------
    // Rollover effect used on "get inspired" etc images in footer on all pages
    $('img.rollover').hover(function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('lowsrc'));
        $(this).attr('lowsrc', currentImg);
    }, function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('lowsrc'));
        $(this).attr('lowsrc', currentImg);
    });

    // ----------------------------------------------------------------
    // Registration/subscription popups.  The show_*_popup vars are set in
    // header.inc.  Since header.inc is not included in the actual popups,
    // they will not be set there and testing them will throw errors, so
    // check they exist first.
    var popup_url='';
    if (typeof(show_reg_popup) !== 'undefined' && show_reg_popup) {
        // show_reg_popup=false;
        popup_url="/" + city + "/" + lang + "/popups/register_details.php";
    } else if (typeof(show_friends_popup) !== 'undefined' && show_friends_popup) {
        // show_friends_popup=false;
        popup_url="/" + city + "/" + lang + "/popups/register_friends.php"
    }

    if (popup_url) {
        $.colorbox({
            width:'662px',
            height:'513px',
            iframe:true,
            opacity:0.8,
            overlayClose:false,
            href: popup_url
        });
    }

    // ----------------------------------------------------------------
    // This is exactly like above except we need a special smaller popups to display in the Facebook iFrames
    var popup_url='';
    if (typeof(show_fb_reg_popup) !== 'undefined' && show_fb_reg_popup) {
        // show_reg_popup=false;
        popup_url="/" + city + "/" + lang + "/popups/register_details_fb.php";
    }

    if (popup_url) {
        $.colorbox({
            width:'480px',
            height:'372px',
            iframe:true,
            opacity:0.8,
            overlayClose:false,
            href: popup_url
        });
    }

    // ----------------------------------------------------------------
    // Focus fields where requested
    $("input.focus").focus();

});

