﻿// loading advertisement movement functionality
jQuery(document).ready(function() {
	jQuery('#downloadList').jcarousel();
});

// function for showing and hiding default texts in inputs
function inputDefaultShowHide(inputId, defaultText, isBlurAction) {
	var obj = document.getElementById(inputId);

	if (isBlurAction) {
		if (obj.value == "")
			obj.value = defaultText;
	}
	else {
		if (obj.value == defaultText)
			obj.value = "";
	}
}

// function for moving news
var tTimeout = 2000;
var iLimitPolozek = 1;

$(document).ready(function() {
	$("#news>li").hover(function() { clearTimeout(bi); }, function() { clearTimeout(bi); bi = setTimeout('bc_rot()', tTimeout); });
	h = 0;
	i = 0;
	if (iLimitPolozek > ($("#news").find("li").length - 1))
		iLimitPolozek = ($("#news").find("li").length - 1);

	$("#news").find("li").each(function(i) {
		if (i < iLimitPolozek)
			h += jQuery(this, i).height();
		i++;
	})
	//$("#rot_mask").height(h);
	//$("#rot_mask_w").height(h);
});

var bi = setTimeout('bc_rot()', tTimeout);

function bc_rot() {
	$("#news li:first").clone(true).appendTo("#news");
	$("#news").animate({ "top": "-=" + $("#news li:first").height() + "px" }, 1000, function() {
		$("#news>li:first").remove();
		$("#news").css('top', '0');
		$("#news>li").hover(
   function() { clearTimeout(bi); },
   function() { clearTimeout(bi); bi = setTimeout('bc_rot()', tTimeout); });
		clearTimeout(bi);
		bi = setTimeout('bc_rot()', tTimeout);
	});
}

// =======================================================================================
// POHOTOGALLERY - MOVING IMAGES IN LIST
// =======================================================================================

var canMoveLeft = false;
var canMoveRight = false;
var movingPart = 5;
var movingSpeed = 100;

function StartMoveLeft(elementId, parentWidth) {
	canMoveLeft = true;
	MoveLeft(elementId, parentWidth);
}

function MoveLeft(elementId, parentWidthString) {
	if (canMoveLeft) {
		var obj = document.getElementById(elementId);
		var leftPos = 0;
		var width = obj.offsetWidth;
		var parentWidth = parseInt(parentWidthString);
		if ((obj.style.left != null) && (obj.style.left != "")) {
			leftPos = parseInt(obj.style.left.replace("px", "").replace(" ", ""));
		}
		if (-leftPos < (width - parentWidth)) {
			leftPos -= movingPart;
			obj.style.left = leftPos + "px";
			window.setTimeout("MoveLeft('" + elementId + "', '" + parentWidthString + "');", movingSpeed);
		}
		else {
			canMoveLeft = false;
		}
	}
}

function StopMoveLeft(elementId) {
	canMoveLeft = false;
}

function StartMoveRight(elementId, parentWidth) {
	canMoveRight = true;
	MoveRight(elementId, parentWidth);
}

function MoveRight(elementId, parentWidthString) {
	if (canMoveRight) {
		var obj = document.getElementById(elementId);
		var leftPos = 0;
		var width = obj.offsetWidth;
		var parentWidth = parseInt(parentWidthString);
		if ((obj.style.left != null) && (obj.style.left != "")) {
			leftPos = parseInt(obj.style.left.replace("px", "").replace(" ", ""));
		}
		if (leftPos < 0) {
			leftPos += movingPart;
			obj.style.left = leftPos + "px";
			window.setTimeout("MoveRight('" + elementId + "', '" + parentWidthString + "');", movingSpeed);
		}
		else {
			canMoveRight = false;
		}
	}
}

function StopMoveRight(elementId) {
	canMoveRight = false;
}
