/* Declare a namespace for the site */
var Site = window.Site || {};
function scaleit () {
	var img = $("#pic-bg img:first");
    function scale (dimensionToScale, scale) {
    	return scale * dimensionToScale;
    }
    //Cache the image element.

    var iH = img.height();
    var iW = img.width();
    //Grab the standard dimensions of everything
    var wW = $(window).width();
    var wH = $(window).height();


    //Return early if the image is already properly sized.
    if (!(((iH < wH || iW < wW) || (iH > wH && iW > wW)) && (iH > 0 && iW > 0)))
    {
    	return;
    }	

    //Determine how many of our image could tile inside of the window.
    var highestScale;
    var widthScale = wW / iW;
    var heightScale = wH / iH;

    //Determine which dimension's scale is higher.
	if (widthScale > heightScale) {
		highestScale = widthScale;
	} else {
		highestScale = heightScale;
	}


    //Function for quickly determining pixels for the provided scale.

    //Calculate the new width and height based on this greater scale.
    newWidth = scale(iW, highestScale);
    newHeight = scale(iH, highestScale);

    //Set the CSS of the image. Centering it in the window, and making sure there is never a boundry inside of the window border.
    img.css({
    	width:newWidth.toString()+"px",
    	height:newHeight.toString()+"px",
		top:((0 - (newHeight / 2)) + (wH / 2)).toString() + "px",
		left:((0 - (newWidth / 2)) + (wW / 2)).toString() + "px"
    });
}
/* Create a closure to maintain scope of the '$'
   and remain compatible with other frameworks.  */
(function($) {
	
	//same as $(document).ready();
	$(function() {
		
		  // for the home page script
		  jQuery(".homebox").hide();
		  //toggle the componenet with class msg_body
		  jQuery(".heading").click(function()
		  {
			jQuery(this).next(".homebox").slideToggle(500);
		  });
        
	});


	$(window).bind("load", function() {
		
        //slides the element with class "menu_body" when mouse is over the paragraph
        $("#content article.what h1").click(function()
        {
             $(this).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
        });
	    scaleit();
	});

    var _tmr = null;
	$(window).resize(function() {
        if (_tmr) {
            clearTimeout(_tmr);
        }
        _tmr = setTimeout(scaleit, 25);
    });

})(jQuery);


// GOOGLE ANALYTICS
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22398585-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


/*    $(document).ready(function()
    {
        //slides the element with class "menu_body" when mouse is over the paragraph
        $("#content article.what h1").mouseover(function()
        {
             $(this).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
        });
    });
*/
