function openWindow(link,name,features) {
	window.open(link,name,features);
}

function toggleDisplay(divName){
	var tempDiv = document.getElementById(divName);
	if (!tempDiv) return;

	if (tempDiv.style.display=="block" || tempDiv.style.display=="") {
		tempDiv.style.display="none";
	} else {	
		tempDiv.style.display="block";
	}
}

function zoomImage(imgId, imgWidth) {
	if ($(imgId).zoomed == "0") {
		var ratio = (imgWidth / $(imgId).width) * 100;
		new Effect.Scale(imgId,ratio,{scaleContent:false});
		$(imgId).zoomed = 1;
	} else {
		var ratio = ($(imgId).width / imgWidth) * 50;
		new Effect.Scale(imgId,ratio,{scaleContent:false});
		$(imgId).zoomed = 0;
	}
}


function toggleDiv(toggleDivName, htmlDivName) {
	var toggleDiv = document.getElementById(toggleDivName);
	var htmlDiv = document.getElementById(htmlDivName);

	if (!toggleDiv || !htmlDiv) return;

	if (toggleDiv.style.display=="block" || toggleDiv.style.display=="") {
		toggleDiv.style.display="none";
		htmlDiv.innerHTML = "... (devamę)";
	} else {	
		toggleDiv.style.display="block";
		htmlDiv.innerHTML = "(kapa)";
	}
}




var UT_RATING_IMG = '/img/star.gif';
var UT_RATING_IMG_HALF = '/img/lt_star_half.gif';
var UT_RATING_IMG_BG = '/img/lt_star_off.gif';

function UTRating(ratingElementId, maxStars, objectName, formName, ratingMessageId, componentSuffix, size)
{
	this.ratingElementId = ratingElementId;
	this.maxStars = maxStars;
	this.objectName = objectName;
	this.formName = formName;
	this.ratingMessageId = ratingMessageId
	this.componentSuffix = componentSuffix

	this.starTimer = null;
	this.starCount = 0;

	// pre-fetch image
	(new Image()).src = UT_RATING_IMG;
	(new Image()).src = UT_RATING_IMG_HALF;

	function showStars(starNum, skipMessageUpdate) {
		this.clearStarTimer();
		this.greyStars();
		this.colorStars(starNum);
		if(!skipMessageUpdate)
			this.setMessage(starNum);
	}

	function setMessage(starNum) {
		messages = new Array("Rate this video", "Poor", "Nothing special", "Worth watching", "Pretty cool", "Awesome!");
		document.getElementById(this.ratingMessageId).innerHTML = messages[starNum];
	}

	function colorStars(starNum) {
		for (var i=0; i < starNum; i++)
			document.getElementById('star_'  + this.componentSuffix + "_" + (i+1)).src = UT_RATING_IMG;
	}

	function greyStars() {
		for (var i=0; i < this.maxStars; i++)
			if (i <= this.starCount)
				document.getElementById('star_' + this.componentSuffix + "_"  + (i+1)).src = UT_RATING_IMG_BG; // UT_RATING_IMG_REMOVED;
			else
				document.getElementById('star_' + this.componentSuffix + "_"  + (i+1)).src = UT_RATING_IMG_BG;
	}

	function setStars(starNum) {
		this.starCount = starNum;
		this.drawStars(starNum);
		document.forms[this.formName]['rating'].value = this.starCount;
		var ratingElementId = this.ratingElementId;
		postForm(this.formName, true, function (req) { replaceDivContents(req, ratingElementId); });
	}


	function drawStars(starNum, skipMessageUpdate) {
		this.starCount=starNum;
		this.showStars(starNum, skipMessageUpdate);
	}

	function clearStars() {
		this.starTimer = setTimeout(this.objectName + ".resetStars()", 300);
	}

	function resetStars() {
		this.clearStarTimer();
		if (this.starCount)
			this.drawStars(this.starCount);
		else
			this.greyStars();
		this.setMessage(0);
	}

	function clearStarTimer() {
		if (this.starTimer) {
			clearTimeout(this.starTimer);
			this.starTimer = null;
		}
	}

	this.clearStars = clearStars;
	this.clearStarTimer = clearStarTimer;
	this.greyStars = greyStars;
	this.colorStars = colorStars;
	this.resetStars = resetStars;
	this.setStars = setStars;
	this.drawStars = drawStars;
	this.showStars = showStars;
	this.setMessage = setMessage;

}


