// Utils
function get(el){return document.getElementById(el);}
function windowProperties(type){
  var myWidth = 0, 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;
  }
  if (type == "height"){
	  return myHeight;
  }
  else {
	  return myWidth;
  }
}
function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}
var aplicado = false; 
// Popup
function showPopup(type){
	switch(type){
		case 'popupSeeTheFastest':
		case 'popupAvailability':
			get('popupClock').style.display = 'block';
			get('popupClock').style.visibility = 'visible';
			get('popup').setAttribute('class','small');
			get('popup').className = 'small';
		break;
		default:
			window.open('http://comcast.cellmaps.com/viewer.html','cellmaps','toolbar=0,location=0,resizable=1,height=505,width=871');
			//window.open('http://comcast.cellmaps.com/viewer.html','_blank');
			//get('popup').setAttribute('class','null');
			//get('popup').className = 'null';
			//get('popupClock').style.visibility = 'hidden';
			//get('popupClock').style.display = 'none';
			return;
		break;
	}
	get('popupContent').innerHTML = get(type).innerHTML;
	shadowAdjust();
	popupAdjust();
	get('shadow').style.display = 'block';
	get('popup').style.display = 'block';
}
function popupCloseButton(ev){
	get('shadow').style.display = 'none';
	get('popup').style.display = 'none';
	return false;
}
function shadowAdjust(){
	sWidth = windowProperties('width');
	sHeight = windowProperties('height');
	get('shadow').style.width = sWidth + 'px';
	get('shadow').style.height = sHeight + 'px';
};
// On resize event
popupAdjust = function(){
	pWidth = parseInt(getStyle(get('popup'),'width'));
	xcenter = windowProperties('width') / 2 - (pWidth / 2);
	get('popup').style.left = xcenter + 'px';
	shadowAdjust();
};
// Onload event
function onloadPage(){
	get('popupCloseButton').onclick = popupCloseButton;
	get('shadow').onclick = popupCloseButton;
	shadowAdjust();
	popupAdjust();
	//showPopup('popupSeeHowFast');
	//showPopup('popupSeeTheFastest');
	//showPopup('popupAvailability');
	//showPopup('popupCoverageMap');
}
window.onload = onloadPage;
window.onresize = popupAdjust; 
window.onscroll = popupAdjust; 
