﻿/// <reference path="modernizr-1.7.js" />
/// <reference path="jquery-1.5.1-vsdoc.js" />


$(document).ready(function () {


    if (Modernizr.touch) {
        //alert("browser supports touch");

        $(document).ready(function () {
            $('#header ul').addClass('hide');
            $('#header').append('<div class="leftButton" onclick="toggleMenu()">Menu</div>');
        });
        function toggleMenu() {
            $('#header ul').toggleClass('hide');
            $('#header .leftButton').toggleClass('pressed');
        }

        /* ok we have a touch device so we will grab the touch events now */
        $("#menu ul li").click(function () {
            $(this).find("ul:first").show();
        });

        var xequence = {};

        xequence.persistentUI.handleTouchEnd = function (event) {
            var bottomPos = bar.offset().top;
            if (window.innerHeight < 600) {
                bottomPos += bar.height();
            }
            bar.css({ bottom: -bottomPos + "px" });
            bar.fadeIn(200);
        }

        bar.bind("touchmove touchstart", function (event) {
            if (!event.target.href) {
                bar.hide();
            } else {
                event.preventDefault();
            }
        });

        bar.bind("touchend", function (event) {
            if (event.target.href) {
                $(event.target).click();
                return false;
            }
        });

        stage.bind("touchmove", function (event) {
            if ($(event.target).parents("#persistent-bar").length == 0) {
                bar.hide();
            } else {
                return false;
            }
        });

        stage.bind("touchend", $.debounce(500, xequence.persistentUI.handleTouchEnd));

        stage.bind("orientationchange", function (event) {
            xequence.persistentUI.handleTouchEnd();
        });

    }
    else {
        //alert("browser does not support touch");
        //$('#blogControl').removeClass("hiddenDiv");
        //$('#blogControl').hide();
    }
});


