// JavaScript Document
function El(id)
{
	return document.getElementById(id);
}

function HideElem(elemId1, elemId2)
{
	if (elemId2 && El(elemId2)) El(elemId2).innerHTML="";
	if (El(elemId1)) El(elemId1).style.display = "none";
}

function ToggleDisplay(elemId)
{
	if (!El(elemId)) return;

	if (El(elemId).style.display == "none")
		El(elemId).style.display = "";
	else
		El(elemId).style.display = "none";
}

function ShowElem(elemId)
{
	if (El(elemId)) El(elemId).style.display = "";
}


function TrimStr(s)
{
	return s.replace(/^\s+|\s+$/, '');
}

function CheckEmail(address)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,6})$/;
	return reg.test(TrimStr(address));
}

function FixLocation(divId, w, h)
{
	var tmpDiv = El(divId);
	if (tmpDiv == null) return;

	if (w == 0) w = tmpDiv.offsetWidth;
	if (h == 0) h = tmpDiv.offsetHeight;

	var topDelta;
	if (self.pageYOffset)
		topDelta = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		topDelta = self.document.documentElement.scrollTop;
	else if (document.body)
		topDelta = document.body.scrollTop;
	else
		topDelta = Math.floor(h / 2);

	topDelta -= Math.floor(h / 2);

	if (window.innerHeight)
		tmpDiv.style.top = Math.max(0, window.innerHeight / 2 + topDelta) + "px";
	else if (document.documentElement.clientHeight)
		tmpDiv.style.top = Math.max(0, document.documentElement.clientHeight / 2  + topDelta) + "px";
	else
		tmpDiv.style.top = (300 + topDelta) + "px";

	if (window.innerWidth)
		tmpDiv.style.left = Math.max(0, window.innerWidth / 2 - Math.floor(w / 2)) + "px";
	else if (document.documentElement.clientWidth)
		tmpDiv.style.left = Math.max(0, document.documentElement.clientWidth / 2 - Math.floor(w / 2)) + "px";
}

function GetWindowSize()
{
	var w = 1024, h = 768;

	if (window.innerHeight)
		h = window.innerHeight;
	else if (document.documentElement.clientHeight)
		h = document.documentElement.clientHeight;

	if (window.innerWidth)
		w = window.innerWidth;
	else if (document.documentElement.clientWidth)
		w = document.documentElement.clientWidth;

	return { x: w, y: h }
}

function HideWaitLayer()
{
	HideElem("waitDiv");
	HideElem("waitImage");
}

var showWaitImage = true;

function ShowWaitLayer()
{
	var tmpDiv = El("waitDiv");
	if (tmpDiv == null) return;

	tmpDiv.style.opacity = 0.8;
	tmpDiv.style.filter = "alpha(opacity=80)";
	tmpDiv.style.top = "0px";
	tmpDiv.style.left = "0px";

	var tmpImage = El("waitImage");
	tmpImage.style.opacity = 0.8;
	tmpImage.style.filter = "alpha(opacity=80)";
	if (showWaitImage)
		tmpImage.style.display = "block";
	else
		tmpImage.style.display = "none";
	FixLocation("waitImage", 0, 0);

	var h = 0;
	if (window.innerHeight)
		h = window.innerHeight;
	else if (document.documentElement.clientHeight)
		h = document.documentElement.clientHeight;

	if (document.body.scrollHeight > document.body.offsetHeight)
	{
		tmpDiv.style.width = document.body.scrollWidth + "px";
		tmpDiv.style.height = Math.max(h, document.body.scrollHeight) + "px";
	}
	else
	{
		tmpDiv.style.width = document.body.offsetWidth + "px";
		tmpDiv.style.height = Math.max(h, document.body.offsetHeight) + "px";
	}
	tmpDiv.style.display = "block";
}

function UnblockBackgroundAccess()
{
	HideElem("blankDiv");
	HideElem("iframeFix");
}

function BlockBackgroundAccess()
{
	var tmpDiv = El("blankDiv");
	if (tmpDiv == null) return;

	tmpDiv.style.opacity = 0.4;
	tmpDiv.style.filter = "alpha(opacity=40)";
	tmpDiv.style.top = "0px";
	tmpDiv.style.left = "0px";

	var h = 0;
	if (window.innerHeight)
		h = window.innerHeight;
	else if (document.documentElement.clientHeight)
		h = document.documentElement.clientHeight;

	if (document.body.scrollHeight > document.body.offsetHeight)
	{
		tmpDiv.style.width = document.body.scrollWidth + "px";
		tmpDiv.style.height = Math.max(h, document.body.scrollHeight) + "px";
	}
	else
	{
		tmpDiv.style.width = document.body.offsetWidth + "px";
		tmpDiv.style.height = Math.max(h, document.body.offsetHeight) + "px";
	}
	tmpDiv.style.display = "block";
	var tmpFrame = El("iframeFix");
	if (tmpFrame)
	{
		// IE6 fix
		tmpFrame.style.width = tmpDiv.style.width;
		tmpFrame.style.height = tmpDiv.style.height;
		tmpFrame.style.filter = "alpha(opacity=0)";
		tmpFrame.style.display = "block";
	}
}

function PopUp(divId, w, h)
{
	ContinueFixLocation(divId);
	FixLocation(divId, w, h);

	var tmpDiv = El(divId);
	if (tmpDiv == null) return;
	FadeIn(divId, 100, "block");

	BlockBackgroundAccess();
	FixLocation(divId, w, h);
}

function PopUpAjax(url, divId1, divId2, w, h, postAction)
{
	if (!divId1) divId2 = "popUpDiv";
	if (!divId2) divId2 = divId1;
	if (!w) w = 0;
	if (!h) h = 0;
	if (!postAction) postAction = "";
	LoadAsyncToDiv(url, divId1, "FixLocation('" + divId2 + "', " + w + "," + h + "); setTimeout(\"PopUp('" + divId2 + "', " + w + "," + h + ")\", 100);" + postAction);
}

var fixLocationDisabled = new Object();

function KeepCenter(divId, w, h)
{
	if (!fixLocationDisabled[divId])
		FixLocation(divId, w, h);
	setTimeout("KeepCenter('" + divId + "', " + w + ", " + h + ")", 20);
}

function StopFixLocation(divId)
{
	fixLocationDisabled[divId] = true;
}

function ContinueFixLocation(divId)
{
	fixLocationDisabled[divId] = false;
}


var waitQueueCount = 0;

function IncreaseWaitQueue()
{
	waitQueueCount++;
	if (waitQueueCount == 1)
	{
		ShowWaitLayer();
	}
}

function DecreaseWaitQueue()
{
	waitQueueCount--;
	if (waitQueueCount <= 0)
	{
		// Hide the animated waiting icon
		HideWaitLayer();
	}
}

// Get an instance of the XMLHttpRequest object
function GetXHRObject()
{
	var xhr = null; // The XMLHTTPRequest object

	if (window.XMLHttpRequest) // Gecko and Opera
		xhr = new XMLHttpRequest();
	else if (window.ActiveXObject) // Internet Explorer
		xhr = new ActiveXObject("Microsoft.XMLHTTP");

	return xhr;
}

// Send a GET request and load the received content into the given div
function LoadAsyncToDiv(url, divId, postAction, preAction)
{
	var xhr = GetXHRObject();

	if (xhr == null)
	{
		alert("Sorry, your browser doesn't support AJAX");
		return;
	}
	xhr.open("GET", url, true);

	IncreaseWaitQueue();

	xhr.onreadystatechange = function()
	{
		if (xhr.readyState == 4) // data received
		{
			var r = xhr.responseText;
			if (TrimStr(r) != "")
			{
				if (r.substring(0, 100).search(/\<html/) > -1)
				{
					// sparta f*cked up
					alert("Session timeout! Please refresh your browser window and relogin.");
					return;
				}
				if (preAction != null)
					eval(preAction); // execute additional code

				if (divId == "script")
					eval(r);
				else if (divId == "alert")
					alert(r);
				else if (El(divId))
					El(divId).innerHTML = r; // insert the received content into the div

				if (postAction != null)
					eval(postAction); // execute additional code
			}
			else
			{
				alert("Transmission failed! Connection error or server too busy!");
			}
			DecreaseWaitQueue();
		}
	}
	// Send the request
	xhr.send(null);
}

// Send a POST request and load the received content into the given div
// POST paramerters are urlencoded and stored in encodedData
function LoadAsyncToDivPost(url, encodedData, divId, postAction, preAction)
{
	var xhr = GetXHRObject();

	if (xhr == null)
	{
		alert("Sorry, your browser doesn't support AJAX");
		return;
	}
	xhr.open("POST", url, true);
	IncreaseWaitQueue();

	xhr.onreadystatechange = function()
	{
		if (xhr.readyState == 4) // data received
		{
			var r = xhr.responseText;
			if (TrimStr(r) != "")
			{
				if (r.substring(0, 100).search(/\<html/) > -1)
				{
					// sparta f*cked up
					alert("Session timeout! Please refresh your browser window and relogin.");
					return;
				}
				if (preAction != null)
					eval(preAction); // execute additional code

				if (divId == "script")
					eval(r);
				else if (divId == "alert")
					alert(r);
				else if (El(divId))
					El(divId).innerHTML = r; // insert the received content into the div

				if (postAction != null)
					eval(postAction); // execute additional code
			}
			else
			{
				alert("Transmission failed! Connection error or server too busy!");
			}
			DecreaseWaitQueue();
		}
	}

	// Send the request
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.send(encodedData);
}

var dragObject = null;
var dragObject2 = null; // for IE 6
var mouseOffset = {x: 0, y: 0};
var mouseDown = false;

function GetMousePos(e)
{
	if (e.pageX || e.pageY)
	{
		return { x: e.pageX, y: e.pageY };
	}
	else
	{
		var tmpx = e.clientX + document.body.scrollLeft - document.body.clientLeft;
		var tmpy = e.clientY + document.body.scrollTop - document.body.clientTop;
		return { x: tmpx, y: tmpy };
	}
}


function GetMouseOffset(elem, e)
{
	if (!e) e = window.event;

	var offset = GetPosition(elem);
	var mousePos = GetMousePos(e);
	return { x: mousePos.x - offset.x, y: mousePos.y - offset.y };
}

function GetPosition(elem)
{
	var left = 0;
	var top  = 0;

	while (elem.offsetParent)
	{
		left += elem.offsetLeft;
		top  += elem.offsetTop;
		elem = elem.offsetParent;
	}

	left += elem.offsetLeft;
	top += elem.offsetTop;

	return { x: left, y: top };
}

function MouseMoved(e)
{
	if (!e) e = window.event;

	if (dragObject)
	{
		var mousePos = GetMousePos(e);
		dragObject.style.top = (mousePos.y - mouseOffset.y) + "px";
		dragObject.style.left = (mousePos.x - mouseOffset.x) + "px";
		if (dragObject2)
		{
			dragObject2.style.top = (mousePos.y - mouseOffset.y) + "px";
			dragObject2.style.left = (mousePos.x - mouseOffset.x) + "px";
		}
		return false;
	}
}

function DummyHandler(e)
{
	// do nothing
}

function MouseReleased()
{
	if (dragObject) dragObject.onmousedown = DummyHandler;

	dragObject = null;
	dragObject2 = null;
	mouseDown = false;
}

function StartDrag(id, id2)
{
	var item = El(id);

	if (!item) return;

	dragObject = item;
	dragObject2 = El(id2);

	item.onmousedown = function(e)
	{
		dragObject = this;
		mouseOffset = GetMouseOffset(this, e);
		return false;
	}
}

function StopBubble(e)
{
	if (!e) e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

document.onmousemove = MouseMoved;
document.onmouseup = MouseReleased;

var preloadImageTmpImage = null;
var preloadImageAction = "";
var preloadImageCounter = 0;
var preloadImageIntervalId = null;
var lastPreloadedImage = null;
var preloadImageMinDelay = 0;

function PreloadImage(url, onDone, minDelay)
{
	if (preloadImageIntervalId != null)
	{
		clearInterval(preloadImageIntervalId);
		preloadImageIntervalId = null
	}
	var oldAction = preloadImageAction;
	preloadImageTmpImage = new Image();
	preloadImageTmpImage.src = url;

	preloadImageCounter = 0;
	preloadImageAction = onDone;

	preloadImageMinDelay = (!minDelay? 0 : minDelay);
	preloadImageIntervalId = setInterval("CheckImagePreloading();", 10);

	// fire the old action if any
	if (oldAction != "") eval(oldAction);
}

function CheckImagePreloading()
{
	preloadImageCounter++; // max 50 second

	if (preloadImageCounter > preloadImageMinDelay &&
		(preloadImageTmpImage == null || preloadImageTmpImage.complete || preloadImageCounter > 5000))
	{
		clearInterval(preloadImageIntervalId);
		lastPreloadedImage = preloadImageTmpImage;
		preloadImageIntervalId = null;
		preloadImageTmpImage = null;

		var oldAction = preloadImageAction;
		preloadImageAction = "";
		preloadImageCounter = 0;

		// fire the old action if any
		if (oldAction != "") eval(oldAction);
	}
}

function FocusCommentBox()
{
	if (El("commentBox"))
	{
		if (El("commentBox").style.display == "none")
			FadeIn("commentBox");
		El("commentName").focus();
	}
}

function SubmitGirlComment()
{
	if (!document.girlCommentForm) return false;
	if (TrimStr(document.girlCommentForm.comment_name.value) == "")
	{
		document.girlCommentForm.comment_name.focus();
		return false;
	}

	if (TrimStr(document.girlCommentForm.comment_email.value) != "" &&
 		!CheckEmail(document.girlCommentForm.comment_email.value))
	{
		document.girlCommentForm.comment_email.focus();
		return false;
	}

	if (TrimStr(document.girlCommentForm.comment_comment.value) == "")
	{
		document.girlCommentForm.comment_comment.focus();
		return false;
	}

	var url = "./?action=add-comment";
	var encodedData =
		"name=" + encodeURIComponent(document.girlCommentForm.comment_name.value) +
		"&email=" + encodeURIComponent(document.girlCommentForm.comment_email.value) +
		"&comment=" + encodeURIComponent(document.girlCommentForm.comment_comment.value) +
		"&rating=" + encodeURIComponent(document.girlCommentForm.comment_rating.value);

	document.girlCommentForm.disabled = true;

	LoadAsyncToDivPost(url, encodedData, "commentsContainer");
	// ok
}

function SubmitWebmasterContact()
{
	if (!document.wmContactForm) return false;
	if (!CheckEmail(document.wmContactForm.wm_email.value))
	{
		document.wmContactForm.wm_email.focus();
		return false;
	}

	if (TrimStr(document.wmContactForm.wm_message.value) == "")
	{
		document.wmContactForm.wm_message.focus();
		return false;
	}

	if (TrimStr(document.wmContactForm.wm_code.value) == "")
	{
		document.wmContactForm.wm_code.focus();
		return false;
	}

	var url = "./?action=add-message";
	var encodedData =
		"&email=" + encodeURIComponent(document.wmContactForm.wm_email.value) +
		"&messenger=" + encodeURIComponent(
  			document.wmContactForm.wm_messenger_type.value + ":" +
			document.wmContactForm.wm_messenger.value) +
		"&message=" + encodeURIComponent(document.wmContactForm.wm_message.value) +
		"&code=" + encodeURIComponent(document.wmContactForm.wm_code.value);

	document.wmContactForm.disabled = true;
	LoadAsyncToDivPost(url, encodedData, "alert",
 		"document.wmContactForm.disabled=false; El('captchaImage').src=appRoot + 'contact/?action=captcha&code=' + Math.random();");
}

function FadingIn(id, op, maxOp)
{
	if (!El(id)) return;
	if (El(id).fading != "in") return;

	op += 10;
	if (op > maxOp) op = maxOp;

	El(id).currentOpacity = op;
	El(id).style.opacity = op / 100;
	El(id).style.filter = "alpha(opacity=" + op + ")";
	if (op < maxOp)
		setTimeout("FadingIn('" + id + "', " + op + ", " + maxOp + ")", 40);
}

function FadingOut(id, op)
{
	if (!El(id)) return;
	if (El(id).fading != "out") return;

	op -= 10;
	if (op <= 0)
	{
		op = 0;
		El(id).style.display = "none";
	}
	El(id).currentOpacity = op;
	El(id).style.opacity = op / 100;
	El(id).style.filter = "alpha(opacity=" + op + ")";
	if (op > 0)
		setTimeout("FadingOut('" + id + "', " + op + ")", 40);
}

function FadeIn(id, maxOp, display, start)
{
	if (!El(id)) return;

	if (!maxOp) maxOp = 100;
	if (El(id).currentOpacity)
		op = El(id).currentOpacity;
	else
		op = 0;
	if (start && op < start)
		op = start;

	El(id).fading = "in";
	El(id).currentOpacity = op;
	El(id).style.opacity = op / 100;
	El(id).style.filter = "alpha(opacity=" + op + ")";
	if (!display)
		El(id).style.display = "";
	else
		El(id).style.display = display;
	FadingIn(id, op, maxOp);
}

function FadeOut(id, maxOp)
{
	if (!El(id)) return;

	if (!maxOp) maxOp = 100;
	if (El(id).currentOpacity)
		maxOp = El(id).currentOpacity;

	El(id).fading = "out";
	El(id).currentOpacity = maxOp;
	El(id).style.opacity = maxOp / 100;
	El(id).style.filter = "alpha(opacity=" + maxOp + ")";
	FadingOut(id, maxOp);
}

function SetOpacity(id, op)
{
	if (!El(id)) return;
	El(id).style.opacity = op / 100;
	El(id).style.filter = "alpha(opacity=" + op + ")";
}

function SubmitSiteComment()
{
	if (!document.siteCommentForm) return false;
	if (TrimStr(document.siteCommentForm.comment_name.value) == "")
	{
		document.siteCommentForm.comment_name.focus();
		return false;
	}

	if (TrimStr(document.siteCommentForm.comment_email.value) &&
		!CheckEmail(document.siteCommentForm.comment_email.value))
	{
		document.siteCommentForm.comment_email.focus();
		return false;
	}

	if (TrimStr(document.siteCommentForm.comment_comment.value) == "")
	{
		document.siteCommentForm.comment_comment.focus();
		return false;
	}

	var url = "./?action=add-comment";
	var encodedData =
		"name=" + encodeURIComponent(document.siteCommentForm.comment_name.value) +
		"&email=" + encodeURIComponent(document.siteCommentForm.comment_email.value) +
		"&comment=" + encodeURIComponent(document.siteCommentForm.comment_comment.value) +
		"&rating=" + encodeURIComponent(document.siteCommentForm.comment_rating.value);

	document.siteCommentForm.comment_name.disabled = true;
	document.siteCommentForm.comment_email.disabled = true;
	document.siteCommentForm.comment_comment.disabled = true;
	document.siteCommentForm.comment_rating.disabled = true;
	document.siteCommentForm.comment_submit.disabled = true;
	document.siteCommentForm.disabled = true;

	LoadAsyncToDivPost(url, encodedData, "commentsContainer");
	// ok
}

function SubscribeNewsletter()
{
	if (document.headerForm.subscribe.readOnly || !CheckEmail(document.headerForm.subscribe.value))
	{
		document.headerForm.subscribe.focus();
		return false;
	}
	else
	{
		 LoadAsyncToDivPost(appRoot + "?page=subscribe",
   			"email=" + encodeURIComponent(document.headerForm.subscribe.value), "alert");
	}
}

function SetAutoScrollH(obj)
{
	if (!obj) return;

	obj.scrollDirection = 0;
	obj.onmousemove = function (e)
	{
		var mouseOffset = GetMouseOffset(this, e);
		if (mouseOffset.x < 60)
			this.scrollDirection = -1;
		else if (mouseOffset.x > this.offsetWidth - 60)
			this.scrollDirection = 1;
		else
			this.scrollDirection = 0;
	};
	obj.onmouseout = function(e)
	{
		// this.scrollDirection = 0;
	};
	setInterval("CheckScrollH(El('" + obj.id + "'));", 30);
}

function CheckScrollH(obj)
{
	if (obj.scrollDirection > 0)
	{
		var oldScroll = obj.scrollLeft;
		obj.scrollLeft += 15;
		if (oldScroll + 15 > obj.scrollLeft)
			obj.scrollDirection = 0;
	}
	else if (obj.scrollDirection < 0)
	{
		obj.scrollLeft -= 15;
		if (obj.scrollLeft <= 0)
			obj.scrollDirection = 0;
	}
}


function FixPopUpImageSize()
{
	HideElem("imageDiv");
	var bound = GetWindowSize();
	var img = El("imageDivPicture");
	if (lastPreloadedImage == null)
	{
		DecreaseWaitQueue();
		return;
	}
	img.src = lastPreloadedImage.src;

	var bx = bound.x - 48;
	var by = bound.y - 32;

	var w = lastPreloadedImage.width, h = lastPreloadedImage.height;
	img.origWidth = w;
	img.origHeight = h;

	if (w > bx || h > by)
	{
		// resize the image
		var ratio = w / h;
		if (ratio > bx / by)
			by = Math.round(bx / ratio);
		else
			bx = Math.round(by * ratio);

		bx = Math.max(1, bx);
		by = Math.max(1, by);
		img.width = bx;
		img.height = by;
		ShowElem("imageDivGlass");
	}
	else
	{
		HideElem("imageDivGlass");
		img.width = w;
		img.height = h;
	}
	DecreaseWaitQueue();
	PopUp("imageDiv", 0, 0);

	El('imageDivPrevImage').onmouseout = function()
	{
		this.onmouseover = this.onclick;
		El('imageDivNextImage').onmouseover = El('imageDivNextImage').onclick;
	}
	El('imageDivNextImage').onmouseout = function()
	{
		this.onmouseover = this.onclick;
		El('imageDivPrevImage').onmouseover = El('imageDivPrevImage').onclick;
	}
	El('imageDivPicture').onmouseover = function()
	{
		El('imageDivNextImage').onmouseover = El('imageDivNextImage').onclick;
		El('imageDivPrevImage').onmouseover = El('imageDivPrevImage').onclick;
	}
}

function RestoreFullImageSize()
{
	var img = El("imageDivPicture");
	img.width = img.origWidth;
	img.height = img.origHeight;
	HideElem("imageDivGlass");
	FixLocation("imageDiv", 0, 0);
}

function PopUpImage(url, prevImage, nextImage)
{
	if (IE6)
	{
		window.open(url);
	}
	else
	{
		IncreaseWaitQueue();
		if (El("imageDiv") && El("imageDiv").style.display != "none")
		{
			FadeOut("imageDiv");
			PreloadImage(url, "setTimeout('FixPopUpImageSize();', 100);", 8);
		}
		else PreloadImage(url, "setTimeout('FixPopUpImageSize();', 100);");

		try
		{
			El("imageDivPicture").onmouseover = null;
			El("imageDivPrevImage").onmouseover = null;
			El("imageDivNextImage").onmouseover = null;
			El("imageDivPrevImage").onmouseout = null;
			El("imageDivNextImage").onmouseout = null;

			if (prevImage == null || !El(prevImage))
			{
				HideElem("imageDivPrevImage");
			}
			else
			{
				ShowElem("imageDivPrevImage");
				El("imageDivPrevImage").onclick = El(prevImage).onclick;
			}
			if (nextImage == null || !El(nextImage))
			{
				HideElem("imageDivNextImage");
			}
			else
			{
				ShowElem("imageDivNextImage");
				El("imageDivNextImage").onclick = El(nextImage).onclick;
			}
		}
		catch (e)
		{
			// ignore
		}
	}
}

function VerticalSlider(slider, knob, sliderBound, knobBound, minValue, maxValue, step, startValue, onValueChanged)
{
	this.slider = slider;
	this.knob = knob;
	this.sliderBound = sliderBound;
	this.knobBound = knobBound;
	this.minValue = Math.min(minValue, maxValue);
	this.maxValue = Math.max(minValue, maxValue);
	this.step = step;
	this.onValueChanged = onValueChanged;
	this.dragging = false;
	this.dragStart = { x: 0, y: 0 };

	this.RepositionKnob = function (deltaY)
	{
		var ratio = (this.maxValue - this.currentValue) / (this.maxValue - this.minValue);
		this.knob.style.top = Math.round(
  			Math.min(this.sliderBound.height, Math.max(0, ratio * this.sliderBound.height + deltaY)) +
			this.sliderBound.y + this.knobBound.y - (this.knobBound.height / 2)) + "px";
		this.knob.style.left = Math.round(this.sliderBound.x + this.knobBound.x - (this.knobBound.width / 2)) + "px";
	};

	this.SetValue = function (newValue)
	{
		this.currentValue = Math.min(this.maxValue, Math.max(newValue, this.minValue));
		this.lastValue = this.currentValue;
		this.RepositionKnob(0);
		this.onValueChanged(newValue);
	};

	this.SetValue(startValue);

	this.CalculateNewValue = function (deltaY)
	{
		return (this.lastValue = Math.min(this.maxValue,
  			Math.max(this.minValue, this.currentValue -
			Math.round(deltaY / ((this.sliderBound.height / (this.maxValue - this.minValue)) * this.step)) * this.step)));
	};

	this.knob.sliderObj = this;
	this.knob.onmousedown = function (e)
	{
		if (!e) e = window.event;

		StopBubble(e);
		mouseDown = true;

		if (this.sliderObj.dragging)
			return;

		this.sliderObj.dragging = true;
		this.sliderObj.dragStart = GetMousePos(e);
	};

	this.slider.sliderObj = this;
	this.slider.onmousemove = function (e)
	{
		if (!e) e = window.event;

		if (!this.sliderObj.dragging)
			return; // nothing to do

		if (!mouseDown)
		{
			this.sliderObj.dragging = false;
			this.sliderObj.SetValue(this.sliderObj.lastValue);
			return; // mouse released outside
		}

		var currentPos = GetMousePos(e);
		var deltaY = currentPos.y - this.sliderObj.dragStart.y;

		this.sliderObj.RepositionKnob(deltaY);
		this.sliderObj.onValueChanged(this.sliderObj.CalculateNewValue(deltaY));
		StopBubble(e);
	};

	this.slider.onmouseup = function (e)
	{
		if (!e) e = window.event;

		if (!this.sliderObj.dragging)
			return; // nothing to do

		var currentPos = GetMousePos(e);
		var deltaY = currentPos.y - this.sliderObj.dragStart.y;

		this.sliderObj.dragging = false;
		this.sliderObj.SetValue(this.sliderObj.CalculateNewValue(deltaY));

		mouseDown = false;
		StopBubble(e);
	};

	this.slider.onclick = function (e)
	{
		if (!e) return;

		if (this.sliderObj.dragging)
			return; // nothing to do

		var currentPos = GetMouseOffset(this.sliderObj.knob, e);
		if (currentPos.y < 0)
			this.sliderObj.SetValue(this.sliderObj.currentValue + this.sliderObj.step);
		else if (currentPos.y > this.sliderObj.knobBound.height)
			this.sliderObj.SetValue(this.sliderObj.currentValue - this.sliderObj.step);
		StopBubble(e);
	}
}

function InitGirlRating()
{
	if (El("ratingSlider") && El("ratingKnob"))
	{
		return new VerticalSlider(El("ratingSlider"), El("ratingKnob"),
			{ x: 17, y: 16, width: 8, height: 125 }, { x: 0, y: 0, width: 20, height: 20 }, 1, 10, 1, 10,
  			function(newValue) { El("ratingValue").innerHTML = newValue + "\/<span>10<\/span>"; });
	}
	else setTimeout("InitGirlRating();", 100);
	return false;
}

function SubmitGirlRating(slider)
{
	if (slider)
	{
		var url = "./?action=add-rating";
		var encodedData = "rating=" + encodeURIComponent(slider.lastValue);
		LoadAsyncToDivPost(url, encodedData, "ratingGirlGlobal",
  			"HideElem('ratingGirlSlider'); HideElem('ratingGirlUser'); ShowElem('ratingGirlGlobal');");
	}
}

var IE6 = false;
var IE7 = false;
var OldIE = false;
