// browser detection script by  Jonathan Neal http://jquery.thewikies.com/browser/
(function($) {
    $.browserTest = function(a, z) {
        var u = 'unknown',x = 'X',m = function(r, h) {
            for (var i = 0; i < h.length; i = i + 1) {
                r = r.replace(h[i][0], h[i][1]);
            }
            return r;
        },c = function(i, a, b, c) {
            var r = {name:m((a.exec(i) || [u,u])[1], b)};
            r[r.name] = true;
            r.version = (c.exec(i) || [x,x,x,x])[3];
            if (r.name.match(/safari/) && r.version > 400) {
                r.version = '2.0';
            }
            if (r.name === 'presto') {
                r.version = ($.browser.version > 9.27) ? 'futhark' : 'linear_b';
            }
            r.versionNumber = parseFloat(r.version, 10) || 0;
            r.versionX = (r.version !== x) ? (r.version + '').substr(0, 1) : x;
            r.className = r.name + r.versionX;
            return r;
        };
        a = (a.match(/Opera|Navigator|Minefield|KHTML|Chrome/) ? m(a, [
            [/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,''],
            ['Chrome Safari','Chrome'],
            ['KHTML','Konqueror'],
            ['Minefield','Firefox'],
            ['Navigator','Netscape']
        ]) : a).toLowerCase();
        $.browser = $.extend((!z) ? $.browser : {}, c(a, /(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/, [], /(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));
        $.layout = c(a, /(gecko|konqueror|msie|opera|webkit)/, [
            ['konqueror','khtml'],
            ['msie','trident'],
            ['opera','presto']
        ], /(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);
        $.os = {name:(/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase()) || [u])[0].replace('sunos', 'solaris')};
        if (!z) {
            $('html').addClass([$.os.name,$.browser.name,$.browser.className,$.layout.name,$.layout.className].join(' '));
        }
    };
    $.browserTest(navigator.userAgent);
})(jQuery);

var date = new Date();
var localTime = date.getTime();
var hours = date.getHours();
var minutes = date.getMinutes();
if (minutes < 10) {
    minutes = "0" + minutes
}
var year = date.getFullYear();
var month = date.getMonth();
month ++;
var day = date.getDate();

(function($) {
    $.fn.extend({
        ezalert: function(browser, os, hours, minutes, page, year, month, day) {
            var AlertPath = "http://www.anglers.co.nz/";
            var ezid = "";
            // compare user values against alerts table
            $.ajax({
                type: "GET",
                url: AlertPath + "includes/alert.php",
                data: "check_alert=true&browser=" + browser + "&os=" + os + "&page=" + page + "&hours=" + hours + "&minutes=" + minutes + "&year=" + year + "&month=" + month + "&day=" + day,
                success: function(alertResponse) {
                    if (alertResponse != "false") {

                        // break response into an array
                        var arr = alertResponse.split("|*|");
                        var alerts = new Array();
                        // clean out array of empty entries
                        for (k in arr) if (arr[k]) alerts.push(arr[k]);
                        var alertClass = alerts[3];
                        if (alerts[0] == "modal" || alerts[0] == "box_no_modal") {
                            // work out whether it is a modal alert
                            if (alerts[0] == "modal") {
                                ezid = 'ezalert_overlay';
                            } else {
                                ezid = 'ezalert_outer';
                            }
                            $('body').append('<div id="' + ezid + '"></div>');
                            $('body').append('<div id="ezalert_container"></div>');
                            $('#ezalert_container').append('<div id="ezalert_title"><img src="' + AlertPath + 'images/alert_' + alertClass + '.png">' + alerts[1] + '</div>');
                            $('#ezalert_container').append('<div id="ezalert_body"><p>' + alerts[2] + '</p></div>')
                            $('#ezalert_container').append('<div id="ezalert_actions" class="' + alertClass + '"><a class="clickable" id="ezalert_close"><img src="' + AlertPath + 'images/alert_small_close.png">close</a></div>')
                            $("#ezalert_close").click(function() {
                                ezalertHide(ezid, 'ezalert_container');
                            });
                            $('#' + ezid).css("opacity", 0.7);
                            $('#' + ezid).fadeIn(150);
                            // center alert
                            var alertHeight = $('#ezalert_container').height();
                            var alertWidth = $('#ezalert_container').width();
                            var windowHeight = $(window).height();
                            var windowWidth = $(window).width();
                            var heightDiff = (windowHeight - alertHeight) / 2;
                            var widthDiff = (windowWidth - alertWidth) / 2;
                            $('#ezalert_container').css("left", widthDiff + "px");
                            $('#ezalert_container').animate({ top: heightDiff }, 300, function() {
                                $('#ezalert_container').effect("bounce", { times:2 }, 200);
                            });
                        } else {
                            if (alerts[0] == "slide_top") {
                                var orient = "top";
                            } else {
                                var orient = "bottom";
                            }
                            var ezid = "ezalert_slide_container";
                            $('body').append('<div id="' + ezid + '"><div id="ezalert_slide_outer"></div>   </div>');
                            $('#ezalert_slide_outer').append('<div id="ezalert_slide_title"><img src="' + AlertPath + 'images/alert_' + alertClass + '.png">' + alerts[1] + '</div>');
                            $('#ezalert_slide_outer').append('<div id="ezalert_slide_body"><p>' + alerts[2] + '</p></div>')
                            $('#ezalert_slide_outer').append('<div id="ezalert_slide_actions" class="' + alertClass + '"><a class="clickable" id="ezalert_close"><img src="' + AlertPath + 'images/alert_small_close.png">close</a></div>')
                            $("#ezalert_close").click(function() {
                                ezalertHide(ezid, 'ezalert_slide_outer');
                            });
                            var hOff = $('#ezalert_slide_outer').height();
                            $('#' + ezid).css(orient, -hOff);
                            if (orient == "top") {
                                $('#' + ezid).animate({ top: "0" }, 500);
                            } else {
                                $('#' + ezid).animate({ bottom: "0" }, 500);
                            }
                        }
                    }
                }
            });
            //hide the modalbox
            function ezalertHide(ezid, container) {
                $('#' + ezid).fadeOut(500, function() {
                    $('#' + ezid).remove()
                });
                $('#' + container).fadeOut(500, function() {
                    $('#' + container).remove()
                });
            }
        }
    });
})(jQuery);

   

