jQuery.dontShowChooseWebstorePopup = function() {
    DONT_SHOW_CHOOSE_WEBSTORE_POPUP_PERIOD = 2*60*60; //a week
    jQuery.createCookie('choose_webstore_popup', 'false', DONT_SHOW_CHOOSE_WEBSTORE_POPUP_PERIOD);
};

jQuery.renewChooseWebstorePopupCookie = function() {
    if(jQuery.readCookie('choose_webstore_popup') == 'false') {
        jQuery.dontShowChooseWebstorePopup();
    }
}

/*
If a visitor is from Canada and "choose_webstore_popup" cookie is not set and current URL is different than Canadian webstore's URL then show a pop-up message suggesting to switch to Canadian webstore.
*/
jQuery.chooseWebstore = function() {
    // TODO: remove it when problems are fixed
    return;

    jQuery.renewChooseWebstorePopupCookie();

    if( jQuery.readCookie('choose_webstore_popup') == 'false'
     || (CURRENT_WEBSTORE_URL == CA_WEBSTORE_URL && visitorsCountry == 'ca')
     || (CURRENT_WEBSTORE_URL == US_WEBSTORE_URL && visitorsCountry == 'us')
     || (CURRENT_WEBSTORE_URL == US_WEBSTORE_URL && visitorsCountry == 'outside_ca_us') ) {
        return;
    }

    // Don't show pop-up on http://amazingdiscoveries.org/webstore/
    if(CURRENT_WEBSTORE_URL != CA_WEBSTORE_URL && CURRENT_WEBSTORE_URL != US_WEBSTORE_URL) {
        jQuery.dontShowChooseWebstorePopup();
        return;
    }

    jQuery.dontShowChooseWebstorePopup();

    jQuery("div.choose-webstore-wrapper").animate({"top": "+=1100px", "left": "-=0px"}, 0);
    jQuery("div.choose-webstore").html('\
        <div class="choose-webstore-content">\
            <br/> <br/><span style="font-size:21px; color:#222;">Shopping from <b>Canada</b> or <b>USA</b>?</span><br /> <br /> <br/>\
            <a href="'+CURRENT_PAGE_URL_CA+'"><img src="'+IMAGES_URL+'header/store_ca.png" /></a><br /> <br /> <br />\
            <a href="'+CURRENT_PAGE_URL_US+'"><img src="'+IMAGES_URL+'header/store_us.png" /></a><br /> <br /> <br />\
            <span style="font-size:11px; line-height:normal;">Please choose the webstore specific to your location to avoid currency exchange rates or excessive shipping rates.</span>\
        </div>');
};

jQuery.setUpWebstoreSelector = function() {
    jQuery("div.webstore-links-selector").hide(0);
    jQuery("div.webstore-links-selector").animate({"top": "90px"}, 0);

    jQuery("span.webstore_flags").click(function(event) {
        jQuery("div.webstore-links-selector").fadeIn("fast");
    });

    jQuery("div.webstore-links-selector").mouseleave(function(event) {
        jQuery("div.webstore-links-selector").fadeOut("fast");
    });
}

