//This file is for tracking initial browser size when a page loads and subsequent user resize actions

//browser width, browser height 
function getWidthAndHeight()
{
	var w, h, str; //browser width, height (this improved check method via http://css-tricks.com/screen-resolution-notequalto-browser-window/ @Chilla42o comment
	if (document.body && document.body.offsetWidth)
	{
		w = document.body.offsetWidth;
		h = document.body.offsetHeight;
	}
	if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth ) 
	{
		w = document.documentElement.offsetWidth;
		h = document.documentElement.offsetHeight;
	}
	if (window.innerWidth && window.innerHeight) 
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	
	str = w + "x" + h;
	return str;
}

//initial check
function checkInitialSize()
{
	//ga
	try {
		var pageTracker = _gat._getTracker("UA-9488561-1");
		pageTracker._trackEvent("Browser Dimensions", "Initial Size", getWidthAndHeight());
		} catch(err) {}
}

//resize (this resize bind method via http://stackoverflow.com/questions/2996431/javascript-detect-when-a-window-is-resized)
$(window).resize(function()
{
	if(this.resizeTO) 
		clearTimeout(this.resizeTO);
		
	this.resizeTO = setTimeout(function() 
	{
		$(this).trigger('resizeEnd');
	}, 500);
});

//resize bind
$(window).bind('resizeEnd', function()
{
	//ga
	try {
		var pageTracker = _gat._getTracker("UA-9488561-1");
		pageTracker._trackEvent("Browser Dimensions", "Resize", getWidthAndHeight());
		} catch(err) {}
});
