﻿$().ready(function () {
    //min-height
    var src = $('#sidebar img').attr('src');
    var image = new Image();
    image.onload = function () {
        SnapMailAndLeft();
    }
    image.src = src;

	//initial backgroudn animation
	SnapMailAndLeft();
  
  //head-hover
	$(".logo").hover(function () {
        $(this).children("div").stop()
					  .animate({ height: "68" }, 200);
    }, function () {
      $(this).children("div").stop()
					  .animate({ height: "0" }, 200);
    });
	
    //nav-hover
	$(".nav li").not($(".active")).children("a").hover(function () {
        $(this).next().stop()
					  .animate({ height: "34" }, 200);
    }, function () {
        $(this).next().stop()
					  .animate({ height: "0" }, 200);
    });

    //footer-mav-hover
    $(".footer-nav li a").hover(function () {
        $(this).next().stop()
					  .animate({ height: "34" }, 200);
    }, function () {
        $(this).next().stop()
					  .animate({ height: "0" }, 200);
    });

    //radio-checked
    $(".radio-container p input").bind('change', function () {
        if ($(this).attr('checked') == true) {
            $(this).next().addClass("checked");
        }
        else {
            $(this).next().removeClass("checked");
        }
    })
    $(".radio-container p input").trigger('change');
    $(".radio-container p span").bind('click', function () {
        $(this).prev().attr('checked', true);
        $(".radio-container p input").trigger('change');
    });
  
    setTimeout("adjustPageHeight()",50);
});

// main--->min-height
function SnapMailAndLeft(){
	var height = $("#sidebar").height();
	$("#main").css("min-height", height);
	
	//nav-li-width
	$(".nav li div").each(function(){
	    $(this).width("100%");					   
	});
	
	//footer-nav-li-width
	$(".footer-nav li div").each(function(){
	    $(this).width($(this).parent().width());					   
	});
	
	//btn-hover
	$(".btn").hover(function () {
	    $(this).css("color", "#fff");
	    var btnWidth = $(this).parent().width();
	    $(this).next().stop().animate({ width: btnWidth }, 200);

	}, function () {
	    $(this).css("color", "#002F52");
	    $(this).next().stop().animate({ width: "0" }, 200);
	});
	
	//child-nav-hover
	$(".child-nav li").not($(".active")).children("a").hover(function () {
	    $(this).css("color", "#fff");
	    var btnWidth = $(this).parent().width();
	    $(this).children("span").addClass("mouseover").removeClass("mouseout");
	    $(this).next().stop().animate({ width: btnWidth }, 200);

	}, function () {
	    $(this).css("color", "#002F52");
	    $(this).children("span").addClass("mouseout").removeClass("mouseover");
	    $(this).next().stop().animate({ width: "0" }, 200);
	});
};

function adjustPageHeight(){
	var windowHeight = $(window).height();
	var headerHeight = $('#header').height();
	var mainContainerHeight = $('#main-container').height();
	if(windowHeight >= $(document).height()){
		$('#footer').css('min-height',windowHeight - headerHeight - mainContainerHeight - 53);
	}
}

