var MacIE=false;
if(navigator.userAgent.split("MSIE")[1] && navigator.userAgent.split("MSIE")[1].indexOf("PowerPC")>=1) {MacIE=true;}

function sD(el,v) {
	document.getElementById(el).style.display = v;
}
function miniExplore(){
	sD('exploreB','none');
	sD('exploreMax','inline');
}
function maxiExplore(){
	sD('exploreB','block');
	sD('exploreMax','none');
}
function miniChannelLinks(){
	document.getElementById('channelLinksMain').style.height = "30px";
	sD('channelLinksMin','none');
	sD('channelLinksMax','block');	
}					
function maxiChannelLinks(){
	document.getElementById('channelLinksMain').style.height = origChanLinkHeight;
	sD('channelLinksMin','block');
	sD('channelLinksMax','none');			
}	
function showMore() {	document.getElementById('moreMenu').style.display = "block"; }						
function hideMore() {	document.getElementById('moreMenu').style.display = "none";	}	

/** start chris code **/
function isWithinNode(e,i) {
answer = false;
te = e;
while(te && !answer) {
	if ((te.id && (te.id == i)) || (te.className && (te.className == i+"Class"))) {
		answer = true;
	} else {
		te = te.parentNode;
	}
}
return answer;
}//isWithinNode

var onMoreShort = false;
var onMoreMenu = false;
var hideMoreTimer = 0;
function handleOver(event) {
var e = event ? event : window.event;
var eL = e.srcElement ? e.srcElement: (e.target ? e.target : e.currentTarget);
		if (isWithinNode(eL,"moreShort")) {
			if (!onMoreShort) {
				showMore();
				onMoreShort = true;
			}
		} else if (isWithinNode(eL,"moreMenu")) {
			if (!onMoreMenu) {
				onMoreMenu = true;
				clearTimeout(hideMoreTimer);
			}
		} else {
			if (onMoreShort || onMoreMenu) {
				hideMoreTimer = setTimeout('hideMore()',500);
				onMoreShort = false;
				onMoreMenu = false;
			}
		}
	//}//if element has an id and is visible
}//handleOver()
document.onmouseover=handleOver;
/** end chris code **/

var thishost = self.location.hostname; 
var thisdomain = thishost.substring(thishost.lastIndexOf(".",(thishost.length - 5)), thishost.length );
var hideShowtimes="hide showtimes <img src='http://eimg.net/img/elements/theaters_hide.gif' width='7' height='5' />";
var displayShowtimes="display showtimes <img src='http://eimg.net/img/elements/theaters_display.gif' width='7' height='5' />";
var cookieEnd="; expires=Wed, 30-Dec-2037 00:00:00 GMT; path=/; domain=" + thisdomain;

function adjustTheaterDisplays(firstTheater) {
  var showTheatersPos = document.cookie.indexOf("showTheaters=");
  if (showTheatersPos != -1) {
    var start = showTheatersPos + 13;                                    // Start of cookie value
    var end = document.cookie.indexOf(";", start);                       // End of cookie value
    if (end == -1) end = document.cookie.length;
    var theaterIDs = unescape(document.cookie.substring(start, end));    // Extract the value
    var theaterIDsArray = theaterIDs.split(",");                         // Run through the array and pick out the IDs.
    if(theaterIDsArray[0]==1) {    
      document.getElementById("listings_"+firstTheater).style.display="block";
      document.getElementById("displayButton_"+firstTheater).innerHTML=hideShowtimes;
      document.cookie = "showTheaters=" + firstTheater + cookieEnd;
    } else {
      if(document.getElementById("listings_"+firstTheater).style.display!="block") {
        document.getElementById("displayButton_"+firstTheater).innerHTML=displayShowtimes;
      }
      for (i=0;i<=theaterIDsArray.length;i++) {
        if(theaterIDsArray[i]) {
          var testForListing=document.getElementById("listings_"+theaterIDsArray[i]);
          if(testForListing) { // If element/listing exists then display it.
            document.getElementById("listings_"+theaterIDsArray[i]).style.display="block";
            document.getElementById("displayButton_"+theaterIDsArray[i]).innerHTML=hideShowtimes;
          }
        }
      }
    } 
  } else {      
    document.getElementById("listings_"+firstTheater).style.display="block";
    document.getElementById("displayButton_"+firstTheater).innerHTML=hideShowtimes;
    document.cookie = "showTheaters=" + firstTheater + cookieEnd;
  }  
}

function showText(type) {		
	var theaterID = type;	
	var showTheatersPos = document.cookie.indexOf("showTheaters=");
  if (showTheatersPos != -1) {
    var start = showTheatersPos + 13;                                   // Start of cookie value
    var end = document.cookie.indexOf(";", start);                      // End of cookie value
    if (end == -1) end = document.cookie.length;
    var theaterIDs = unescape(document.cookie.substring(start, end));   // Extract the value	 
    var theaterIDsArray = theaterIDs.split(",");
  }
  document.getElementById("theaterRow_" + theaterID).style.borderTop="1px solid #fff";
  document.getElementById("theaterTitle_" + theaterID).style.background="#aaa";
	switch(theaterID) {					
		case theaterID: 
			if(document.getElementById("listings_" + theaterID).style.display=="block") {
				document.getElementById("displayButton_" + theaterID).innerHTML="display showtimes <img src='http://eimg.net/img/elements/theaters_display.gif' />";
				document.getElementById("listings_" + theaterID).style.display="none";
								
				// Remove selected TheaterID from the showTheaters array.
        var newTheaterIDsArray = new Array();
        j=0;
        for (i=0;i<theaterIDsArray.length;i++) { 
          if (theaterIDsArray[i]!=theaterID) { 
            newTheaterIDsArray[j] = theaterIDsArray[i];
            j++;
          } 
				} 
        if(theaterIDsArray.length==0 || newTheaterIDsArray.length==0) document.cookie = "showTheaters=0" + cookieEnd;
        else document.cookie = "showTheaters=" + newTheaterIDsArray + cookieEnd;
			} else {
				document.getElementById("displayButton_" + theaterID).innerHTML=hideShowtimes;
				document.getElementById("listings_" + theaterID).style.position="relative";
				document.getElementById("listings_" + theaterID).style.display="block";
				        
        // Run thru cookie and sniff out the values for "showTheaters"
        if(theaterIDsArray[0]=="" || theaterIDsArray[0]==0) theaterIDsArray.length=0;
        theaterIDsArray[theaterIDsArray.length]=theaterID;
        document.cookie = "showTheaters=" + theaterIDsArray + cookieEnd;          
 			}
			break;
		default: break;
	}
}

function showDynCt(targetContainerId, contentString) {
	document.getElementById(targetContainerId).innerHTML = contentString;
}

function replaceContent(showMe,hideMe,changeTextID,changeText) { 
  document.getElementById(showMe).style.display="block";
  document.getElementById(hideMe).style.display="none"; 
  document.getElementById(changeTextID).innerHTML=changeText;
}

function inlineEdit(ctname,edtType) {
  d=document;
  if(MacIE) {
    location.href="/channel/edit/"+ctname;
  } else {
    switch(ctname) {					
      case ctname: 
        // close style if layout is open and vice-versa
        if(ctname=="style" && d.getElementById("inline_edit_layout").style.display=="block") {d.getElementById("inline_edit_layout").style.display="none";}
        if(ctname=="layout" && d.getElementById("inline_edit_style").style.display=="block") {d.getElementById("inline_edit_style").style.display="none";}		
        // if the edit box is open, close it
        if(d.getElementById("inline_"+edtType+"_"+ctname).style.display=="block") {	
          if(d.getElementById(edtType+"_"+ctname)) {
            d.getElementById(edtType+"_"+ctname).innerHTML="edit <img src='http://eimg.net/img/elements/theaters_display.gif' width='7' height='5' />"; 
          }
          d.getElementById("inline_"+edtType+"_"+ctname).style.display="none";	
          if(d.getElementById("title_"+ctname)) d.getElementById("title_"+ctname).innerHTML="";
        }
        // else if the edit box is closed, open it
        else {
          //if(d.getElementById("inline_remove_"+ctname)) d.getElementById("inline_remove_"+ctname).style.display="none";
          if(d.getElementById("inline_edit_"+ctname)) d.getElementById("inline_edit_"+ctname).style.display="none";
          if(d.getElementById("inline_edit_none_"+ctname)) d.getElementById("inline_edit_none_"+ctname).style.display="none";
          
          if(document.getElementById("inlineIframe_"+ctname)) {
            // iframe will only reload edit page content if its source is blank.
            if(document.getElementById("inlineIframe_"+ctname).src=="about:blank") {
              if(edtType!="edit_none") {
                document.getElementById("inlineIframe_"+ctname).src = "/channel/edit/"+ctname+"/inline/html";
              }
            }
          }
          
          d.getElementById("inline_"+edtType+"_"+ctname).style.display="block";
          if((edtType=="edit" && d.getElementById("title_"+ctname)) || (edtType=="edit_none" && d.getElementById("title_"+ctname))) {
            d.getElementById("title_"+ctname).innerHTML="Edit&#160;";
            d.getElementById(edtType+"_"+ctname).innerHTML="edit <img src='http://eimg.net/img/elements/theaters_hide.gif' width='7' height='5' />";
          }
          else if (d.getElementById("title_"+ctname)) d.getElementById("title_"+ctname).innerHTML="Remove&#160;";
        }
      break;
      default: break;
    }
	}
}

function inlineEditCleanUp(ctname) {
  d.getElementById(ctname+"_edit_notice").style.display="block";
  d.getElementById(ctname+"_widget_container").style.backgroundImage="url(\"/img/misc/yellow_fade.gif\")";
  setTimeout('inlineEditConfirm("'+ctname+'")', 800);
}

function inlineEditConfirm(ctname) {
  d.getElementById(ctname+"_widget_container").style.background="#fff";
  setTimeout('inlineEditCleanAll("'+ctname+'")', 4200);
}

function inlineEditCleanAll(ctname) {
  d.getElementById(ctname+"_edit_notice").style.display="none";
}

function inlineEditReset(ctname) {
  if(document.getElementById("inline_edit_"+ctname).style.display=="block") {
    if(ctname=="layout") {
      document.getElementById("inlineIframe_"+ctname).src="about:blank";
    } else {
      document.forms['editForm_'+ctname].reset();
    }
  }
}


