sfHover = function() {
	var sfEls = document.getElementById("navmenu").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"), "");
		}
	}
}

//if (window.attachEvent) window.attachEvent("onload", sfHover);
//----------------------------------------------------------

/*
	Opens popup window, whitch is centered in screen
	Param:
		url string (link to the file you want to open)
		width int (window width)
		height int (window height)
*/
function OpenImagePopup(url,width,height) {
	var rnd = (Math.round((Math.random()*999)+1));
	
	var SH = screen.height;
	var SW = screen.width;

	if (SW < width)
	{
		newW = Math.round(SW * 0.90);
		dif = newW / width;
		newH = Math.round(height * dif);
		height = newH;
		width = newW;
	}

	if (SH < height)
	{
		newH = Math.round(SH * 0.90);
		dif = newH / height;
		newW = Math.round(width * dif);
		height = newH;
		width = newW;
	}

	var top = (screen.height) ? (screen.height-height)/2 : 0;
	var left = (screen.width) ? (screen.width-width)/2 : 0;

	iw = width;
	ih = height;
	my_window = window.open("", "w"+rnd, "top="+top+",left="+left+",width="+width+",height="+height+",buttons=no,scrollbars=no,location=no,menubar=no,resizable=no,status=no,directories=no,toolbar=no");
	my_window.document.writeln("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" "+"\"http://www.w3.org/TR/html4/strict.dtd\">");
	my_window.document.writeln("<html><head><title>Picture preview</title>");
	my_window.document.writeln("<meta http-equiv=\"Content-Script-Type\" ","content=\"text/javascript\"><\/head>");
	my_window.document.writeln("<body style='margin:0px;padding:0px;'>")
	my_window.document.writeln("<img src='" + url + "' onclick='window.close();' border='0' width='" + iw + "' height='" + ih + "' alt='' />");
	my_window.document.writeln("<\/body><\/html>");
	my_window.document.close();
}
//---------------------------------------------------------------

/*
	Opens popup window, whitch is centered in screen
	Param:
		url string (link to the file you want to open)
		width int (window width)
		height int (window height)
*/
function openPopup(url,width,height) {
	var rnd = (Math.round((Math.random()*999)+1));
	
	scrollbars = 'yes';
	
	var top = (screen.height) ? (screen.height-height)/2 : 0;
	var left = (screen.width) ? (screen.width-width)/2 : 0;

	my_window = window.open(url, "w"+rnd, "top="+top+",left="+left+",width="+width+",height="+height+",buttons=no,scrollbars="+scrollbars+",location=no,menubar=no,resizable=no,status=no,directories=no,toolbar=no");
	my_window.document.close();
}
//---------------------------------------------------------------

/*
	Strips spaces from start and end of string
	Param:
		str string (text)
*/
function trimString (str)
{
	while (str.charAt(0) == ' ')
		str = str.substring(1);
	while (str.charAt(str.length - 1) == ' ')
		str = str.substring(0, str.length - 1);

	return str;
}
//---------------------------------------------------------------

function togleBlockView(id) {
	var ob = $('#'+id);
	
	if (ob.length) {
		if (ob.is(':visible'))
			ob.slideUp(500);
		else
			ob.slideDown(500);
	}
}
//---------------------------------------------------------------

function togleClassActive(obj) {
	var ob = $(obj);
	
	if (ob.length) {
		if (ob.hasClass('active'))
			ob.removeClass('active');
		else
			ob.addClass('active');
	}
}
//---------------------------------------------------------------

function toggleCheckboxAll(obj, name) {
	var checked_status = obj.checked;
	
	var els = document.getElementsByName(name);
	for (var i = 0; i<els.length; i++) {
		els[i].checked = checked_status;
	}
	
	/*
	$("input[name="+name+"]").each(function() {
		this.checked = checked_status;
	});
	*/
	obj.blur();
}
//---------------------------------------------------------------

var clockT = 0;
var clockObj = 0;
 
function stopClock(){
	clearTimeout(clockT);
	if (clockT)
		clockT = 0;
}
//---------------------------------------------------------------
 
function getDigitalClock(id) {
	if ((!clockObj) && (id))
		clockObj = document.getElementById(id);
	if (clockObj) {
		var nd = new Date();
		var h, m;
		var s;
		var time = "";
		h = nd.getHours();
		m = nd.getMinutes();
		s = nd.getSeconds();
		if (h <= 9) h = "0" + h;
		if (m <= 9) m = "0" + m;
		if (s <= 9) s = "0" + s;
		time += h + " : " + m + " : " + s;
		clockObj.value = time;
		clockT = setTimeout("getDigitalClock()", 1000);
	}
}
//---------------------------------------------------------------

function addExercize(obj) {
	var exList = $('#exercisesList');
	var exercize = exList.val();
	
	$(obj).blur();
	if (!exercize) {
		return;
	}
	
	var title = exList.find('option:selected').text();
	var exTable = $('#powerExercises');
	var disabledStr = '';
	var disList = new Array('press_up', 'pull_up', 'abs_lying');
	for(var i=0; i<disList.length; i++) {
		if (disList[i] == exercize) {
			disabledStr = 'disabled="disabled"';
			break;
		}
	}
	
	var html = '';
	html = '<tr>';
    html += '<td><input type="checkbox" name="exercize[]" value="'+exercize+'" /></td>';
    html += '<td><label>'+title+':</label></td>';
    html += '<td><input type="text" name="sets[]" value="" class="text_field" /></td>';
    html += '<td><input type="text" name="repetitions[]" value="" class="text_field" /></td>';
    html += '<td><input type="text" name="weight[]" value="" class="text_field" '+disabledStr+' /></td>';
    html += '<td><input type="text" name="rm[]" value="" class="text_field" disabled="disabled" /></td>';
    html += '</tr>';
	
	exList.find('option:first').attr('selected', 'selected');
	exTable.append(html);
}
//---------------------------------------------------------------

function deleteSelectedExercises(obj) {
	var name = 'exercize[]';
	
	$('input:checkbox[name='+name+']:checked').each(function(){
		$(this).parent().parent().remove();
	});
}
//---------------------------------------------------------------

$(document).ready(function()
{
	/*
	$("#searchField").focus(function(){
		if ($(this).val() == shHint)
			$(this).val('');
	});
	//---------------------------------------------------------------

	$("#searchField").blur(function(){
		if ($(this).val() == '')
			$(this).val(shHint);
	});
	//---------------------------------------------------------------
	*/

	$("form#searchForm").submit(function(){
		var fieldObj = $("#searchField");
		var q = trimString(fieldObj.val());
		fieldObj.val(q);
		if ((q) && (q != ''))
		{
			q = fieldObj.serialize();
			
			var baseUri = $("#searchForm").attr('action');
			if (!baseUri)
				baseUri = host+'lt';
			window.location = baseUri + '?' + q;
		}
		
		return false;
	});
	//---------------------------------------------------------------
	
	
	$("#note_box_close").click(function(){
		$('#note_box').slideUp('slow');
		return false;
	});
	//---------------------------------------------------------------
	
	activateLeft = function() {
		$('#btn_move_left').attr({src: host+'/public/images/vt-go-left-a.gif'});
	}
	//----------------------------------------------------------

	activateRight = function() {
		$('#btn_move_right').attr({src: host+'/public/images/vt-go-right-a.gif'});
	}
	//----------------------------------------------------------

	deActivateLeft = function() {
		$('#btn_move_left').attr({src: host+'/public/images/vt-go-left.gif'});
	}
	//----------------------------------------------------------

	deActivateRight = function() {
		$('#btn_move_right').attr({src: host+'/public/images/vt-go-right.gif'});
	}
	//----------------------------------------------------------
	
	//var items = document.getElementById("list_images_inner").getElementsByTagName("div");
	var items = $('#vt_nav .img');
	
	var numItems = 0;
	var maxWidth = 0;
	var marginLeft = parseInt($("#vt_nav table").css("marginLeft"));
	var containerW = parseInt($('#vt_nav').css('width'));
	var clicks = 0;
	var itemW = 124;
	var inline = 5;
	
	numItems = items.length;
	
	if (numItems > inline) {
		activateRight();
	}
	
	moveLeft = function() {
		if (clicks >= (numItems - inline)) {
			clicks = (numItems > inline) ? numItems - inline : 0;
			deActivateRight();
		}
		if (clicks > 0)
			activateLeft();
		marginLeft = clicks * itemW;
		$("#vt_nav table").animate({"marginLeft": -marginLeft+"px"}, 500);
	}
	//----------------------------------------------------------

	moveRight = function() {
		if (clicks <= 0) {
			clicks = 0;
			deActivateLeft();
		}
		if (clicks < (numItems - inline))
			activateRight();
		marginLeft = clicks * itemW;
		$("#vt_nav table").animate({"marginLeft": -marginLeft+"px"}, 500);
	}
	//----------------------------------------------------------
	
	$("#btn_move_left").click(function() {
		clicks--;
		moveRight();
		$(this).blur();
		return false;
	});					
	//----------------------------------------------------------

	$("#btn_move_right").click(function() {
		clicks++;
		moveLeft();
		$(this).blur();
		return false;
	});
	//----------------------------------------------------------
});
//---------------------------------------------------------------


