function ImagePreloader() 
{
}

ImagePreloader.Add = function(imageUrl) 
{
	var image = new Image();
	image.src = imageUrl;
}

function ImageOverlay(image, link) 
{
	var _image = image;
	
	var _images = [];
		_images[0] = image.src;

	var _links = [];
	_links[0] = link;
	
	var _changeDuration = 0;
	
	var _imageIndex = 0;
	
	var _stoped = false;
	
	var _hideOptions = 
	{
		from: 1.0,
		to: 0.0,
		queue: {position: 'end', scope: 'imageOverlay'},
		afterFinishInternal : function(effect)
		{
			if (effect.options.to != 0)
				return;
			if (_imageIndex == _images.length -1)
				_imageIndex = 0;
			else 
				_imageIndex++;
			//alert(_links[_imageIndex]);
			_image.src = _images[_imageIndex];
			
			if(_links[_imageIndex])
				$('flash').firstDescendant().href = _links[_imageIndex];
			else
				$('flash').firstDescendant().href = "javascript:void(0)";
			new Effect.Opacity(_image, _showOptions);	
		}
	}
	
	var _showOptions = 
	{
		from: 0.0,
		to: 1.0,
		queue: {position: 'end', scope: 'imageOverlay'},
		afterFinishInternal : function(effect)
		{
			if (effect.options.to != 1)
				return;
			ShowNextImage();
		}
	}
	
	function ShowNextImage() 
	{
		if (_stoped)
		{
			return;
		}
		window.setTimeout(HideImage, _changeDuration);
	}
	
	function HideImage() 
	{
		if (_stoped)
			return;
		new Effect.Opacity(_image, _hideOptions);
	}
	
	this.Add = function(imageUrl, linkHref) 
	{
		ImagePreloader.Add(imageUrl);
		var curPosition = _images.length;
		
		_images[curPosition] = imageUrl;
		_links[curPosition] = linkHref;
	}
	
	this.SetChangeDuration = function(duration)
	{
		_changeDuration = duration;
	}
	
	this.SetFadeDuration = function(duration)
	{
		duration = duration / 1000;
		_showOptions.duration = duration;
		_hideOptions.duration = duration;
	}
	
	this.Start = function() 
	{
		_stoped = false;
		if (_images.length == 1)
			return;
		ShowNextImage();
	}
	
	this.Stop = function() 
	{
		_stoped = true;
		var queue = Effect.Queues.get('imageOverlay');
		queue.each(function(effect) { effect.cancel(); });
		_image.setStyle({opacity: 1.0});
	}
	
	this.IsStarted = function()
	{
		return !_stoped;
	}
}

function CookieHelper() 
{
	
}

CookieHelper.Get = function(name)
{
	var cookie = document.cookie;
	var prefix = name + "=";
	var begin = cookie.indexOf("; " + prefix);
	if (begin == -1)
	{
    	begin = cookie.indexOf(prefix);
	    if (begin != 0) return null;
	} 
	else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = cookie.length;
	return unescape(cookie.substring(begin + prefix.length, end));
}

CookieHelper.Set = function (name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}


function HideFlash() 
{
	imageOverlay.Stop();
	Effect.SlideUp('flash');
	Effect.SlideDown('showFlash', {queue: 'end'});
}

function ShowFlash()
{
	Effect.SlideUp('showFlash');
	Effect.SlideDown('flash', { queue: 'end', restoreAfterFinish: false });
	imageOverlay.Start();
}

function showEncForm()
{
	//Effect.Appear('encForm');
	//Effect.Fade('encForm');
	Effect.toggle('encForm', 'appear');
}

function showOfficeForm(id)
{
	Effect.toggle(id, 'appear');
}

function OnNavigationClick(linkElement) 
{
	linkElement = $(linkElement);
	
	var parent = linkElement.ancestors()[0];
	var childElements = parent.childElements();
	if (childElements.length == 1)
		return;
//	var options = {queue: {position: 'end', scope: 'navigation'}};	
	if (parent.className.length > 0) 
	{
		parent.className = "";//("selected");
		childElements[1].hide();
//		Effect.SlideUp(childElements[1], options);		
	}
	else
	{
//		Effect.SlideDown(childElements[1], options);	
		parent.className = "selected";
		childElements[1].show();
	}
}

var imageOverlay;

