﻿var aniSpd01 = 800;
var aniSpd02 = 300;
var aniSpd03 = 4000;
var playMuSlider;

$(function() {

    if ($.browser.msie && $.browser.version <= 6) {
        $('.menu_arrow img:first').attr('src', '/images/arw_menu.gif');
    }

    $('option').each(function(i, e) {
        if ($(e).text() == 'International')
            $(e).remove();
    });

    //Bottom Bar
    //$('body').prepend("<div id='debug'></div>");

    var footerC;
    footerC = $('#footer_wrap').clone();
    $('body').append(footerC);
    var bbContentH = $('#content').height() + 50;
    var bbHeaderH = $('#header_wrap').height();
    var bbFooterH = $('#footer_wrap').height() + 75;
    var windowH = $(window).height();

    setBottomBar(footerC)
    window.onresize = function() { setBottomBar(footerC); };

    function setBottomBar(footer) {

        windowH = $(window).height();
        if ((bbContentH + bbHeaderH) <= (windowH - bbFooterH)) {
            footer.attr('style', 'bottom:0px; position:absolute');
            $('#footer_wrap').hide();
            footer.show();
        }
        else {
            footer.attr('style', '');
            $('#footer_wrap').show();
            footer.hide();
        }

    }


    // Specials Home
    $('.home_special_wrap:first').addClass('current');
    $('.home_special_arrow').css({ marginTop: 70 * (0 + 1) - 72 + 'px' });
    $('.hSimgC:first').fadeIn(aniSpd01);

    playMuSlider = window.setInterval(function() {
        $('.home_view_specials a.Next').click();
    }, aniSpd03);

    $('.muSlider').mouseenter(function(e) {
        window.clearInterval(playMuSlider);
    });

    $('.muSlider').mouseleave(function(e) {
        playMuSlider = window.setInterval(function() {
            $('.home_view_specials a.Next').click();
        }, aniSpd03);
    });


    $('.home_special_wrap:not(.current)').live('click', function(e) {
        e.preventDefault();
        var cA = '.hSimgC';
        var cS = '.hSimgC:eq(' + (parseInt($(this).index()) - 1) + ')';
        $('.home_special_wrap').removeClass('current');

        //$('.home_special_arrow').css({ marginTop: 70 * parseInt($(this).index()) - 72 + 'px' });
        $('.home_special_arrow').animate({ marginTop: 70 * parseInt($(this).index()) - 72 + 'px' }, { duration: aniSpd02, queue: false, easing: 'easeInOutQuad' });

        $(cA).fadeOut(aniSpd01);
        $(cA).css('z-index', '10');
        $(cS).css('z-index', '0');
        $(cS).fadeIn({ duration: aniSpd01, easing: 'easeInOutQuad', queue: true });

        $(this).addClass('current');
    });

    $('.home_view_specials a.Next').click(function(e) {
        e.preventDefault();
        var totI = $('.hSimgC').length;
        var curI = $('.home_special_wrap.current').index();

        if (curI >= totI) curI = 0;

        var cA = '.hSimgC';
        var cS = '.hSimgC:eq(' + curI + ')';
        $('.home_special_wrap').removeClass('current');

        $(cA).fadeOut(aniSpd01);
        $(cA).css('z-index', '10');
        $(cS).css('z-index', '0');
        $(cS).fadeIn({ duration: aniSpd01, easing: 'easeInOutQuad', queue: true });

        $('.home_special_wrap:eq(' + curI + ')').addClass('current');
        $('.home_special_arrow').css({ marginTop: 70 * parseInt(curI + 1) - 72 + 'px' });
    });

    $('.home_view_specials a.Prev').click(function(e) {
        e.preventDefault();
        var totI = $('.hSimgC').length;
        var curI = $('.home_special_wrap.current').index();
        var prevI = 0;

        prevI = curI - 2;
        if (prevI < 0) prevI = totI - 1;

        var cA = '.hSimgC';
        var cS = '.hSimgC:eq(' + prevI + ')';
        $('.home_special_wrap').removeClass('current');

        $(cA).fadeOut(aniSpd01);
        $(cA).css('z-index', '10');
        $(cS).css('z-index', '0');
        $(cS).fadeIn({ duration: aniSpd01, easing: 'easeInOutQuad', queue: true });

        $('.home_special_wrap:eq(' + prevI + ')').addClass('current');
        $('.home_special_arrow').css({ marginTop: 70 * parseInt(prevI + 1) - 72 + 'px' });
    });

    //Restaurant Locator - Advanced Search
    $('#rlAsBtn').click(function(e) {
        e.preventDefault();
        var storeSpecs = "";
        storeSpecs += $('.slChk1').is(':checked') ? "1" : "0";
        storeSpecs += ",";
        storeSpecs += $('.slChk2').is(':checked') ? "1" : "0";
        storeSpecs += ",";
        storeSpecs += $('.slChk3').is(':checked') ? "1" : "0";
        storeSpecs += ",";
        storeSpecs += $('.slChk4').is(':checked') ? "1" : "0";
        storeSpecs += ",";
        storeSpecs += $('.slChk5').is(':checked') ? "1" : "0";
        storeSpecs += ",";
        storeSpecs += $('.slChk6').is(':checked') ? "1" : "0";

        $.ajax({
            type: 'GET',
            url: '/rLaS-' + new Date().getTime(),
            data: 'v=' + new Date().getTime() + '&kW=' + $('#txt_Keywords').val() + '&pV=' + $('.ddlProvinceRight option:selected').val() + '&sS=' + storeSpecs,
            success: function(r) {
                if (r != "") {
                    $('#rLc div:first').fadeOut(500, function() {
                        $('#rLc div:first').html(r);
                        $('#rLc div:first').fadeIn(500);
                        if ($('.ddlProvinceRight option:selected').val() != "0") {
                            $('.menu_arrow').show();
                            $('.rlCurrentProvince').text($('.ddlProvinceRight option:selected').text());
                            $('#menu div').removeClass('current');
                            setCurrentLeftNav($('.ddlProvinceRight option:selected').text().replace(/ /gi, ''));
                        }
                        else {

                            $('.menu_arrow').hide();
                            $('#menu div').removeClass('current');
                        }
                    });
                }
            },
            error: function(r) { alert("Error has occurred, please try again."); }
        });

    });

    //Submit Newsletter
    $('.btnNewsletterSubmit').click(function(e) {
        e.preventDefault();

        var frmVals = "";
        frmVals += '&txtFirstName=' + $('.txtFullname').val().split(' ')[0];
        frmVals += '&txtSurname=' + $('.txtFullname').val().split(' ')[1];
        frmVals += '&txtContactNumber=' + $('.txtContactNumber2').val() + ', ' + $('.txtContactNumber').val();
        frmVals += '&txtEmail=' + $('.txtEmail').val();
        frmVals += '&ddlProvinces=' + $('.ddlProvinces option:selected').val();
        frmVals += '&ddlDOBdd=' + $('.ddlDOBdd option:selected').val();
        frmVals += '&ddlDOBddT=' + $('.ddlDOBdd option:selected').text();
        frmVals += '&ddlDOBmm=' + $('.ddlDOBmm option:selected').val();
        frmVals += '&ddlDOBmmT=' + $('.ddlDOBmm option:selected').text();
        frmVals += '&ddlDOByyyy=' + $('.ddlDOByyyy option:selected').val();
        frmVals += '&ddlDOByyyyT=' + $('.ddlDOByyyy option:selected').text();

        $.ajax({
            type: 'GET',
            url: '/cPnLt-' + new Date().getTime(),
            data: 'v=' + new Date().getTime() + frmVals,
            success: function(r) {
                if (r != "1")
                    showResp('.signup_form_error', '.signup_form', true);
                else {
                    showResp('.signup_form_confirm', '.signup_form', false);

                    var axel = Math.random() + "";
                    var a = axel * 10000000000000;
                    $.ajax({
                        type: 'GET',
                        url: 'http://fls.doubleclick.net/activityi;src=2526715;type=panar962;cat=newsl220;ord=1;num=' + a + '?',
                        data: '',
                        success: function(r) { },
                        error: function(r) { }
                    });
                }
            },
            error: function(r) { showResp('.signup_form_error', '.signup_form', true); }
        });

    });

    //Submit Newsletter
    $('.btnContactUsSubmit').click(function(e) {
        e.preventDefault();

        var frmCVals = "";
        frmCVals += '&txtFirstName=' + $('.ctxtFirstname').val();
        frmCVals += '&txtSurname=' + $('.ctxtSurname').val();
        frmCVals += '&txtContactNumber=' + $('.ctxtContactNumber').val();
        frmCVals += '&txtEmail=' + $('.ctxtEmail').val();
        frmCVals += '&ddlProvinces=' + $('.cddlProvinces option:selected').text();
        frmCVals += '&ddlSubject=' + $('.cddlSubject option:selected').text();
        frmCVals += '&txtComments=' + escape($('.ctxtComment').val());


        $.ajax({
            type: 'GET',
            url: '/cPcUf-' + new Date().getTime(),
            data: 'v=' + new Date().getTime() + frmCVals,
            success: function(r) {
                if (r != "1")
                    showResp('.emailus_form_error', '.emailus_form', true);
                else {
                    showResp('.emailus_form_confirm', '.emailus_form', false);

                    var axel = Math.random() + "";
                    var a = axel * 10000000000000;                    $.ajax({
                    type: 'GET',
                        url: 'http://fls.doubleclick.net/activityi;src=2526715;type=panar962;cat=conta728;ord=1;num=' + a + '?',
                        data: '',
                        success: function(r) {},
                        error: function(r) { }
                    });
                    
                }
            },
            error: function(r) { showResp('.emailus_form_error', '.emailus_form', true); }
        });

    });

    //Set Menu Icons
    //menuIcons [name.h]
    var iconImgsV = '<img alt="Vegetarian" src="/images/ico_v.gif">';
    var iconImgsH = '<img alt="Heart and Stroke Foundation Approved" src="/images/ico_h.gif"/>';
    var iconImgsN = '<img alt="Contains Nuts" src="/images/ico_n.gif"/>';
    $('.menuIcons').each(function(i, e) {
        var iconImgs = '';
        if ($(e).text().toString().indexOf('v') > -1) {
            iconImgs += iconImgsV;
        }
        if ($(e).text().toString().indexOf('h') > -1) {
            iconImgs += iconImgsH;
        }
        if ($(e).text().toString().indexOf('n') > -1) {
            iconImgs += iconImgsN;
        }
        if (iconImgs != '')
            $(e).html(iconImgs + '<br/>');
    });

});

//Set Background Resizer
function setBG(imageURL) {
    $(function() {
        //Remove background for IE6 and lower
        if ($.browser.msie && $.browser.version <= 6) {
            $("#body-background-throbber").remove();
            $("#body-background").remove();
            $("body").css('background', 'none');

            //$("body").css('background-image', 'url(' + imageURL + ')');
            //$("body").css('background-position', 'center');
            //$("body").css('background-repeat', 'repeat-y');


            //            $('#body-background').attr('style', 'visibility: visible; position: fixed; top: 0px; left: 0px; z-index: -1; overflow: hidden; width: ' + $(window).width() * 1.2 + 'px; height: ' + $(window).height() * 1.2 + 'px;');
            //            $('#body-background img').attr('style', 'display:block; width: ' + $(window).width() * 1.2 + 'px; height: ' + $(window).height() * 1.5 + 'px;');
            //            $("#body-background img").attr('src', imageURL);
        }
        else { //Add background
            var img = new Array()
            img.push(""); // do this to fill the img[0] position
            img.push(imageURL);
            var ran = randomMinToMax(1, img.length - 1);

            var _img = new Image();
            _img.src = img[ran];
            $(_img).hide();
            $(_img).load(function() {
                $("#body-background-throbber").hide();
                //$(this).fadeIn();
                $(this).show();
            });

            $("#body-background").append(_img);
            $("#body-background").ezBgResize();

        }
    });
}

function setCurrentTopNav(buttonText) {
    $(function() {

        $('#navigation a').each(function(i, e) {
            if ($(e).text().toLowerCase().replace(/ /gi, '').replace(/-/gi, '') == buttonText.toLowerCase().replace(/ /gi, '').replace(/-/gi, ''))
                $(e).addClass('current');
        });
    });
}

function setCurrentLeftNav(buttonClass) {
    $(function() {
        if (buttonClass != '') {
            if ($('#menu').length) {
                $('#menu .' + buttonClass).addClass('current');

                var sLNav = $('#menu .current');

                $('.menu_arrow').css({
                    'height': sLNav.height() + 'px',
                    'top': sLNav.position().top - 2 + 'px',
                    'left': sLNav.position().left + 'px',
                    'position': 'absolute'
                });
                $('.menu_arrow img').css({
                    'width': '14px',
                    'height': sLNav.height() - 1 + 'px'
                });
            }
        }
    });
}

window.onresize = function() {
    $(function() {
        try {
            $('.menu_arrow').css('left', $('#menu .current').position().left + 'px');
        }
        catch (Error) { }
    });
};



// Default text value function
function OnFocus(elementId, defaultText) {
    if (document.getElementById(elementId).value == defaultText) {
        document.getElementById(elementId).value = "";
    }
}

function OnBlur(elementId, defaultText) {
    var textValue = document.getElementById(elementId).value;

    if (textValue == defaultText || textValue.length == 0) {
        document.getElementById(elementId).value = defaultText;
    }
}


//showContent function
function showContent(id) {
    if ($("#" + id + "_content").is(":visible")) return;
    $("img[src*='/images/ico_open.gif']").attr('src', '/images/ico_closed.gif');
    $("div[id*='_content']:visible").slideUp(aniSpd01);
    $("#" + id + "_content").slideDown(aniSpd01, "easeOutQuad");
    $("#" + id + " img").attr('src', '/images/ico_open.gif');
}

function slideit(str) {
    $(str).slideDown(aniSpd01, "easeOutQuad");
}

function randomMinToMax(min, max_v) {
    var range = max_v - min + 1;
    return Math.floor(Math.random() * range + min);
}

//Widget Submit Response
function showResp(itemToShow, itemToHide, newItemTemp) {
    $(function() {
        $(itemToHide).hide();
        $(itemToShow).fadeIn(aniSpd01);

        if (newItemTemp) {
            $(itemToShow).delay(2000).fadeOut(aniSpd01, function() { $(itemToHide).show(); });
        }
    });
}


//GALLERY
var muAniSpd = 300;
$(function() {


    //Item Hover Effect
    $('.muPagingItem').mouseenter(function(e) {
        e.preventDefault();
        $('.cItemTmp').fadeOut(300, $('.cItemTmp').remove());
        var cI = $(this);
        var cIc = $(this).clone();
        var rX = cI.position().left;
        var rY = cI.position().top;
        cIc.addClass('cItemTmp');
        cIc.addClass('shadowBox');
        cIc.css({
            'position': 'absolute',
            'left': rX,
            'top': rY,
            'z-index': '50'
        });
        //cIc.find('.galOv').remove();
        cI.prepend(cIc);
        //cI.find('.galOv').fadeOut(muPagingAniSpd);

        if (!$.browser.msie) {
            cIc.animate({ left: rX - 20, top: rY - 20 }, { queue: false, duration: muAniSpd });
            cIc.find('img:first').animate({ width: $(this).width() + 40 }, { queue: false, duration: muAniSpd });

        } else {
            //Static Hover
            cIc.css({ 'left': rX - 20 + 'px', 'top': rY - 20 + 'px' });
            cIc.find('img:first').css({ 'width': $(this).width() + 40 + 'px' });
        }
    });

    $('.box_wrap_2').mouseleave(function(e) {
        $('.cItemTmp').fadeOut(300, $('.cItemTmp').remove());
    });

    //Set margins for items [Custom for page]
    $('.muPagingSet').each(function(ii, ee) {
        $(ee).find('a').each(function(i, e) {
            if ((i % 3) == 0 && i != 0) {
                $(e).prev().removeClass('img_1');
                $(e).prev().addClass('img_2');
            }
        });
    });
    //$('.img_1').css('margin-bottom', '0px');



    //if ($.browser.msie)
    //$('.galOv').remove();
});


