﻿var popUpTip = new Array();
popUpTip[0] = '<a class="tipOverlay" id="tipKJ" title="<p><strong>About the KJ</strong><br />Kilojoule = The international (metric) unit used to measure the amount of energy in a food. The old measure \'calorie\' may be more familiar to some people. 1 calorie = 4.2 kilojoules.</p>"></a>';

popUpTip[1] = '<a class="tipOverlay2" id="tipActivity" title="<p><strong>Add some activity</strong><br />Adding some activity to your morning routine can lift your mood, energy and help burn up excess kilojoules. Try...<br /><strong>Walking</strong> the dog before work<br /><strong>Sit-ups</strong> before breakfast<br />An early <strong>swim</strong> at the local pool<br /><strong>Cycling or walking</strong> to work.</p>"></a>';

popUpTip[2] = '<a class="tipOverlay" id="tipGetFit" title="<p><strong>Get fit with your kids</strong><br />If your child needs to train for a big event or sports match, give them some encouragement by getting out there alongside them. Cycling and swimming in pairs will make the lead-up to an event much more fun – you will both get far more out of it.</p>"></a>';

popUpTip[3] = '<a class="tipOverlay" id="tipPackADrink" title="<p><strong>Pack a drink</strong><br />It\'s great to sip on water, whether at school or out and about. Pop some water bottles in the freezer overnight so your little ones have refreshing, cool water to drink every day.</p>"></a>';

popUpTip[4] = '<a class="tipOverlay" id="tipFoodInviting" title="<p><strong>Make good food inviting</strong><br />Use shape-cutters to make simple, healthy sandwiches more appealing to younger children.</p>"></a>';

popUpTip[5] = '<a class="tipOverlay2" id="tipFruitVeg" title="<p><strong>Get your fruit & vegies</strong><br />There are so many ways to enjoy fruit and veges:</p><p><strong>In recipes</strong> &ndash; in curries, stir fries, boil-ups, chop suey, casseroles, soups and stews<br /><strong>Grated</strong> &ndash; in hamburgers, meat loaf, meat balls or rissoles<br /><strong>On platters</strong> &ndash; As raw fingerfoods served with dips – the more colours the better.</p>"></a>';

popUpTip[6] = '<a class="tipOverlay2" id="tipApple" title="<p><strong>An apple a day...</strong><br />Not getting your share of apples? Enjoy them in these delicious ways:</p><p><strong>Fresh</strong> in the lunch box or sliced and drizzled with lemon juice, in a snack-size zip-lock bag, to prevent browning<br /><strong>Cored</strong>, stuffed with dried fruit and baked<br /><strong>Stewed</strong> and served with custard or yoghurt<br /><strong>With a crumble topping</strong> for a winter treat.</p>"></a>';

popUpTip[7] = '<a class="tipOverlay" id="tipNuts" title="<p><strong>Go nuts</strong><br />A handful of almonds (20-24) a day and/or cashews (16-18) a day is a valuable addition to healthy eating.</p>"></a>';

popUpTip[8] = '<a class="tipOverlay2" id="tipLog" title="<p><strong>Keep an exercise log</strong><br />Silver Ferns coach Ruth Aitken asks the Silver Ferns to keep training diaries tracking their training and conditioning.</p><P>If you\'re serious about getting fit, you too could keep a daily or weekly workout and dietary log to help monitor your progress and any changes in energy (kilojoules) consumed and burnt through exercise.</p>"></a>';

var rand1 = Math.floor(Math.random() * popUpTip.length);
var rand2 = Math.floor(Math.random() * popUpTip.length);
while (rand2 == rand1) {
    rand2 = Math.floor(Math.random() * popUpTip.length);
}

jQuery().ready(function() {

    $("#navigation").accordion({ autoHeight: false, active: false });

    $("#tip1").html(popUpTip[rand1]);
    $("#tip2").html(popUpTip[rand2]);

    var pageNoToLoad = "01";
    var reg2digit = /^[0-2]{1}[0-9]{1}$/;

    if (location.href.substring(location.href.length - 8, location.href.length - 3) == "#tabs") {
        if (reg2digit.test(location.href.substring(location.href.length - 2, location.href.length))) {
            pageNoToLoad = location.href.substring(location.href.length - 2, location.href.length);
        }
    }
    else {
    
        
        $(".headingLink:first").addClass("selected");
        $("#navigation").accordion({ active: 0 });
    }

    $("#tabContent").empty().load("/ajax/page" + pageNoToLoad + ".html", function() {
        var newHeight = $("#tabContent").height() + 50 + "px";
        $("#tabs").height(newHeight);
    });

    $("div#navigation ul li a").removeClass("active");
    $("a#page" + pageNoToLoad).addClass("active");

    $("#TVadvert").empty().load("/ajax/" + movies[movies.length - 1] + ".html");
    $("#" + movies[movies.length - 1]).addClass("TVadvertLinksActive");

    $(".btnMovie").mouseover(function() {
        $(this).addClass("TVadvertLinksHover");
    });

    $(".headingLink").click(function() {
        $(".headingLink").removeClass("selected");
        $(this).addClass("selected");
    });

    $(".btnMovie").mouseout(function() {
        $(this).removeClass("TVadvertLinksHover");
    });

    $(".btnMovie").click(function() {
        $(".btnMovie").each(function() {
            $(this).removeClass("TVadvertLinksActive");
        });
        $(this).addClass("TVadvertLinksActive");
        var pagetoLoad = "/ajax/" + $(this).attr("id") + ".html";
        $("#TVadvert").load(pagetoLoad);
    });

    $("#navigation li a").click(function() {
        $("#navigation li a").removeClass("active");
        $(this).addClass("active");
        var pagetoLoad = "/ajax/" + $(this).attr("id") + ".html";

        $("#tabContent").load(pagetoLoad, function() {
            var newHeight = $("#tabContent").height() + 50 + "px"
            $("#tabs").height(newHeight);
        });
    });

    $("#page13").click(function() {
        var pagetoLoad = "/ajax/page13.html";
        $(".headingLink").removeClass("selected");
        $("#tabContent").load(pagetoLoad, function() {
            var newHeight = $("#tabContent").height() + 50 + "px"
            $("#tabs").height(newHeight);
        });
        var temp = "#tabs-13";
        url = "Default.aspx" + temp;
        window.location.replace(url);

    });

    $("#entryForm_txtEmail").blur(function() {
        $("#entryForm_txtName").val('');
        $("#entryForm_txtPhone").val('');
        $("#entryForm_chkPromo").attr('checked', false);
        $("#entryForm_selPrefStore").val(0);

        $.ajax({ type: "POST", async: false, url: "/WebService.asmx/checkEntry",
            data: "email=" + $("#entryForm_txtEmail").val() + "&competitionName=eatWiseGiftCard2",
            dataType: "xml",
            success: function(xml) {
                var returnOutput = $(xml).find('boolean').text()
                if (returnOutput == "true") {
                    showPopup('popupDuplicateEntry');
                } else {
                    $.ajax({ type: "POST", async: false, url: "/WebService.asmx/getEntrantDetails",
                        data: "email=" + $("#entryForm_txtEmail").val() + "&competitionName=eatWiseGiftCard",
                        dataType: "xml",
                        success: function(xml) {
                            $(xml).find('row').each(function() {
                                $("#entryForm_txtName").val($(this).find('name').text());
                                $("#entryForm_txtPhone").val($(this).find('phone').text());
                                var promo = $(this).find('promotionalEmails').text();
                                if (promo == "Yes") {
                                    $("#entryForm_chkPromo").attr('checked', true);
                                }
                                var prefStore = $(this).find('preferredStore').text();
                                if (prefStore > 0) {
                                    $("#entryForm_selPreferredStore").val(prefStore);
                                }
                            });
                        }
                    });
                }

            }
        });
        return false;

    });


    $("a.tipOverlay[title]").tooltip({

        // use single tooltip element for all tips
        tip: '#dynatip',
        // tweak the position
        offset: [25, 25],
        // use "slide" effect
        effect: 'slide',
        // one configuration property 
        position: "top center"
        // add dynamic plugin 
    }).dynamic({
        // customized configuration on bottom edge
        bottom: {
            // slide downwards
            direction: 'down',
            // bounce back when closed
            bounce: true
        }
    });

    $("a.tipOverlay2[title]").tooltip({

        // use single tooltip element for all tips
        tip: '#dynatip2',
        // tweak the position
        offset: [25, 25],
        // use "slide" effect
        effect: 'slide',
        // one configuration property 
        position: "top center"
        // add dynamic plugin 
    }).dynamic({
        // customized configuration on bottom edge
        bottom: {
            // slide downwards
            direction: 'down',
            // bounce back when closed
            bounce: true
        }
    });


});
function showPopup(divID) {
    $("#" + divID).show();
    $("#" + divID).css({ "top": $("#rComp").offset().top - 65, "left": $("#rComp").offset().left + 25 });
}
function closePopup(divID) {
    $("#" + divID).hide();
}