allowchange = 1

titletxt = ""


function gotodvd(v)
{
  with(v)
  {
    document.location = id[id.selectedIndex].value
  }

  return false;
}

function changevote(v)
{
  if (allowchange == 0)
  {
	return
  }

  for (i = 1; i <= 5; i++)
  {
    fr = document.getElementById("vote_" + i)

	src = ""

	if (v == ((i - 1) * 2) + 1)
	{
		src = "-half.gif"
	}
	else if (v < (i * 2))
	{
		src = "-faded.gif"
	}
	else
	{
		src = ".gif"
	}

    fr.src = "images/icons/star" + src
  }
}

function changevote2(v)
{
  if (allowchange == 0)
  {
	return
  }

  for (i = 1; i <= 5; i++)
  {
    fr = document.getElementById("vote_" + i)

	src = ""

	if (v == ((i - 1) * 2) + 1)
	{
		src = "-half2.gif"
	}
	else if (v < (i * 2))
	{
		src = "-faded2.gif"
	}
	else
	{
		src = "2.gif"
	}

    fr.src = "images/icons/star" + src
  }
}



function dovote(v, id, type)
{
  if (allowchange == 0)
  {
     return
  }

  if (window.XMLHttpRequest)
  {
    // If IE7, Mozilla, Safari, etc: Use native object
    var http = new XMLHttpRequest()
  }
  else
  {
     if (window.ActiveXObject)
     {
        // ...otherwise, use the ActiveX control for IE5.x and IE6
        var http = new ActiveXObject("Microsoft.XMLHTTP");
     }
  }


  var url = "vote.php"
  var params = "contentgroup=" +id+ "&vote=" + v + "&type=" + type + "&ajax=1"

  http.open("GET", url+"?"+params, true);
  http.onreadystatechange = function() 
  {
     	if(http.readyState == 4 && http.status == 200) 
        {
		  if (http.responseText == "done")
		  {
		    alert("Thank you for rating this update.");
			changevote(v)
		    allowchange= 0
        }
		  else
		  {
			alert("There was an error recording your vote.  Please try again later");
          	  }
	}
  }

  http.send(null);
}


function domodelvote(v, id)
{
  if (allowchange == 0)
  {
     return
  }

  if (window.XMLHttpRequest)
  {
    // If IE7, Mozilla, Safari, etc: Use native object
    var http = new XMLHttpRequest()
  }
  else
  {
     if (window.ActiveXObject)
     {
        // ...otherwise, use the ActiveX control for IE5.x and IE6
        var http = new ActiveXObject("Microsoft.XMLHTTP");
     }
  }


  var url = "vote.php"
  var params = "set=" +id+ "&vote=" + v + "&ajax=1"

  http.open("GET", url+"?"+params, true);
  http.onreadystatechange = function() 
  {
     	if(http.readyState == 4 && http.status == 200) 
        {
		  if (http.responseText == "done")
		  {
		    alert("Thank you for rating this model.");
			changevote2(v)
		    allowchange= 0
        }
		  else
		  {
			alert("There was an error recording your vote.  Please try again later");
          	  }
	}
  }

  http.send(null);
}

function jsgallery(cg, id, fid, settype, mt)
{
  var url = "image.php?cg=" + cg + "&type=" + settype + "&id=" + fid 
  if (mt != "")
  {
     url = url + "&mt=" + mt
  }
  url = url + "#id=" + id
  document.location = url
  return false
}

function retPicarr(picarr, id)
{
  for(i = 0; i < picarr.length; i++)
  {
    if (picarr[i][0] == id)
    {
	   return picarr[i]
    }
  }
}


function getPlayer(gid) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[gid];
	} else {
		return document[gid];
	}
};

function playerReady() 
{

    titletxt = document.title

	var obj = getPlayer("playerID")

	if (obj)
	{
		playerReady2();
	}
	else
	{
		setTimeout("playerReady()",100);
	}
}


function cPlayer(prr)
{
	pvv = 0;

	if (prr.length == 0)
	{
		return;
	}

    pa = retPicarr(prr, id)

    imgg = pa[1]
    wdth = parseInt(pa[2])
    hdth = parseInt(pa[3]) + 15

	barwidth= 205

	if (picarr.length == 1)
	{
		barwidth = 0
	}

	var s1 = new SWFObject("mediaplayer.swf","playerID",wdth+barwidth, hdth,"8");
	s1.addParam("allowfullscreen","true");
	s1.addParam("allowscriptaccess","always");
	s1.addVariable("autostart",false);
	s1.addVariable("smoothing","true");
	s1.addVariable("width",wdth+barwidth);
	s1.addVariable("height",hdth);

	if (barwidth != 0)
	{
		s1.addVariable("playlistsize",barwidth);
		s1.addVariable("playlist","right");
	    s1.addVariable("thumbsinplaylist","true")
	    s1.addVariable("repeat", "true");
		s1.addVariable("shuffle","false");
	}

	if (typeof(flashvar_arr) != "undefined")
	{
		for(var ix in flashvar_arr) 
		{
			s1.addVariable(ix, flashvar_arr[ix]);
		}
	}

 	s1.write("mediabox");


  spu = pa

  if (document.getElementById("sharevideourl") != undefined)
  { 
    document.getElementById("sharevideourl").href = "share.php?id=" + spu[0] + "&type=" + spu[4] + "&mt=" + spu[5]
  }
}







function RenderImg(picarr, id, divv)
{
  var poss = 0;
  dv = document.getElementById(divv)

  for(i = 0; i < picarr.length; i++)
  {
    if (picarr[i][0] == id)
    {
       imgg = picarr[i][1]
	   wdth = picarr[i][2]
	   hdth = parseInt(picarr[i][3]) + 75
	   movtype = picarr[i][4]
	   movname= picarr[i][5]
       poss = i
    }
  }

  if (dv == undefined)
  {
    return true
  }
  

  noman = document.getElementById("nomansland")


  var dot = imgg.lastIndexOf("."); 
  var extt = imgg.substr(dot,imgg.length); 

  if (movtype == undefined)
  {
    movtype = ""
  }

  if (movname == undefined)
  {
    movname = ""
  }

  if ((movname.indexOf("divx") != -1) || (movname.indexOf("xvid") != -1))
  {
	hdth = hdth - 55

     dc1 = document.location + ''
     dc = dc1.substring(7, dc1.indexOf('/',7)+1)

     dc = dc1.substr(0, 7) + dc;


     // Code to make sure videos work on strongbox.
	
     sbsession = getCookie("sbsession")
	
     if (sbsession != "")
     {
	sbsession = sbsession.split("&");
	sbsession = sbsession[0]
		
	if(dc.indexOf(sbsession) == -1)
	{
	   dc = dc.replace("http://", "http://" + sbsession + ".")
	}
     }
     else if(username != "")
     {
	dc = dc.replace("http://", "http://" + username + ":" + password + "@")
     }
     

     imgg = dc + imgg

     inht = ""
     inht += '<object classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616" width="'+wdth+'" height="'+hdth+'" ' 
     inht += ' codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab">'
     inht += ' <param name="custommode" value="none" />'
     inht += '  <param name="src" value="'+imgg+'" />'
     inht += '<embed type="video/divx" src="'+imgg+'" custommode="none" width="'+wdth+'" height="'+hdth+'" '
     inht += ' pluginspage="http://go.divx.com/plugin/download/">'
     inht += '</embed>'
     inht += '</object>'
     inht += '<p style="color:white;">No video? Get the DivX Web Player for <a style="text-decoration: underline;" ' 
     inht += ' href="http://download.divx.com/player/DivXWebPlayerInstaller.exe">Windows</a> or '
     inht += '<a style="text-decoration: underline;" href="http://download.divx.com/player/DivXWebPlayer.dmg">Mac</a></p>'

     dv.innerHTML = inht
  }
  else if ((extt == ".mov") || (extt == ".mp4"))
  {
	inht = ''
	inht += '<object width="'+wdth+'" height="'+hdth+'" '
	inht += 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '
	inht += 'codebase="http://www.apple.com/qtactivex/qtplugin.cab"> '
	inht += '<param name="src" value="'+imgg+'"> '
	inht += '<param name="autoplay" value="true"> '
	inht += '<param name="controller" value="true"> '
	inht += '<embed src="'+imgg+'" width="'+wdth+'" height="'+hdth+'" '
	inht += 'autoplay="true" controller="true" '
	inht += 'pluginspage="http://www.apple.com/quicktime/download/"> '
	inht += '</embed> '
	inht += '</object> '

	dv.innerHTML = inht
  }
  else if ((extt == ".rm") || (extt == ".rmvb"))
  {
	 inht = ""

     dc1 = document.location + ''
     dc = dc1.substring(7, dc1.indexOf('/',7)+1)
     dc = dc1.substr(0, 7) + dc;

	 imgg = dc + imgg


	 inht += '<OBJECT ID=RVOCX CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" WIDTH="'+wdth+'" HEIGHT="'+hdth+'"> '
	 inht += '<PARAM name="src" value="'+imgg+'"> '
	 inht += '<PARAM name="autostart" value="true"> '
	 inht += '<PARAM name="controls" value="imagewindow"> '
	 inht += '<PARAM name="console" value="video"> '
	 inht += '<EMBED TYPE="audio/x-pn-realaudio-plugin" SRC="'+imgg+'" WIDTH="'+wdth+'" HEIGHT="'+hdth+'" AUTOSTART="tue" CONTROLS="all" CONSOLE="video"> '
	 inht += '</EMBED> '
	 inht += '</OBJECT><br />'

	 inht += '<OBJECT ID=RVOCX CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" WIDTH="'+wdth+'" HEIGHT=36>'
	 inht += '<PARAM NAME="CONTROLS" VALUE="ControlPanel">'
	 inht += '<PARAM NAME="CONSOLE" VALUE="video">'
	 inht += '<EMBED SRC="plugin.rpm" WIDTH=350 HEIGHT=36 NOJAVA=true CONTROLS=ControlPanel CONSOLE=one>'
	 inht += '</OBJECT>'




	dv.innerHTML = inht
  }
  else if (noman == undefined)
  {
    htm = '<img src="' + imgg + '" />'
    dv.innerHTML = htm
  }
  else
  {
	inht = ""
	
	dc1 = document.location + ''
	dc = dc1.substring(7, dc1.indexOf('/',7)+1)
	dc = dc1.substr(0, 7) + dc;
	
	
	// Code to make sure videos work on strongbox.
	
	sbsession = getCookie("sbsession")
	
	if (sbsession != "")
	{
		sbsession = sbsession.split("&");
		sbsession = sbsession[0]
		
		if(dc.indexOf(sbsession) == -1)
		{
		dc = dc.replace("http://", "http://" + sbsession + ".")
		}
	}
	
	imgg = dc + imgg


	if (document.all) // IE
	{
	 inht += "<object id='mediabox' ";
	 inht += "classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' ";
	 inht += "codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701' ";
	 inht += "standby='Loading Microsoft Windows Media Player components...' ";
	 inht += "type='application/x-oleobject' width='"+wdth+"' height='"+hdth+"''> ";
	 inht += "<param name='fileName' value=\""+imgg+"\"/> ";
	 inht += "<param name='animationatStart' value='true' /> ";
	 inht += "<param name='transparentatStart' value='true' /> ";
	 inht += "<param name='autoStart' value=\"true\" /> ";
	 inht += "<param name='showControls' value=\"true\" /> ";
	 inht += "<param name=\"ShowStatusBar\" value=\"true\" /> ";
	 inht += "<param name='loop' value=\"0\" /> ";
	 inht += "</object>"
	}
	else
	{
	// Code for anything but IE.

	 inht += "<object classid=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" width=\""+wdth+"\" height=\""+hdth+"\" type=\"application/x-oleobject\" >"
	 inht += "<param name=\"fileName\" value=\""+imgg+"\">"
	 inht += "<param name=\"autostart\" value=\"1\">"
	 inht += "<param name=\"ShowStatusBar\" value=\"true\" /> ";
	 inht += "<param name='showControls' value=\"true\" /> ";
	 inht += "<param name=\"volume\" value=\"0\">"
	 inht += "<EMBED type=\"application/x-mplayer2\" pluginspage = \"http://www.microsoft.com/Windows/MediaPlayer/\" "
	 inht += "SRC=\""+imgg+"\" name=\"MediaPlayer1\" width=\""+wdth+"\" "
	 inht += "height=\""+hdth+"\" AutoStart=\"true\" ShowStatusBar=\"1\" ShowControls=\"1\"></EMBED>"
	 inht += "</object>"
	} 
	dv.innerHTML = inht


 }



  
  prevcss = (poss == 0) ? "nav_hid" : "nav_vis"
  nextcss = (poss == picarr.length - 1) ? "nav_hid" : "nav_vis"

  if (document.getElementById("gal_prevpage") != undefined)
  {
     document.getElementById("gal_prevpage").className = prevcss
  }

  if (document.getElementById("gal_nextpage"))
  {
    document.getElementById("gal_nextpage").className = nextcss
  }


  spu = picarr[poss]

  if (document.getElementById("sharevideourl") != undefined)
  { 
    document.getElementById("sharevideourl").href = "share.php?id=" + spu[0] + "&type=" + spu[4] + "&mt=" + spu[5]
  }


  TrackContent(spu)


  return false

}

function getCookie(c_name)
{
  if (document.cookie.length>0)
  {
	c_start=document.cookie.indexOf(c_name + "=");
	if (c_start!=-1)
    { 
    	c_start=c_start + c_name.length+1; 
	    c_end=document.cookie.indexOf(";",c_start);
    	if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }

  return "";
}

function NextImage()
{
  nid = 0

  for(i = 0; i < picarr.length; i++)
  {
    if (picarr[i][0] == id)
    {
       nid = i
    }
  }

  if (picarr[nid+1] != undefined)
  {
	if (picarr[nid+1][1] == "#trial#")
	{
	    document.location = nourl
	    return false
	}

    id = picarr[nid+1][0]
    imgg = picarr[nid+1][1]

    noman = document.getElementById("nomansland")
    flash = document.getElementById("flashplayer")


    if (flash != null)
	{
		ply = getPlayer("playerID")
		itm = parseInt(ply.getConfig().item) + 1
		ply.sendEvent("ITEM", itm);
		ply.sendEvent("PLAY", "true");
		
	    if (document.getElementById("sharevideourl") != undefined)
	    { 
	      spu = picarr[nid+1]
	      document.getElementById("sharevideourl").href = "share.php?id=" + spu[0] + "&type=" + spu[4] + "&mt=" + spu[5]
	    }
	
		document.location = "#" + id

		prevcss = (nid+1 == 0) ? "nav_hid" : "nav_vis"
		nextcss = (nid+1 == picarr.length - 1) ? "nav_hid" : "nav_vis"
		
		document.getElementById("gal_prevpage").className = prevcss
		document.getElementById("gal_nextpage").className = nextcss
	}
    else if (noman != null)
	{
		document.location = "#id=" + id
		window.location.reload();
	}
	else
	{
		document.location = "#id=" + id
    	return RenderImg(picarr, id, "mediabox")
	}
  }

  return false
}

function PrevImage()
{
  nid = 0

  for(i = 0; i < picarr.length; i++)
  {
    if (picarr[i][0] == id)
    {
       nid = i
    }
  }

  if (picarr[nid-1] != undefined)
  {
	if (picarr[nid-1][1] == "#trial#")
	{
	    document.location = nourl
	    return false
	}

    id = picarr[nid-1][0]
    imgg = picarr[nid-1][1]



    noman = document.getElementById("nomansland")
    flash = document.getElementById("flashplayer")


	
    if (flash != null)
	{
		ply = getPlayer("playerID")
		itm = parseInt(ply.getConfig().item) - 1
		ply.sendEvent("ITEM", itm);
		ply.sendEvent("PLAY", "true");

	    if (document.getElementById("sharevideourl") != undefined)
	    { 
	      spu = picarr[nid-1]
	      document.getElementById("sharevideourl").href = "share.php?id=" + spu[0] + "&type=" + spu[4] + "&mt=" + spu[5]
	    }

		document.location = "#" + id

		prevcss = (nid-1 == 0) ? "nav_hid" : "nav_vis"
		nextcss = (nid-1 == picarr.length - 1) ? "nav_hid" : "nav_vis"
		
		document.getElementById("gal_prevpage").className = prevcss
		document.getElementById("gal_nextpage").className = nextcss
	}
    else if (noman != null)
	{
		document.location = "#id=" + id
		window.location.reload();
		return false
	}
	else
	{
		document.location = "#id=" + id
    	return RenderImg(picarr, id, "mediabox")
	}
  }

  return false
}


// What happens when a flash movie goes to the next clip.

function playState(obj)
{
  ind = obj.index
  spu = picarr[ind]

  dl = document.location
  document.location = "#" + spu[0]
  document.title = titletxt


  id = spu[0]

  if (document.getElementById("sharevideourl") != undefined)
  { 
    document.getElementById("sharevideourl").href = "share.php?id=" + spu[0] + "&type=" + spu[4] + "&mt=" + spu[5]
  }

  TrackContent(spu)
}

function TrackContent(suu)
{
   url = "stattrack.php?pagename=image&id=" + suu[0] + "&cg=" + suu[6] + "&type=" + suu[4] + "&mt=" + suu[5];
   url = url + "&rnd=" + Math.floor(Math.random()*1000000)

   if (window.XMLHttpRequest)
   {
     // If IE7, Mozilla, Safari, etc: Use native object

     var http = new XMLHttpRequest()
   }
   else
   {
     if (window.ActiveXObject)
     {
        // ...otherwise, use the ActiveX control for IE5.x and IE6
        var http = new ActiveXObject("Microsoft.XMLHTTP");
     }
   }

  http.open("GET", url, true);
  http.send(null);
}



// CALENDAR POPUP CODE


var ie  = document.all

function positionoffset(wg, ot)
{
	var toff = (ot=="left") ? wg.offsetLeft : wg.offsetTop;
	var parentEl = wg.offsetParent;
	while (parentEl != null)
	{
		toff = (ot=="left") ? toff + parentEl.offsetLeft : toff + parentEl.offsetTop;
		parentEl = parentEl.offsetParent;
	}
	return toff;
}

function showhideobject(obj, e)
{
	dropmenuobj.style.left = dropmenuobj.style.top="-500px"
	if (e.type=="mouseover")
	{
		obj.visibility="visible"
	}
}

function ietest()
{
	if (document.compatMode && document.compatMode!="BackCompat")
	{
		return document.documentElement
	}
	else
	{
		document.body
	}
}

function clearedge(obj, wedge)
{
	if (wedge=="rightedge")
	{
		eoffx=0
		var winedge = ie && !window.opera ? ietest().scrollLeft + ietest().clientWidth-15 : window.pageXOffset+window.innerWidth - 15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (winedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			eoffx=dropmenuobj.contentmeasure-obj.offsetWidth
		return eoffx
	}
	else
	{
		eoffy=0
		var topedge = ie && !window.opera? ietest().scrollTop : window.pageYOffset
		var winedge=ie && !window.opera? ietest().scrollTop+ ietest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (winedge-dropmenuobj.y < dropmenuobj.contentmeasure) //move up?
			eoffy=dropmenuobj.contentmeasure+obj.offsetHeight
		return eoffy
	}
}

function displaycalendarpopup(obj, e)
{
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	if (typeof dropmenuobj!="undefined")
		dropmenuobj.style.visibility="hidden"

	clearhidemenu()
	dropmenuobj=document.getElementById(obj.getAttribute("popid"))
	showhideobject(dropmenuobj.style, e)
	dropmenuobj.x = positionoffset(obj, "left")
	dropmenuobj.y = positionoffset(obj, "top")
	dropmenuobj.style.left=dropmenuobj.x-clearedge(obj, "rightedge")+"px"
	dropmenuobj.style.top=dropmenuobj.y-clearedge(obj, "bottomedge")+obj.offsetHeight+"px"
}


function delayhidemenu()
{
	delayhide=setTimeout("dropmenuobj.style.visibility='hidden'; dropmenuobj.style.left=0; ",250)
}

function clearhidemenu()
{
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide)
}

function popidtoelement(linkobj)
{ 
	var relvalue=linkobj.getAttribute("popid")
	return (relvalue!=null && relvalue!="" && document.getElementById(relvalue)!=null && document.getElementById(relvalue).className=="calendarpopup")? true : false
}

function initcal()
{
	var all_links=document.getElementsByTagName("a")
	for (var i=0; i<all_links.length; i++)
	{
		if (popidtoelement(all_links[i]))
		{
			all_links[i].onmouseover=function(e)
			{
				var evtobj=window.event? window.event : e
				displaycalendarpopup(this, evtobj)
			}

			all_links[i].onmouseout=delayhidemenu
		}
	}
}

if (window.addEventListener)
	window.addEventListener("load", initcal, false)
else if (window.attachEvent)
	window.attachEvent("onload", initcal)
else if (document.getElementById)
	window.onload=initcal

