var myWidth = 0;
function sizeMe() {
   myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  $('#largeImage').css('width:',myWidth);
  $('#largeImage').css('height',myHeight);


}

function setBasePx() {
  if ((myWidth<1000))
    {
       alert("Small screen detected\nPlease note that all boxes are draggable.");
    }
    
}



function setFont(){
if (navigator.appVersion.indexOf("Mac")!=-1){
        $("body").css("font-family",'helvetica');
    };
}

$(document).ready(function(){
    sizeMe();
    setFont();
    window.onresize=sizeMe;
    document.onresize=sizeMe;
    setBasePx();
    

    $(".draggable").draggable({
        cursor: 'move',
        drag: function(event, ui) {
            var layer =$("#zindexcounter").attr('class');
            $(this).css("z-index",layer);
            layer++;
            $("#zindexcounter").attr('class',layer);}
    });

    // Highlight Link
    $(".menuLink").live("click",function () {
       $(".menuLink").removeClass("linkSelected");
       $(this).addClass("linkSelected");
       resetClasses();
     
    });

    // Highlight subLink
    $(".sublink").live("click",function () {
       $(".sublink").removeClass("sublinkSelected");
       $(this).addClass("sublinkSelected");
       resetClasses();
    });

    // Why Pilates submenu
    $("#whypilates").live("click",function () {
       snap();
       if( $("#showclasses").is(":visible") ) {
            $("#showclasses").hide("slow");
       }
       $(".hidden_window").fadeOut("fast");
       $("#window_why").fadeIn("fast");
    });

    // Why Pilates submenu
    $("#prices").live("click",function () {
       snap();
       if( $("#showclasses").is(":visible") ) {
            $("#showclasses").hide("slow");
       }
       $(".hidden_window").fadeOut("fast");
       $("#window_prices").fadeIn("fast");
    });

    $("#links").live("click",function () {
       snap();
       if( $("#showclasses").is(":visible") ) {
            $("#showclasses").hide("slow");
       }
       $(".hidden_window").fadeOut("fast");
       $("#window_links").fadeIn("fast");
    });

    // Ourclasses submenu
    $("#ourclasses").live("click",function () {
       snap();
       
       if( $("#showclasses").is(":visible") ) {
            $("#showclasses").hide("slow");
       }else{
            $("#showclasses").show("slow");
       }

       if( !$("#window_ourclass").is(":visible") ) {
           $(".hidden_window").fadeOut("fast");
           $("#window_ourclass").fadeIn("fast");
       }
       
    });

    $("#sub_window_mat").live("click",function () {
        $(".hidden_window").fadeOut("fast");
        $("#window_mat").fadeIn("fast");
    });

    $("#sub_window_equipment").live("click",function () {
        $(".hidden_window").fadeOut("fast");
        $("#window_equipment").fadeIn("fast");
    });

    $("#sub_window_prenatal").live("click",function () {
        $(".hidden_window").fadeOut("fast");
        $("#window_prenatal").fadeIn("fast");
    });

    $("#sub_window_gyrotonic").live("click",function () {
        $(".hidden_window").fadeOut("fast");
        $("#window_gyrotonic").fadeIn("fast");
    });

    $("#sub_window_powerplate").live("click",function () {
        $(".hidden_window").fadeOut("fast");
        $("#window_powerplate").fadeIn("fast");
    });

    $("#sub_window_children").live("click",function () {
        $(".hidden_window").fadeOut("fast");
        $("#window_children").fadeIn("fast");
    });

    $("#schedule").live("click",function () {
        $(".blackBox").fadeOut("fast");
        $("#window_schedule").fadeIn("fast");
    });

    $("#workshop").live("click",function () {
        $(".blackBox").fadeOut("fast");
        $("#window_workshop").fadeIn("fast");
    });

    function resetClasses(){
        $("#window_prices,#window_links,#window_why,#window_ourclass,#window_mat,#window_equipment,#window_prenatal,#window_gyrotonic,#window_powerplate,#window_children").animate({
        left: "22.5em", top:"1.6777em"}, { duration: 200, queue: false });
    }
    

    // Reset z-indecies
    function resetZindex(){
        $(".blackBox").css('z-index',2);
        $("#contentBox").css('z-index',2);
        $("#zindexcounter").attr('class',3);
    }

    // Click Home
    $("#home").live("click",function () {
       resetDivs();
       resetZindex();
       $(".hidden_window").fadeOut("fast");
       $("#window_home").fadeIn("fast");
    });

    $(".scheduleCloser,#scheduleCloserText").live("click",function () {
       resetDivs();
       resetZindex();
       $(".hidden_window").fadeOut("fast",
            function(){ $("#logoBox,#menuBox,#addressBox,#window_home").fadeIn("fast");
            $(".menuLink").removeClass("linkSelected");
            $("#home").addClass("linkSelected");
            }
        );

       
    });



    // When we click close
    $(".closer").live("click",function () {
       $(".hidden_window").fadeOut("fast");
       });

    // When we click home
    $("#schedule").live("click",function () {
        if( $("#showclasses").is(":visible") ) {
            $("#showclasses").hide("slow");
       }

    });
    
    

    function snap(){
        $("#logoBox").animate({
        left: "1.6777em", top:"1.6777em"}, { duration: 500, queue: false});

        $("#menuBox").animate({
        left: "1.6777em", top:"22.5em"}, { duration: 500, queue: false });

        $("#addressBox").animate({
        left: "1.6777em", top:"43.333em"}, { duration: 500, queue: false });

        $(".submenuLink").hide("fast");

        $(".sublink").removeClass("sublinkSelected");

    }

    
    // When we click  sublinks
    $(".sublink").live("click",function () {
    });

    

        
        
    
});
