// adds hover functionality to IE
sfHover = function() {
	var sfEls = document.getElementById("navbar").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}




// controls forgot your password button
function forgotPass() {
	var username = document.getElementById('username').value;
	if (username == "username") {username = "";}
	window.location = '/members/profile.php?action=lost_password&username='+username;
}




// clears login form inputs on click
// the input's name attribute should be the same as it's initial value
function clearInput(input) {
	// change password fields to password type for security
	if (input.value == 'password') {input.type = 'password';}
	
	// clear field unless something was perviously entered
	if (input.value == input.name) {input.value = '';}
	
	// if nothing entered, replace initial value
	input.onblur = function() {
		if (input.value == '') {
			input.value = input.name;
			if (input.type == 'password') {input.type = 'text';}
		}
	}	
}




// http://www.dynamicsitesolutions.com/javascript/change-input-type-dynamically/
function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var isMSIE=/*@cc_on!@*/false; //http://dean.edwards.name/weblog/2007/03/sniff/
  if(!isMSIE){
    var newElm=document.createElement('input');
    newElm.type=iType;
  } else {
    var newElm=document.createElement('span');
    newElm.innerHTML='<input type="'+iType+'" name="'+oldElm.name+'">';
    newElm=newElm.firstChild;
  }
  var props=['name','id','className','size','tabIndex','accessKey'];
  for(var i=0,l=props.length;i<l;i++){
    if(oldElm[props[i]]) newElm[props[i]]=oldElm[props[i]];
  }
  newElm.onfocus=function(){return function(){
    if(this.hasFocus) return;
    var newElm=changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur=function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  // some browsers need the value set before the element is added to the page
  // while others need it set after
  if(!blankValue) newElm.value=iValue;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!isMSIE && !blankValue) newElm.value=iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm=newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}




// sets up flash player

function createPlayer(dir,filename,width,height,auto) {
		if(!width) var width = '750';
		if(!height) var height = '420';
		if(!auto) var auto = 'true';
		var base = filename.substring(0, filename.indexOf('.'));
		var flashvars = {
						file:"/videos/"+dir+base+".flv", 
						autostart:auto, 
//						streamer:"rtmp://www.dragraceplace.com/oflaDemo/DRP/"+dir,
						bufferlength:2
		}
		var params = {
						allowfullscreen:"true", 
						allowscriptaccess:"always"
		}
		var attributes = {
						id:base,  
						name:base
		}
		swfobject.embedSWF("/jw/player.swf", "video", width, height, "9.0.115", "/jw/expressInstall.swf", flashvars, params, attributes);
}




// sets up flow player
function createFlowPlayer(dir,filename,width,height) {
		if(!width) var width = '750';
		if(!height) var height = '420';
		var base = filename.substring(0, filename.indexOf('.'));
		var flashvars = {
						file:base+".flv", 
						autostart:"true", 
						streamer:"rtmp://www.dragraceplace.com/oflaDemo/DRP/"+dir,
						bufferlength:2
		}
		var params = {
						allowfullscreen:"true", 
						allowscriptaccess:"always"
		}
		var attributes = {
						id:base,  
						name:base
		}
		swfobject.embedSWF("/flowplayer/FlowPlayerDark.swf", "video", width, height, "9.0.115", "", flashvars, params, attributes);
}




function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  var arr = new Array(scrOfX, scrOfY);
  return arr;
}




function getWinSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var arr = new Array(myWidth, myHeight);
  return arr;
}




// puts the gradient image at the absolute bottom of the browser
function btmGrad() {
	var scr = getScrollXY();
	var win = getWinSize();
	var topOffset = scr[1]+win[1]-500+'px';
	// prototype stuff...
	var ele = $('grad_btm');
	ele.setStyle({top: topOffset});
}




// remove empty girl gallery thumbnails
function checkThumbs() {
  for(var i = 1; i <= 3; i++) {
    var thumb = document.getElementById("girlthumb"+i);
    if(thumb) {
      var box = document.getElementById("girlthumbbox"+i);
      var ih = thumb.innerHTML;
      document.write("<div style='visibility:hidden;'>"+ih.substr(0,30)+"</div>");
      if(!ih.indexOf){
    
      } else {
        var indexnum = ih.indexOf("href");
        //document.write("<div style='visibility:hidden;'>"+ih+"</div>");
        if(indexnum == -1) {
          box.innerHTML = "";
          //document.write("<div style='visibility:hidden;'>removed</div>");
        }
      }
    }
  }
}