/* Constants */
var AXIS_X = 0;
var AXIS_Y = 1;

/* shortcut to getElementById */
function getNode(node) {
	return document.getElementById(node);
}


/* Destroy a node with the Death Star */
function killNode(nodeID) {
	var node = getNode(nodeID);
	var nodeParent = node.parentElement;
	if (typeof nodeParent != "undefined") {
		nodeParent.removeChild(node);
	} else {
		node.style.display = "none";
	}
}

/* Replace text in a node. */
function swapTextNode(parentObject, newText) {
    parentObject.replaceChild(document.createTextNode(newText), parentObject.firstChild);
}

/* Replace text in a node. Has more protection than the previous version and will fall back on non-DOM techniques if it can't pick out the childNodes */
function replaceInnerText(node, text) {
	//	replacement for node.innerHTML = text; which is apparently broken in Safari 1.2.4
	if (typeof node.childNodes != "undefined" && node.childNodes.length > 0) {
		var newnode = document.createTextNode(text);
		node.replaceChild(newnode, node.firstChild);
	} else {
		// fall back on the old school just in case
		node.innerHTML = text;
	}
}

/* Cross browser solution to DOM getComputedStyle() (Safari doesn't currently support this) */
function grabComputedStyle(elementObject) {

    if (document.defaultView && document.defaultView.getComputedStyle ) {
        return  document.defaultView.getComputedStyle(elementObject, null);
     } else if  (elementObject.currentStyle) {
        return elementObject.currentStyle;
    } else  {
        return null;
    }

}

function grabComputedHeight(elementObject) {

    var height = grabComputedStyle(elementObject).height;
    
    if (height != null) {
        if (height.indexOf("px") != -1)
            height = height.substring(0, height.indexOf('px'));
        if (height == "auto") {
            if (elementObject.offsetHeight)
                height = elementObject.offsetHeight;
        }
    }
    
    return height;
    
}

/* Return the target node for an event. */
function getEventTarget(evt) {
	var tgt = evt.srcElement;
	if (!tgt)
		tgt = evt.target;
	return tgt;
}
function getWindowHeight() {
    var height = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	    height = window.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight) {
	    height = document.documentElement.clientHeight;
	} else if( document.body && document.body.clientHeight) {
	    height = document.body.clientHeight;
	}
    return height;
}

/* Clear out any text that may have been selected (called "ranges") by dragging the mouse mid-click. */

function clearRanges(event) {
	if (isMacIE) { // Mac IE is blowing up
	} else if (isSafari) { // Avoid Safari 1.3 / 2.0 bugs with window.getSelection()
		event.stopPropagation();
	} else if (document.selection) { // IE 6
		document.selection.empty();
	} else if (window.getSelection()) { // NS 6
		window.getSelection().removeAllRanges();
	} else {
		event.stopPropagation();
	}
}

/* How much the document's been scrolled vertically. Needed for correcting position calculations. */
function getDocumentScrollAmount() {
	if (!isSafari) {
		return document.body.scrollTop;
	} else {
		return 0;
	}
}

/* Computes the total vertical offset of a node, the sum of the enclosing objects' vertical offset. */
function getElementOffsetY(element) {
	var totalOffset = 0;
	if (element.offsetTop != null) {
        totalOffset += element.offsetTop;
		while (element.offsetParent) {
			totalOffset += element.offsetParent.offsetTop;
			element = element.offsetParent;
		}
	}
	return totalOffset;
}

function getElementMouseCoordinate(evt, curEmt) {
var xC = -1;  
    if (!evt) var evt = window.event;
    
    if (evt.offsetX) {
        xC = evt.offsetX;
    } else if (curEmt.offsetX != null) {
        eXC = curEmt.offsetX;
        xC = evt.layerX - eXC;
    } else if (evt.layerX) {
        eXC = getElementOffsetX(curEmt);
        xC = evt.layerX - eXC;
        curEmt.offsetX = eXC;
    }
    return xC;
}

/* Computes the total horizontal offset of a node, the sum of the enclosing objects' horizontal offset. */
function getElementOffsetX(element) {
    var totalOffset = 0;
    if (element.offsetLeft != null) {
        totalOffset += element.offsetLeft;
        while (element.offsetParent) {
            totalOffset += element.offsetParent.offsetLeft;
            element = element.offsetParent;
        }
    }
    return totalOffset;
}

/* Gets the position of the top of a node. */
function getNodeTop(nodeId) {
	var itemOver = document.getElementById(nodeId);
	var itemOverTop = itemOver.style.top ? (itemOver.offsetTop - stripUnits(itemOver.style.top)) : itemOver.offsetTop;
	return itemOverTop;
}


/* Moves an object vertically. Pass in either the node or the node's ID. If amount is positive, move it down. Negative? Move it up. */
function moveNode(mover, amount) {
	if (typeof mover == "string")
		mover = getNode(mover);
	
	if (mover.style.top) {
		mover.style.top = stripUnits(mover.style.top) + amount + "px";
	} else {
		mover.style.top = (amount) + "px";
	}
}

/* Debug utility; displays all of the properties of an object in a popup */
function displayObject(obj) {
	var msg = "";
	for (var prop in obj) {
		msg += prop;
		msg += ": ";
		msg += prop.value;
		msg += "\n";
	}
	window.alert(msg);
}

function tokenizeString(inputString, token) {
    var output = new Array();
    var counter = 0;
    if (inputString) {
        while (inputString.indexOf(token) != -1) {
            var end = inputString.indexOf(token);
            var newStart = end + token.length;
            output[counter] = inputString.substring(0,end);
            inputString = inputString.substring(newStart);
            counter++;        
        }
        output[counter] = inputString;
    }
    return output;
}

function xmlRequest() {
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		//req.isDOM = true;
		return req;
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		return req;
	} else 
		return null;
}

function isXMLReady(xmlObject) {
	return (xmlObject.readyState == 4 && xmlObject.status == 200);
}

function getTournData(tournId)
{
	var response = SomMainPage.GetTournamentInfo(tournId);
	var dc = response.value;
	return dc;
}

function getUltRestOfTourns()
{
	
	var ultDrop = document.getElementById("showmoreult");
	ultDrop.style.visibility = "visible";
}

function initMovie() {
   
   // if (isXMLReady(movieXml)) {
   
      try{  
        var out = getTournData(myPopup.movieId);
       if(out != null){
        var vals = tokenizeString(out,",");
       // alert(xml.getElementsByTagName("TournName")[0].firstChild.nodeValue);
      // var movieParent = xml.getElementsByTagName("MOVIE")[0];
      //var elementId = "b" + movieParent.getAttribute("DS") + movieParent.getAttribute("ID") + COUNT_DELIM + movieParent.getAttribute("POS");        
		
        myPopup = document.getElementById(myPopup.id);
     //   myPopup.isDOM = movieXml.isDOM;
   //    myPopup.parentId = movieParent.getAttribute("PARENTID");
  //     myPopup.mtitle = xml.getElementsByTagName("TITLE")[0].firstChild.nodeValue;
		  myPopup.mtitle = vals[3];
		  myPopup.tournlogo = vals[15];
		if(vals[15].length == "0") myPopup.tournlogo = "http://www.scoreomatic.com/somMain/popup/1px.gif";
		myPopup.dates = "Dates: " + vals[8] + " - " + vals[9] + " ";
		myPopup.location = "Location: " + vals[27].replace('|',',');
   //     myPopup.synopsis = xml.getElementsByTagName("SYNOPSIS")[0].firstChild.nodeValue;
    //    try {
   //         var details = xml.getElementsByTagName("DETAILS")[0];
  //          myPopup.rated = details.getAttribute("RATED");
  //          myPopup.relYear = details.getAttribute("RELYEAR");
   //         myPopup.genreId = details.getAttribute("GENREID");
  //          myPopup.genreName = details.getAttribute("GENRENAME");
  //          myPopup.CMURate = details.getAttribute("CMURATE");
  //          myPopup.CMPred = details.getAttribute("CMPRED");
 //           myPopup.CMWgtR = details.getAttribute("CMWGTR");
   //   } catch (e) {}
  //     try {
   //         var glyph = xml.getElementsByTagName("GLYPH")[0];
  //          myPopup.isRec = glyph.getAttribute("REC");
  //          myPopup.isFrnd = glyph.getAttribute("FRND");
   //     } catch (e){}
  //      try {
   //         var starring = xml.getElementsByTagName("STARRING")[0].getElementsByTagName("PERSON");
   //         var starNames = "";
   //         var starIds = "";
   //         for (var ii=0; ii < starring.length; ii++) {
   //             var person = starring[ii];
   //             if (starNames != "") {                
  //                  starNames += ", ";
  //                 starIds += ",";
    //            }
   //             starNames += person.getAttribute("NAME");
  //              starIds   += person.getAttribute("ID");
                
  //         }
   //       myPopup.starNames = starNames;
  //        myPopup.starIds = starIds;
    //   } catch (e) {}
   //    try {
  //         myPopup.director = xml.getElementsByTagName("DIRECTOR")[0].getElementsByTagName("PERSON")[0].getAttribute("NAME");
 //          myPopup.directorId = xml.getElementsByTagName("DIRECTOR")[0].getElementsByTagName("PERSON")[0].getAttribute("ID");
 //      } catch (e) {}
   // } 
    }
    else {
     return false;
     }
    }
    
    catch(e){
		return false;
    }
    
    
    return true;
}

/* ************** START BOB ******************** */
var STYLE_POSITION = 1;
var COUNT_DELIM = "_";
var BOX_STYLE = "0";
//var PARENTAL_RATING_ROOT = IMAGE_ROOT + "/pages/parental_ratings/rating_";
var MED_BOXSHOT_HEIGHT = 92;
var PAGE_CURRENT_TIME =  new Date();
var BOB_BOX_TOP_SHADOW_OFFSET = -10;
var BOB_BOX_WIDTH = 290;
var BOB_MOVIE_TO_ARROW_SPACER = 5;
var BOB_DISPLAY_STYLE_DEFAULT = 0;
var BOB_DISPLAY_STYLE_LARGE_BOXSHOT = 1;
var BOB_DISPLAY_STYLE_TINY_BOXSHOT = 2;
var BOB_ARROW_HEIGHT_NO_SHADOW = 70;
var LARGE_BOXSHOT_WIDTH = 110;
var MED_BOXSHOT_WIDTH = 65;
var TINY_BOXSHOT_WIDTH = 50;
var AppRoot = "/som/v4/";
//var AppRoot = "/v4/";
var myPopup;
var req;



/* do BOB */
function dB(evt, thisPopup) {   
    if (d_bobMS != -1) {
        try {
            if (myPopup.tagName != "A")
            clearTimeout(clearBOBTimer);
        } catch (e){}
        myPopup = thisPopup;
        myPopup.onmouseout = clearBOB; 
	   // movieItemId = myPopup.id;                
      //  myPopup.displayStyle = movieItemId.substring(1,2);
        myPopup.mouseCoordX = getElementMouseCoordinate(evt, myPopup);
        popArrow.onclick = handleBOBArrowClick;
      // if (popBox.style.visibility != "visible")
           //popBoxshot.src = "labels/1px.gif";
        //if (myPopup.tagName != "A") {
	        popArrow.onmouseover = cancelClearBOB;
	        popArrow.onclick = handleBOBArrowClick;
	        popArrow.onmouseout = clearBOB;
       // }
		bobDisplay = setTimeout("initBOB()", d_bobMS);
    }
}

/*  If the movie is clicked within the arrowspace, use the movie's href */
function handleBOBArrowClick() {  
    //if (myPopup.tagName == "A")
        document.location.href = myPopup.href;
    //else if (myPopup.parentNode.tagName == "A")
     //   document.location.href = myPopup.parentNode.href;
}

function getElementHeightMidpoint(element, modifier) {
    
    var height = grabComputedHeight(element);  
    if (height == null) 
        return null;
    else  {
        var safeHeight = "" + height;
        if (safeHeight.indexOf('px') != -1) {
            height = safeHeight.substring(0, height.indexOf('px'));
            
        }
    }
    return height / 2;
}

function initBOB() {
    myPopup.isActive = true;
    var itemId = myPopup.id;
    if (myPopup.alt) {
	   myPopup.altBackup = myPopup.alt;
       myPopup.alt = "";
    }
	if (!myPopup.mtitle) {
		var countIndex = itemId.indexOf(COUNT_DELIM);
        var movieId = itemId.substring(2, countIndex);
        var style = itemId.charAt(STYLE_POSITION);
        var position = itemId.substring(countIndex+1);

        myPopup.movieId = movieId;
        myPopup.itemId = itemId;
        myPopup.dispStyle = style;
        myPopup.position = position;
        
        var linkCtrType = "BOX";
        if (myPopup.tagName == "A") 
            linkCtrType = "TXT";
		//var url = XML_ROOT + "MovieData?movieid=" + myPopup.movieId + "&pos=" + myPopup.position + "&ds=" + myPopup.dispStyle + "&lnkctr=pop" + linkCtrType + myPopup.movieId;
	//	var url = XML_ROOT + myPopup.movieId + ".xml";
        
	//		movieXml = new xmlRequest();
	//		movieXml.onreadystatechange = initBOBMovie;
	//		movieXml.open("GET", url, true);
	//		movieXml.send(null);
		initBOBMovie();
	} else {
    
	  //  if (getBOBBoxshot(myPopup))
		  drawBOB();
	}
	 
    return true;
}

function getBOBBoxshot() {  

  //   if (myPopup.tagName == "A") {                
           // popBoxshot.style.display = "inline";
            //popBoxshot.parentMovieId = myPopup.itemId;
          //  var boxMovieId = myPopup.movieId;
          //  if (movie.parentId)
          //      boxMovieId = myPopup.parentId;
            
           // popBoxshot.src = IMAGE_ROOT + "boxshots/small/" + boxMovieId + ".jpg";
            drawBOB();
            
   //     } else {
           // popBoxshot.style.display = "none";
   //        drawBOB();
   //     }
        return true;
    }
    
function initBOBMovie() {
   try {
	//    if (isXMLReady(movieXml)) { 
	       if (initMovie())
	     {
	       
	          getBOBBoxshot(); 
	        }
	        else
	        {
				 doClearBOB();
				 }
	   // } 
    } catch (e) {}
    
}
function cancelClearBOB() {
    try {
    clearTimeout(clearBOBTimer);
    //movie.isActive = true;
    } catch (e) {}
}

function clearBOB() {
        doClearBOB();
        //clearBOBTimer = setTimeout("doClearBOB()", 3);
}

function doClearBOB() { 
        try {
	    myPopup.isActive = false;
	    clearTimeout(bobDisplay);
	    myPopup.alt = myPopup.altBackup;
	    popBox.style.visibility = "hidden";
	     popTournInfoTr.style.visibility = "hidden";
	   // popLocationTr.style.visibility = "hidden";
	    popTournLogo.style.visibility = "hidden";
	    //popBoxshot.style.display = "none";
	    //popFriend.style.visibility = "hidden";
	   // popRec.style.visibility = "hidden";
	   // bobRating.style.visibility = "hidden";
        //bobDirectorTr.style.visibility = "hidden";
       // bobActorsTr.style.visibility = "hidden";
	    //bobRating.src = IMAGE_ROOT + "labels/1px.gif";
	    var emptyNodes = emptyBOBNodes();
        } catch (e) {}
}

function emptyBOBNodes() {
    while (popTitle.hasChildNodes()) popTitle.removeChild(popTitle.firstChild);
	while (popTournInfo.hasChildNodes()) popTournInfo.removeChild(popTournInfo.firstChild);
	//while (popLocation.hasChildNodes()) popLocation.removeChild(popLocation.firstChild);
    //while (bobGenre.hasChildNodes()) bobGenre.removeChild(bobGenre.firstChild);
   // while (bobDirector.hasChildNodes()) bobDirector.removeChild(bobDirector.firstChild);
    //bobArrowImg.src = IMAGE_ROOT + "/pages/bob/lower-right.gif";
    return true;
}

function createNFTextNode(textString) {
    /* This function is incomplete */
    var safeString = tokenizeString(textString, "%%~p;");
    var textSpan = document.createElement("SPAN");
    
    for (var ii=0; ii < safeString.length; ii++) {
        textSpan.appendChild(document.createTextNode(safeString[ii]));
        if (ii+1 < safeString.length) {
            textSpan.appendChild(document.createElement("P"));
        }
    }
    return textSpan;
}



function drawBOB() { 
    myPopup.drawingBOB = true;
    var emptyNodes = emptyBOBNodes();
   // alert(myPopup.mtitle);
    if (myPopup.mtitle) popTitle.appendChild(document.createTextNode(myPopup.mtitle));
    popTournInfo.appendChild(document.createTextNode(myPopup.dates));
    popTournInfo.appendChild(document.createElement("BR"));
    popTournInfo.appendChild(document.createTextNode(myPopup.location));  
	//popLocation.appendChild(document.createTextNode(myPopup.location));
	popTournLogo.src = myPopup.tournlogo;
   // if (movie.synopsis) bobSynopsis.innerHTML = createNFTextNode(movie.synopsis).innerHTML;
    //if (movie.relYear) bobYear.appendChild(document.createTextNode(" (" + movie.relYear + ")"));
    //if (movie.starNames) bobActors.appendChild(document.createTextNode(movie.starNames));
    //if (movie.director) bobDirector.appendChild(document.createTextNode(movie.director));

    
   // if (movie.genreName) bobGenre.appendChild(document.createTextNode(movie.genreName));
    //if (myPopup.isActive) { 
        setupBOBPosition(myPopup);      
  //  }
}

function getBOBYOverrunAdjustment(_computedHeight, myPopup) {
    var _winHeight = getWindowHeight();            
    var _scrollAmt = getDocumentScrollAmount();
    var _bobBoxTop = (getElementOffsetY(popBox) - BOB_BOX_TOP_SHADOW_OFFSET) - _scrollAmt; // its okay for the shadow to bleed
    var _overrun = 0;
    
    
    var _bobBoxBottomPos = (_bobBoxTop * 1) + (_computedHeight * 1);
    popBox.computedHeight = _computedHeight;
    
   if (_bobBoxBottomPos > _winHeight) {
        _overrun =  _bobBoxBottomPos - _winHeight - 30;
        // Fix for mozilla first time rendering boxshot funk 
       if (myPopup.tagName == "A" && myPopup.isDOM && !myPopup.MozAdjust) {
            //_overrun -= 85;
            //bobBox.computedHeight -= 85
            myPopup.MozAdjust = true;
        }
   }
    if (_bobBoxTop - _overrun < 1) {
        _overrun = _bobBoxTop;
    }
    
    return _overrun;
}

function getBOBTop(myPopup) {
    var _computedHeight = grabComputedHeight(popBox);
    var _quarterHeight = _computedHeight / 4;
    var _elementY = getElementOffsetY(myPopup);
    var _topPosition = (_elementY + BOB_BOX_TOP_SHADOW_OFFSET) - _quarterHeight; //its okay for the shadow to bleed
    popBox.style.top = _topPosition; // set so we can calculate overrun    
    _topPosition -= getBOBYOverrunAdjustment(_computedHeight, myPopup);    
    return _topPosition;
    
}

function getBOBLeft(myPopup) {
    
    
    var _pageMidpoint = getElementOffsetX(document.getElementById("page-content"));
    var _elementOffsetX = getElementOffsetX(myPopup);
    var _activeAreaWidth = 0;
    if (myPopup.tagName != "A") {
	    if (myPopup.displayStyle == BOB_DISPLAY_STYLE_LARGE_BOXSHOT)
	        _activeAreaWidth = LARGE_BOXSHOT_WIDTH;
	    else if (myPopup.displayStyle == BOB_DISPLAY_STYLE_TINY_BOXSHOT) 
	        _activeAreaWidth = TINY_BOXSHOT_WIDTH;
	    else
	        _activeAreaWidth = MED_BOXSHOT_WIDTH;
    } else {
        _activeAreaWidth = myPopup.mouseCoordX + 50; //50 is a buffer zone for the link
    }
    

    var _leftPosition = _elementOffsetX + BOB_MOVIE_TO_ARROW_SPACER + _activeAreaWidth;
    
    if (_leftPosition  > _pageMidpoint + 490) { // is beyond right buffer?
        _leftPosition -= BOB_BOX_WIDTH + BOB_MOVIE_TO_ARROW_SPACER + _activeAreaWidth;
        popBox.arrowSwap = true;
    } else {
        popBox.arrowSwap = false;
    }
    return _leftPosition;
}

function setupBOBPosition(myPopup) {
       
        var ARROW_BUFFER = 35;
        
        
        var winHeight = getWindowHeight();            
        var scrollAmt = getDocumentScrollAmount();
        var PAGE_MIDPOINT = getElementOffsetX(document.getElementById("page-content")) + 405;
        
        var WINDOW_TOP_PADDING = 4;
        var FALLBACK_MIDPOINT = 160;
        
        var dispStyleLeftAdjustment = 0;
        var dispStyleRightAdjustment = 0;
         
        popBox.style.top = getBOBTop(myPopup);
      
        popBox.style.left = getBOBLeft(myPopup);
        
        popArrow.style.top = positionBOBArrow(myPopup);
        
        doDisplayBob = setTimeout("displayBOB('" + myPopup.itemId + "')", 5);
}

function positionBOBArrow(myPopup) {    

    var _isPointedUp = false;
    var _isPointedRight = popBox.arrowSwap;
    var _elementY = getElementOffsetY(myPopup) - getElementOffsetY(popBox);
    var _ARROW_HEIGHT = 101;
    var _arrowTop = _elementY;
    
    if (_arrowTop <  (popBox.computedHeight / 2)) {
        _isPointedUp = true;
    } else {
        _arrowTop -= BOB_ARROW_HEIGHT_NO_SHADOW; 
    }
    // Make sure arrow doesn't overlap top and bottom and respects the top and bottom of BOB
    if (_arrowTop + _ARROW_HEIGHT + 10 > popBox.computedHeight)  //10 is the padding we want to preserve at the bottom of the page.
        _arrowTop -= 10;
    if (_arrowTop < 10)
        _arrowTop = 10;


    if (_isPointedRight) {
        popArrow.style.left = 268;
    } else {
        popArrow.style.left = -42;
    }
    if (_isPointedUp && !_isPointedRight) {
		  popArrowULImg.style.display = "none";
       //  popArrowULImg.style.display = "block";
         popArrowURImg.style.display = "none";
         popArrowLLImg.style.display = "none";
         popArrowLRImg.style.display = "none";
    } else if (_isPointedUp && _isPointedRight) {
         popArrowULImg.style.display = "none";
         popArrowURImg.style.display = "none";
      //  popArrowURImg.style.display = "block";
         popArrowLLImg.style.display = "none";
         popArrowLRImg.style.display = "none";
    } else if (!_isPointedUp && _isPointedRight) {
         popArrowULImg.style.display = "none";
         popArrowURImg.style.display = "none";
         popArrowLLImg.style.display = "none";
         popArrowLRImg.style.display = "none";
     //   popArrowLRImg.style.display = "block";
    } else {
        popArrowULImg.style.display =  "none";
         popArrowURImg.style.display = "none";
         popArrowLLImg.style.display = "none";
     //   popArrowLLImg.style.display = "block";
         popArrowLRImg.style.display = "none";

    }
	//if (arrowTop < 30) arrowTop = 30;   
     
    return _arrowTop;
}

function displayBOB(itemId) {
    myPopup = document.getElementById(itemId);
       // if (myPopup.isActive) {
		//if(popFriend && myPopup.isFrnd && myPopup.isFrnd == "true")
		  // popFriend.style.visibility = "visible";
	   // if(popRec && myPopup.isRec && myPopup.isRec == "true")
	       // popRec.style.visibility = "visible";            
	    popBox.style.visibility = "visible";
	    popTournInfoTr.style.visibility = "visible";
	   // popLocationTr.style.visibility = "visible";
	    popTournLogo.style.visibility = "visible";
   // }
}

function primePOP() {
    popBox = document.getElementById("pop");
    popTitle = document.getElementById("poptitle");
    //bobSynopsis = document.getElementById("bobsynopsis");
    //bobYear = document.getElementById("bobyear");
   // bobActors = document.getElementById("bobactors");
   // bobDirector = document.getElementById("bobdirector");
   popTournInfoTr = document.getElementById("poptourninfo");
   //popLocationTr = document.getElementById("poptournlocation");
   // popFriend = document.getElementById("popfrnd");
   // popRec = document.getElementById("poprec");
    //bobRating = document.getElementById("bobprating");
   // popBoxshot = document.getElementById("popimg");
	//popDates = document.getElementById("popdates");
	//popLocation = document.getElementById("poplocation");
	popTournInfo = document.getElementById("popinfo");
    popArrow = document.getElementById("poparrow");
    popArrowULImg = document.getElementById("poparrowulimg");
    popArrowURImg = document.getElementById("poparrowurimg");
    popArrowLLImg = document.getElementById("poparrowllimg");
    popArrowLRImg = document.getElementById("poparrowlrimg");
    popTopCap = document.getElementById("poptopcap");
    popBottomCap = document.getElementById("popbottomcap");
    popTournLogo = document.getElementById("poptournlogo");
	/* if(document.all)
    {
		popTopCap.src = AppRoot + "images/popup/pngfix.png";
		popArrowULImg.src = AppRoot + "images/popup/pngfix.png";
		popArrowURImg.src = AppRoot + "images/popup/pngfix.png";
		popArrowLLImg.src = AppRoot + "images/popup/pngfix.png";
		popArrowLRImg.src = AppRoot + "images/popup/pngfix.png";
		popBottomCap.src = AppRoot + "images/popup/pngfix.png";
	}*/
	
   // bobGenre = document.getElementById("bobgenre");
    popArrow.style.cursor = "pointer";
    window.onscroll = clearBOB;
    window.onblur = clearBOB;
    
}

function primePlayerPOP() {
    popBox = document.getElementById("pop");
    popTitle = document.getElementById("poptitle");
    //bobSynopsis = document.getElementById("bobsynopsis");
    //bobYear = document.getElementById("bobyear");
   // bobActors = document.getElementById("bobactors");
   // bobDirector = document.getElementById("bobdirector");
   popPlayerInfoTr = document.getElementById("popplayerinfo");
   //popLocationTr = document.getElementById("poptournlocation");
   // popFriend = document.getElementById("popfrnd");
   // popRec = document.getElementById("poprec");
    //bobRating = document.getElementById("bobprating");
   // popBoxshot = document.getElementById("popimg");
	//popDates = document.getElementById("popdates");
	//popLocation = document.getElementById("poplocation");
	popPlayerInfo = document.getElementById("popinfo");
    popArrow = document.getElementById("poparrow");
    popArrowULImg = document.getElementById("poparrowulimg");
    popArrowURImg = document.getElementById("poparrowurimg");
    popArrowLLImg = document.getElementById("poparrowllimg");
    popArrowLRImg = document.getElementById("poparrowlrimg");
    popTopCap = document.getElementById("poptopcap");
    popBottomCap = document.getElementById("popbottomcap");
    popPlayerImg = document.getElementById("popplayerimg");
    /*if(document.all)
    {
		popTopCap.src = AppRoot + "images/popup/pngfix.png";
		popArrowULImg.src = AppRoot + "images/popup/pngfix.png";
		popArrowURImg.src = AppRoot + "images/popup/pngfix.png";
		popArrowLLImg.src = AppRoot + "images/popup/pngfix.png";
		popArrowLRImg.src = AppRoot + "images/popup/pngfix.png";
		popBottomCap.src = AppRoot + "images/popup/pngfix.png";
	}*/
	
   // bobGenre = document.getElementById("bobgenre");
    popArrow.style.cursor = "pointer";
    window.onscroll = clearBOB;
    window.onblur = clearBOB;
    
}

function primePhotoViewer()
{
	photoviewer = document.getElementById("photoviewer");
	largeImageTr = document.getElementById("largeimage");
	largeImage = document.getElementById("largeimageholder");
	photoInfoTr = document.getElementById("photoinfo");
	photoInfo = document.getElementById("photoinformation");
	thumbnailsTr = document.getElementById("thumbnails");
	thumbnail0 = document.getElementById("tnholder1");
	thumbnail1 = document.getElementById("tnholder2");
	thumbnail2 = document.getElementById("tnholder3");
	thumbnail3 = document.getElementById("tnholder4");
	thumbnail4 = document.getElementById("tnholder5");
	thumbnail5 = document.getElementById("tnholder6");
	thumbnail6 = document.getElementById("tnholder7");
	thumbnail7 = document.getElementById("tnholder8");
	thumbnail8 = document.getElementById("tnholder9");
	thumbnail9 = document.getElementById("tnholder10");
	createPhotoViewer(0);
}

function createPhotoViewer(startIndex)
{
	var response = getThumbs(startIndex);
	if(response != null)
	{
		photoviewer.style.visibility = "visible";
		var vals = tokenizeString(response,",");
		for(var i=0;i<vals.length;i++)
		{
			var info = tokenizeString(vals[i],";");
			if(i==0)
			{
				var obj = document.createElement("img");
				obj.src = info[1];
				obj.id = info[0];
				thumbnail0.appendChild(obj);
			}
			if(i==1)
			{
				var obj = document.createElement("img");
				obj.src = info[1];
				obj.id = info[0];
				thumbnail1.appendChild(obj);
			}
			if(i==2)
			{
				var obj = document.createElement("img");
				obj.src = info[1];
				obj.id = info[0];
				thumbnail2.appendChild(obj);
			}
			if(i==3)
			{
				var obj = document.createElement("img");
				obj.src = info[1];
				obj.id = info[0];
				thumbnail3.appendChild(obj);
			}
			if(i==4)
			{
				var obj = document.createElement("img");
				obj.src = info[1];
				obj.id = info[0];
				thumbnail4.appendChild(obj);
			}
			if(i==5)
			{
				var obj = document.createElement("img");
				obj.src = info[1];
				obj.id = info[0];
				thumbnail5.appendChild(obj);
			}
			if(i==6)
			{
				var obj = document.createElement("img");
				obj.src = info[1];
				obj.id = info[0];
				thumbnail6.appendChild(obj);
			}
			if(i==7)
			{
				var obj = document.createElement("img");
				obj.src = info[1];
				obj.id = info[0];
				thumbnail7.appendChild(obj);
			}
			if(i==8)
			{
				var obj = document.createElement("img");
				obj.src = info[1];
				obj.id = info[0];
				thumbnail8.appendChild(obj);
			}
			if(i==9)
			{
				var obj = document.createElement("img");
				obj.src = info[1];
				obj.id = info[0];
				thumbnail9.appendChild(obj);
			}
		}
	}
}


function getThumbs(startIndex)
{
	var response = ratePhotos.GetThumbNails(startIndex);
	var dc = response.value;
	return dc;
}

function getPhoto(photoId)
{
	var response = ratePhotos.GetFullSizePhoto(photoId);
	var dc = response.value;
	return dc;
}

