// TorridArt.com
//
//********************************************//
//  Controls the slide show  //
//  Modified from www.vicsjavascripts.org.uk  //

function the_BAnimator(the_mde,the_obj,the_srt,the_fin,the_time){
 if (typeof(the_obj)=='string'){ the_obj=document.getElementById(the_obj); }
 if (!the_obj||(!the_srt&&!the_fin)) return;
 var the_oop=the_obj[the_mde.replace(/[-#]/g,'')+'oop'];
 if (the_oop){
  clearTimeout(the_oop.to);
  if (the_oop.srtfin[0]==the_srt&&the_oop.srtfin[1]==the_fin&&the_mde.match('#')) the_oop.update([the_oop.data[0],(the_oop.srtfin[0]==the_oop.data[2])?the_fin:the_srt],the_time);
  else the_oop.update([the_srt,the_fin],the_time);
 }
 else the_obj[the_mde.replace(/[-#]/g,'')+'oop']=new the_BAnimatorOOP(the_mde,the_obj,the_srt,the_fin,the_time);
}

function the_BAnimatorOOP(the_mde,the_obj,the_srt,the_fin,the_time){
 this.srtfin=[the_srt,the_fin];
 this.to=null;
 this.obj=the_obj;
 this.mde=the_mde.replace(/[-#]/g,'');
 this.update([the_srt,the_fin],the_time);
}

the_BAnimatorOOP.prototype.update=function(the_srtfin,the_time){
 this.time=the_time||this.time||2000;
 if (the_srtfin[0]==the_srtfin[1]) return;
 this.data=[the_srtfin[0],the_srtfin[0],the_srtfin[1]];
 this.srttime=new Date().getTime();
 this.cng();
}

the_BAnimatorOOP.prototype.cng=function(){
 var the_ms=new Date().getTime()-this.srttime;
 this.data[0]=(this.data[2]-this.data[1])/this.time*the_ms+this.data[1];
 if (this.mde!='opacity') this.obj.style[this.mde]=this.data[0]+'px';
 else  this.opacity(this.data[0]);
 if (the_ms<this.time) this.to=setTimeout(function(the_oop){return function(){the_oop.cng();}}(this), 10);
 else {
  if (this.mde!='opacity') this.obj.style[this.mde]=this.data[2]+'px';
  else  this.opacity(this.data[2]);
 }
}

the_BAnimatorOOP.prototype.opacity=function(the_opc){
 if (the_opc<0||the_opc>100){ return; }
 this.obj.style.filter='alpha(opacity='+the_opc+')';
 this.obj.style.opacity=this.obj.style.MozOpacity=this.obj.style.KhtmlOpacity=the_opc/100-.001;
}


function InitSlideShow(the_id,the_spd,the_hold,the_txt,the_auto){
 var the_p=document.getElementById(the_id);
 if (!the_p.slideshow) the_p.slideshow=new the_SlideShowOOP(the_p,the_spd,the_hold,the_txt,the_auto);
 else {
  var the_oop=the_p.slideshow;
  the_oop.spd=the_spd||the_oop.spd;
  the_oop.hold=the_hold||the_oop.hold;
 }
}

function the_SlideShowOOP(the_p,the_spd,the_hold,the_txt,the_auto){
 this.imgs=the_p.getElementsByTagName('IMG');
 for (var the_0=0;the_0<this.imgs.length;the_0++){
  the_BAnimator('opacity',this.imgs[the_0],(the_0==0)?90:10,(the_0==0)?100:0,10);
  the_ES(this.imgs[the_0],{zIndex:(the_0>0)?'0':'1',left:(the_p.offsetWidth-this.imgs[the_0].offsetWidth)/2+'px',top:(the_p.offsetHeight-this.imgs[the_0].offsetHeight)/2+'px',cursor:(this.imgs[the_0].parentNode.tagName.toUpperCase()=='A')?'pointer':'default'});
  if (this.imgs[the_0].style.cursor=='pointer'){
   this.imgs[the_0].link=this.imgs[the_0].parentNode.href||this.imgs[the_0].parentNode.title||null;
   this.imgs[the_0].parentNode.removeAttribute('title');
   this.imgs[the_0].onclick=function(){
     if (window[this.link]) window[this.link](this);
     else if (this.link) window.top.location=this.link;
    }
  }
  if (the_txt){
   this.imgs[the_0].txt=the_ES('DIV',{visibility:(this.imgs[the_0].title)?'visible':'hidden'},the_p,this.imgs[the_0].title||'');
   this.imgs[the_0].txt.className=the_txt;
   the_BAnimator('opacity',this.imgs[the_0].txt,(the_0==0)?90:10,(the_0==0)?100:0,10);
   this.imgs[the_0].removeAttribute('title');
  }
 }
 this.p=the_p;
 this.cnt=0;
 this.spd=the_spd||1000;
 this.hold=the_hold||this.spd*4;
 this.to=null;
 if (the_auto) this.to=setTimeout(function(the_oop){return function(){the_oop.auto(1);}}(this),this.hold);
}

the_SlideShowOOP.prototype.rotate=function(the_ud,the_goto){
 the_ES(this.imgs[this.cnt],{zIndex:'0'});
 the_BAnimator('opacity',this.imgs[this.cnt],this.imgs[this.cnt]['opacityoop'].data[0],0,this.spd)
 if (this.imgs[this.cnt].txt) the_BAnimator('opacity',this.imgs[this.cnt].txt,this.imgs[this.cnt].txt['opacityoop'].data[0],0,this.spd)
 this.cnt+=the_ud||0;
 if (the_goto) this.cnt=the_goto-1;
 if (this.cnt>=this.imgs.length) this.cnt=0;
 if (this.cnt<0) this.cnt=this.imgs.length-1;
 the_ES(this.imgs[this.cnt],{zIndex:'1'});
 the_BAnimator('opacity',this.imgs[this.cnt],this.imgs[this.cnt]['opacityoop'].data[0],100,this.spd)
 if (this.imgs[this.cnt].txt) the_BAnimator('opacity',this.imgs[this.cnt].txt,this.imgs[this.cnt].txt['opacityoop'].data[0],100,this.spd)
}

the_SlideShowOOP.prototype.auto=function(the_ud){
 this.rotate(the_ud);
 this.to=setTimeout(function(the_oop){return function(){the_oop.auto(the_ud);}}(this),this.hold);
}

function the_ES(the_ele,the_style,the_p,the_txt){
 if (typeof(the_ele)=='string'){ the_ele=document.createElement(the_ele); }
 for (key in the_style){ the_ele.style[key]=the_style[key]; }
 if (the_p){ the_p.appendChild(the_ele); }
 if (the_txt){ the_ele.appendChild(document.createTextNode(the_txt)); }
 return the_ele;
}

function TA_SlideShow(the_id,the_ud,the_auto){
 var the_oop=document.getElementById(the_id).slideshow;
 if (!the_oop) return false;
 clearTimeout(the_oop.to);
 if (!the_auto) the_oop.rotate(the_ud);
 else if (the_ud) the_oop.auto(the_ud);
}

function the_SlideShowGoTo(the_id,the_nu){
 var the_oop=document.getElementById(the_id).slideshow;
 if (!the_oop||!the_oop.imgs[the_nu-1]) return false;
 clearTimeout(the_oop.to);
 the_oop.rotate(0,the_nu)
}

//   END OF SLIDESHOW   //
//**********************//

// close windows and tabs
function closeWindow() {
   window.open('','_parent','');
   window.close();
}

//function notLogged() {
//    alert("Must be logged in to view photos");
//}

// ***************//
//   Alert Box    //

// constants to define the title of the alert and button text.
var ALERT_TITLE = "Oops!";
var ALERT_BUTTON_TEXT = "Ok";
//var alert_text = "You must be a registered user & logged in to view larger images";
//if (msg) alert_text = "you must be kidding";
// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
if(document.getElementById) {
	window.alert = function(txt) {
		createCustomAlert(txt);
	}
}

function createCustomAlert(txt) {
	// shortcut reference to the document object
	d = document;

	// if the modalContainer object already exists in the DOM, bail out.
	if(d.getElementById("modalContainer")) return;

	// create the modalContainer div as a child of the BODY element
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	 // make sure its as tall as it needs to be to overlay all the content on the page
	mObj.style.height = document.documentElement.scrollHeight + "px";

	// create the DIV that will be the alert
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
	if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
	// center the alert box
	alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";

	// create an H1 element as the title bar
	h1 = alertObj.appendChild(d.createElement("h1"));
	h1.appendChild(d.createTextNode(ALERT_TITLE));

	// create a paragraph element to contain the txt argument
	msg = alertObj.appendChild(d.createElement("p"));
//	msg.innerHTML = alert_text;
    if (txt) msg.innerHTML = txt;
    else msg.innerHTML = "You must be a registered user & logged in to view larger images";

	// create an anchor element to use as the confirmation button.
	btn = alertObj.appendChild(d.createElement("a"));
	btn.id = "closeBtn";
	btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	btn.href = "#";
	// set up the onclick event to remove the alert when the anchor is clicked
	btn.onclick = function() { removeCustomAlert();return false; }


}

// removes the custom alert from the DOM
function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}

// End of Alert Box //
// *****************//


// make sure browser windows close
var browserName=navigator.appName;
if (browserName=="Netscape") {

function closynoshowsme()
{
window.open('','_parent','');
window.close();}
}
else {
if (browserName=="Microsoft Internet Explorer")
{
function closynoshowsme()
{
window.opener = "whocares";
window.close();
}
}
}

// open uri in parent browser window, close popup
function changeParentWin(url){
    window.opener.location = url;
    parent.close();
}

// Validate the feedback form
// If a field is left blank, alert box
// If all fields are filled in, popup verification
function Validate_fb(form)
{
	var msg = "All fields must be filled in ...";
	var realname = document.forms['fb_me'].realname.value;
	var email = document.forms['fb_me'].email.value;
    var msg_subject = document.forms['fb_me'].msg_subject.value;
    var the_message = document.forms['fb_me'].the_message.value;
    var window_width = 300;
    var window_height = 200;
    var screen_height = window.screen.availHeight;
    var screen_width = window.screen.availWidth;
    var left_point = parseInt(screen_width / 2) - parseInt(window_width / 2);
    var top_point = parseInt(screen_height / 2) - parseInt(window_height / 2);
    var the_features = "width=" + window_width + ",height=" + window_height + ",top=" + top_point + ",left=" + left_point;

	// check for any space characters that may be input

  	if (realname == "" || realname == null || email == "" || email == null || msg_subject == "" || msg_subject == null || the_message == "" || the_message == null)
  	{
  		alert (msg);
  		return false;
  	}
    else
    {
  	var results_window = window.open('','results_window',the_features);
    results_window.focus();
    }
}


// Add favorite gallery to My Favorites
// Controls the popup verification window
//
function addFaves(abs_link)
{
    var window_width = 300;
    var window_height = 130;
    var screen_height = window.screen.availHeight;
    var screen_width = window.screen.availWidth;
    var left_point = parseInt(screen_width / 2) - parseInt(window_width / 2);
    var top_point = parseInt(screen_height / 2) - parseInt(window_height / 2);
    var the_features = "width=" + window_width + ",height=" + window_height + ",top=" + top_point + ",left=" + left_point;

  	var results_window = window.open(abs_link,'results_window',the_features);
    results_window.focus();
}


// Notify Me
// Controls the popup window
//
function notifyMe(mod_link)
{
    var window_width = 300;
    var window_height = 250;
    var screen_height = window.screen.availHeight;
    var screen_width = window.screen.availWidth;
    var left_point = parseInt(screen_width / 2) - parseInt(window_width / 2);
    var top_point = parseInt(screen_height / 2) - parseInt(window_height / 2);
    var the_features = "width=" + window_width + ",height=" + window_height + ",top=" + top_point + ",left=" + left_point;

  	var results_window = window.open(mod_link,'results_window',the_features);
    results_window.focus();
}

// Rate Model
// Controls the popup window
//
function rateModel()
{
    var window_width = 300;
    var window_height = 300;
    var screen_height = window.screen.availHeight;
    var screen_width = window.screen.availWidth;
    var left_point = parseInt(screen_width / 2) - parseInt(window_width / 2);
    var top_point = parseInt(screen_height / 2) - parseInt(window_height / 2);
    var the_features = "width=" + window_width + ",height=" + window_height + ",top=" + top_point + ",left=" + left_point;

  	var results_window = window.open('','results_window',the_features);
    results_window.focus();
}

// Validate the preferences form on member's home
// If both fields are left blank, alert box
// If a preference is selected, popup verification
function Validate_pref(form)
{
	var msg = "Please select preference(s)";
	var pic = document.forms['memprefs'].pic.value;
	var fave_order = document.forms['memprefs'].fave_order.value;
    var window_width = 300;
    var window_height = 160;
    var screen_height = window.screen.availHeight;
    var screen_width = window.screen.availWidth;
    var left_point = parseInt(screen_width / 2) - parseInt(window_width / 2);
    var top_point = parseInt(screen_height / 2) - parseInt(window_height / 2);
    var the_features = "width=" + window_width + ",height=" + window_height + ",top=" + top_point + ",left=" + left_point;

	// check for any space characters that may be input

  	if ((pic == "") && (fave_order == ""))
  	{
  		alert (msg);
  		return false;
  	}
    else
    {
  	var results_window = window.open('/pref_confirm.htm','results_window',the_features);
    results_window.focus();
    }
}



// Validate input from the newsletter opt-in
// If field is blank, alert box
function Validate_nl(form)
{
	var msg = "Must enter an email address...";
	var the_address = document.forms['notify_me'].YMLP0.value;

  	if (the_address == "" || the_address == null)
  	{
  		alert (msg);
  		return false;
  	}
}

