﻿// Check that the page has loaded
$(document).ready(function () {

    // About us dropdown   
    $('.mainNav LI:eq(1)').hover(
        function () {
            // Show dropdown
            $('#mainNav .aboutUs').show();
        },

        function () {
            // Hide dropdown
            $('#mainNav .aboutUs').hide();
        });

    $('.mainNav LI:eq(4)').hover(
        function () {
            // Show dropdown
            $('#mainNav .instructors').show();
        },

        function () {
            // Hide dropdown
            $('#mainNav .instructors').hide();
        });

    $('#mainNav .aboutUs').hover(
        function () {
            // Show dropdown
            $(this).show();
        },

        function () {
            // Hide dropdown
            $(this).hide();
        });
    $('#mainNav .instructors').hover(
        function () {
            // Show dropdown
            $(this).show();
        },

        function () {
            // Hide dropdown
            $(this).hide();
        });

    // Remove border for last dropdown
    $('.dropdown LI:last A').css({ border: 'none' });


    // Homepage quick links rollover
    $('#homeQuicklinks .quicklink').hover(

    // Mouseover
        function () {
            $(this).find('.tooltip').dequeue().css("bottom", 110).css("opacity", null).css("display", "none");
            $(this).find('.quicklinkTitle').css({ backgroundPosition: '0 -30px' });
            $(this).find('.tooltip').animate({ bottom: 110 }, 0).animate({ bottom: 120, opacity: 'show' }, 300);
        },

    // Mouseout
        function () {
            $(this).find('.quicklinkTitle').css({ backgroundPosition: '0 0' });
            $(this).find('.tooltip').animate({ bottom: 140, opacity: 'hide' }, 300).animate({ bottom: 110 }, 0);

        }
    );

    // Product page gallery
    $('.productDetailsGallery .thumbnail A').click(function () {

        // Find out which image to load
        var img = $(this).attr('href');

        // Change image
        $('.productDetailsGallery .mainImg IMG').attr('src', img);

        // Remove 'selected' from all thumbnails
        $('.productDetailsGallery .thumbnail').removeClass('selected');

        // Add 'selected' to correct thumbnail
        $(this).parent('.thumbnail').addClass('selected');

        return false;
    });

    // Bottom alignment for product description
    var heightLeft = '340';
    var heightRight = $('.productDetailsDesc').height();
    var marginBottom = heightLeft - heightRight;

    //$('#bottomArea').css({marginTop: marginBottom });

    for (var count = 0; count < 20; count++) {
        setTimeout("resetInputs()", 50 * count);
    }
    timer = setInterval("resetInputs()", 250);


    $('#header .btn_login').live('click', function () {

        $.ajax({

            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            responseType: 'json',

            url: 'https://www.ausphysio.com/handlers/app.aspx/login',
            data: '{"d": {"email": "' + $('#txt_email').val() + '","password": "' + $('#txt_password').val() + '"}}',
            success: function (data) {
                if (data.d.indexOf('Error') > -1) {
                    $('#header .errors').html('<div class="loginerrors"><div class="EcomErrors"><div>* Incorrect email or password.</div></div><a class="btn_forgot" href="/account/password.aspx"></a></div>');
                } else {
                    $('#accountHolder').html(data.d);
                    top.location.reload();
                }
            }
        });

        return false;

    });

    $('.btn_logout').live('click', function () {

        var cookie_date = new Date();  // current date & time
        cookie_date.setTime(cookie_date.getTime() - 1);
        document.cookie = "TviEcom=;expires=" + cookie_date.toGMTString();

        $.ajax({

            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            responseType: 'json',

            url: '/handlers/app.aspx/logout',
            success: function (data) {
                $('#accountHolder').html(data.d);
            }
        });

        return false;

    });



});

function resetInputs(){
    $('input').css("background-color", "white");
    $('.form').find('input').css("background-color", "#f5fafb");
    $('.TVI-form').find('input').css("background-color", "transparent");
}

function clear_checkboxes(myID) {
    var frm = document.forms[0];
    for (i = 0; i < frm.length; i++) {
        if (frm.elements[i].id != myID) {
            if (frm.elements[i].id.indexOf('cb') != -1) {
                frm.elements[i].checked = false;
            }
        }
    }
}
