/* Gets number of known visits */
function known_visits(){
    var utma = $.cookie('__utma');
    var utma_split = utma.split(".");
    var known_visits = utma_split[5];
    return known_visits;
}

// show appeal if no cookie found

/*
$(".print-only").ready(function($) {
    x = parseInt($.cookie("splash"));

    if (!x) {
       // /india/Global/india/image/2015/69GP_PopUp_11May15.jpg
        var imageUrl = encodeURIComponent('https://secured-static.greenpeace.org/india/Global/india/2018/images/AP-popUP.jpg');

        var config = {
            contentUrl: resources.base_url + "Templates/Planet3/Pages/Popups/ThumbnailEnlarged.aspx .enlargepopup",
            contentParams: { 'imageUrl': imageUrl, 'uiculture': resources.uiculture }
        };
       Main.openLightbox(imageUrl, config,
        function() {
            var a = $('<a/>').attr('href', 'https://act.greenpeace.org/page/17274/action/1?utm_source=website&utm_medium=banner&utm_campaign=airpollution&utm_content=popup'
);
            $('img', '.lightbox:visible').wrap(a);
        });
    }

    // set 2 day cookie
    $.cookie("splash", 1, {expires:6, path: '/'});
});


*/


/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};




$(document).ready(function() {
    /**
     * Get random image and set to the given anchor
     */
    function getRandomImage( id, imgArray, link, title) {
        // default path here
        var num = Math.floor( Math.random() * imgArray.length ),
            target = $('#'+id),
            targetImg = $(target).find('img');
        $(target).attr("href", link[num]);
        $(targetImg).attr('src', imgArray[ num ]);
        $(targetImg).attr('alt', title[num] );
        $(targetImg).attr('title', title[num] );
    }
    
    getRandomImage('sideBanner', 
        [ '/india/Global/india/image/2014/banner/sidebanner/8-26-sidebar-contribute3.png'], 
        [ 'http://donate.greenpeace.in/?utm_source=website&utm_medium=banner&utm_content=side-banner&utm_campaign=website'], 
        ['Donate']
    );

    // read more 
    $('#gp-read-more').click(function() {
      $(this).css('display', 'none');
      $('#'+$(this).attr('data-target')).css('display', 'block');
    })
});

