$(document).ready(function () {

    var notificationDelay;
    var timer;
    var closeClicked = false;
	
	var eyVisitedCookieCheck = getCookie('eyvisited');	
    if (eyVisitedCookieCheck != null) {
		var countryCookie = getCookie('Country');
		var localeCookie = getCookie('Locale');	
		var baseLocation = localeCookie + "_" + countryCookie;
        var currentLocation =  contentLang + "_" + contentCountry;
        
		if (baseLocation.toLowerCase() == currentLocation.toLowerCase()) {
			deleteCookie("eyvisited", "/", cookieDomainName);
		}	
	}
			
    function startDelayCount() {
        notificationDelay = 0;
        timer = setInterval(function () {
            if (notificationDelay == 2) {
                $('.notification').animate({
                    top: ['-145px', 'swing'],
                    opacity: 'toggle'
                });
                clearInterval(timer);
            }
            notificationDelay++;
        }, 3000);
    }

    function checkVisit() {
        var loc = location.pathname;
        var locArray = loc.split("/");

        targetCountryLocale = (locArray[2]).toLowerCase() + "_" + (locArray[1]).toLowerCase();
        var eyVisitedCookie = getCookie('eyvisited');

        if (eyVisitedCookie == null) {
            setCookie("eyvisited", targetCountryLocale, "", "/", cookieDomainName);
        }
        else {
            if (eyVisitedCookie.indexOf(targetCountryLocale) > -1) {
            } else {
                setCookie("eyvisited", getCookie('eyvisited') + "#" + targetCountryLocale, "", "/", cookieDomainName);
            }
        }
    }
    
    $('#notificationnevershow').removeAttr('checked');
    if ($.cookie('eyhidechgsiteareanotice') != '1') {

        startDelayCount();

        $('.notification').delay(2000).animate({
            top: ['22', 'swing'],
            opacity: 'toggle'
        }, 1000, function(){ checkVisit() });

        $('.notification').mouseover(function () {
            clearInterval(timer);
        }).mouseout(function () {
            if (closeClicked == false) { startDelayCount(); }
        });
        
        $('.notificationclose').click(function () {
            $('.notification').fadeOut('fast');
            clearInterval(timer);
            closeClicked = true;
        });

        $('#notificationnevershow').change(function () {
            if ($(this).is(':checked')) {
                $.cookie('eyhidechgsiteareanotice', '1', { expires: 365, path: '/', domain: location.host });
            } else {
                $.cookie('eyhidechgsiteareanotice', null, { path: '/', domain: location.host });
            }
        });
    }
});
