var hutchButton;
var hutch;
var hutchContent;
var hutchContentFrame;	

var sTOId;

function SR_init() {
	hutchButton = window.document.getElementById('mediaHutchButton');
	hutch = window.document.getElementById('mediaHutchBG');
	// hutch.style.width = window.document.body.offsetWidth;
	// hutch.style.hieght = window.document.body.offsetHeight;
	hutchContent = window.document.getElementById('srContent');	
	hutchContentFrame = window.document.getElementById('srContentFrame');
}

function showScreeningRoom(promoOrTrailer, trailerInfo) {
	SR_init();
	hideFormElements();
	if (promoOrTrailer == 'trailer') {
		hutchContentFrame.src = '/screeningroom/sr_trailers.asp' + trailerInfo;
	} else {
		hutchContentFrame.src = '/screeningroom/sr_contest.html';
	}
	sTOId = setTimeout("hideHutchButton()",250);
	hutch.style.display = 'block';
	hutchContent.style.display = 'block';
}

function hideHutchButton() {
	hutchButton.style.display = 'none';
	clearTimeout(sTOId);
}

function hideScreeningRoom() {
	hutch.style.display = 'none';
	hutchContent.style.display = 'none';
	hutchButton.style.display = 'block';
    hutchContentFrame.src = '/screeningroom/blank.html';
	showFormElements();
}

function sizeMask() {
//netscape hack for 100% div on scroll

	var ua = navigator.userAgent.toLowerCase(); 
	// browser name
	var isGecko     = (ua.indexOf('gecko') != -1);
	var isMozilla   = (this.isGecko && ua.indexOf("gecko/") + 14 == ua.length);
	var isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
	var isIE        = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
   
	// version number
	if (isNS && isGecko) {
      document.getElementById('mediaHutchBG').style.height = document.documentElement.offsetHeight+"px";
      window.onresize = function(){document.getElementById('mediaHutchBG').style.height = document.documentElement.offsetHeight+"px";}
   } else if (isIE) {

	} else if (isMozilla) {
     document.getElementById('mediaHutchBG').style.height = document.documentElement.offsetHeight+"px";
      window.onresize = function(){document.getElementById('mediaHutchBG').style.height = document.documentElement.offsetHeight+"px";}
   }
}

function writeFlashTek() {
	
	if (getFlashVersion() >= 5) {
		var flashTek = '';
		flashTek += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"122\" height=\"9\" id=\"openButton\" align=\"\">";
		flashTek += "\t<param name=\"movie\" value=\"/screeningroom/flash/open_button.swf\" />";
		flashTek += "\t<param name=\"quality\" value=\"high\" />";
		flashTek += "\t<param name=\"bgcolor\" value=\"#D9D9D9\" />";
		flashTek += "\t<embed src=\"/screeningroom/flash/open_button.swf\" quality=\"high\" bgcolor=\"#D9D9D9\" width=\"122\" height=\"9\" name=\"openButton\" align=\"\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>";
		flashTek += "</object>";
		
		document.write(flashTek);
	} else {
		document.write("<a href=\"#\" onclick=\"showScreeningRoom('promo'); return false;\"><img src=\"/screeningroom/images/enter_sr_but_off.gif\" alt=\"\" width=\"116\" height=\"14\" border=\"0\" /></a>");
	}

}

function goToSRTrailer(tid, mid) {
	showScreeningRoom('trailer', "?mid=" + escape(mid) + "&tid=" + escape(tid));
}

function hideFormElements() {
  //hide form elements   
  for(i=0;i<document.forms.length;i++) {
    for(j=0;j<document.forms[i].elements.length;j++) {
  	  document.forms[i].elements[j].style.visibility = 'hidden';
    }
  }

}

function showFormElements() {
   //show form elements   
  for(i=0;i<document.forms.length;i++) {
    for(j=0;j<document.forms[i].elements.length;j++) {
	    document.forms[i].elements[j].style.visibility = 'visible';
    }
  }
}

function goCoreOffer(mid) {
	document.getElementById('offerWin').src = '/screeningroom/sr_header.asp?mid=' + mid;
}