// JS Document
 
var myWidth = 0, myHeight = 0, myScroll = 0; myScrollWidth = 0, myScrollHeight = 0;
var imgLoader = document.createElement("img"), loaderDisplay = false, spin = 1;
  
function getSize() {
	
	// Window Size

    if (self.innerHeight) { // Everyone but IE
    	myWidth = window.innerWidth;
    	myHeight = window.innerHeight;
    	myScroll = window.pageYOffset;
    } else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict
    	myWidth = document.documentElement.clientWidth;
    	myHeight = document.documentElement.clientHeight;
    	myScroll = document.documentElement.scrollTop;
    } else if (document.body) { // Other IE, such as IE7
    	myWidth = document.body.clientWidth;
    	myHeight = document.body.clientHeight;
    	myScroll = document.body.scrollTop;
    }

    // Page size w/offscreen areas

    if (window.innerHeight && window.scrollMaxY) {	
    	myScrollWidth = document.body.scrollWidth;
    	myScrollHeight = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac
    	myScrollWidth = document.body.scrollWidth;
    	myScrollHeight = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    	myScrollWidth = document.body.offsetWidth;
    	myScrollHeight = document.body.offsetHeight;
    }
}
	
function findPosX(obj) {
  var curleft = 0;
  if(obj.offsetParent)
      while(1) {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.x)
      curleft += obj.x;
  return curleft;
}

function findPosY(obj) {
  var curtop = 0;
  if(obj.offsetParent)
      while(1) {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.y)
      curtop += obj.y;
  return curtop;
}

function createLoader() {

	var inBody = document.getElementsByTagName('body').item(0);
	
	imgLoader.setAttribute('id', 'imgLoader');
	imgLoader.style.position = 'absolute';
	imgLoader.style.zIndex = '2000';
	imgLoader.style.top = '0';
	imgLoader.style.left = '0';
	
	inBody.appendChild(imgLoader);
	
	Element.hide('imgLoader');
	
	runLoader();
}

function runLoader() {
	if (loaderDisplay) {
		if ($('imgLoader').style.display == 'none') { 
			Element.show('imgLoader');
		}
		imgLoader.src = 'http://boston.barstoolsports.com/caddyconfessions/img/zoom/zoom-spin-'+spin+'.png';
		if (spin < 12) {
			spin++;
		} else {
			spin = 1;
		}
	} else {
		if ($('imgLoader').style.display == '') { 
			Element.hide('imgLoader');
		}
	}
	setTimeout('runLoader()', 100);
}

function inputFocus(id, def) {
	if ($(id).value == def) {
		$(id).value = '';
	}
}

function inputBlur(id, def) {
	if (($(id).value == '') || ($(id).value == def)) {
		$(id).value = def;
		$(id).className = '';
	} else {
		$(id).className = 'set';
	}
}

function showTheBox() {
	getSize();
    $("blackBg").style.width = myWidth+'px';
    $("blackBg").style.height = (myHeight+myScroll)+'px';
    $("closeBox").style.left = (Math.ceil(myWidth / 2) - 265) + 'px';
    $("closeBox").style.top = (myScroll+60)+'px';
    $("dispElement").style.left = (Math.ceil(myWidth / 2) - 250) + 'px';
    $("dispElement").style.top = (myScroll+75)+'px';
    Element.show('blackBg');
    Element.show('dispElement');
    Element.show('closeBox');
}

function closeTheBox() {
    Element.hide('blackBg');
    Element.hide('dispElement');
    Element.hide('closeBox');
    if ($('imgFlyOut') != null) {
    	document.getElementsByTagName('body').item(0).removeChild($('imgFlyOut'));
    }
}

function setUpMask() {

   	var inBody = document.getElementsByTagName('body').item(0);
	
	var maskBg = document.createElement("div");
	maskBg.setAttribute('id', 'blackBg');
	maskBg.style.position = 'absolute';
	maskBg.style.zIndex = '999';
	maskBg.style.left = '0';
	maskBg.style.top = '0';
	maskBg.className = 'blackBg';
	maskBg.onclick = closeTheBox;
	
	var disp = document.createElement("div");
	disp.setAttribute('id', 'dispElement');
	disp.style.position = 'absolute';
	disp.style.zIndex = '1000';
	disp.style.left = '0';
	disp.style.top = '0';
	disp.style.width = '500px';
	disp.className = 'dispElement';
	
	var close = document.createElement("div");
	close.setAttribute('id', 'closeBox');
	close.style.position = 'absolute';
	close.style.zIndex = '1001';
	close.style.left = '0';
	close.style.top = '0';
	close.className = 'closeBox';
	close.onclick = function() {
	    closeTheBox()
	};
	
	inBody.appendChild(maskBg);
	inBody.appendChild(disp);
	inBody.appendChild(close);
	
	Element.hide('blackBg');
	Element.hide('dispElement');
	Element.hide('closeBox');
		
}
