﻿/// ********************************
/// OTHER
/// ********************************
function InitToggleBlocks(baseItemSelector, toggleAnchorSelector, dataElementSelector)
{
	$(document).ready(function()
	{
		$(baseItemSelector+" "+toggleAnchorSelector).each
		(function(aindex, aelem)
		{
			$(aelem).bind("click", function(e){ e.preventDefault(); $(baseItemSelector+" "+dataElementSelector+":eq("+String(aindex)+")").toggle("normal"); });
		});
		
		$(baseItemSelector+" "+dataElementSelector).hide(0);
	});
}

function PreloadSingleImage(iurl)
{
	var img = new Image();
	img.src = iurl;
	return img;
}

function PreloadMultipleImages(iurls)
{
	var i = 0, img = null;
	for (i = 0; i < iurls.length; i++)
	{
		img = null;
		img = PreloadSingleImage(iurls[i]);
	}
}

/// ********************************
/// VALIDATION HELPER
/// ********************************
function ValidateComboBoxByID(cmbid)
{
	var cmb = $find(cmbid);
	return ValidateComboBoxByInstance(cmb);
}

function ValidateComboBoxByInstance(cmb)
{
	return cmb.get_selectedIndex() > 0;
}

function OnComboBoxClientValidate(validator, args)
{
	args.IsValid = ValidateComboBoxByID(validator.controltovalidate);
}

/// ********************************
/// COLORBOX INIT
/// ********************************
$(document).ready(InitColorBox);

function InitColorBox()
{
	InitColorBoxGroup(".thickbox");
	InitColorBoxGroup(".colorbox");
}

function InitColorBoxGroup(groupSelector, title, rel)
{
	$(groupSelector).colorbox
	({
		transition: "elastic",
		speed: 700,
		opacity: 0.85,
		current: "Obrázek {current} z {total}",
		next: "Předchozí",
		previous: "Další",
		close: "Zavřít",
		title: title != null ? !title : null,
		rel: rel
	});
}

/// *****************************************************************
/// FONT SIZE MANAGER
/// *****************************************************************
function FontSizeManager()
{
	this.Container = null;
	this.ButtonsContainer = null;
	
	this.ContainerSelector = ".content .right";
	this.ButtonsContainerSelector = ".menu-header .font-size";
	this.IncreaseButtonSelector = ".menu-header .font-size a:first";
	this.DecreaseButtonSelector = ".menu-header .font-size a:last";
	this.DefaultSize = 100;
	this.SelectedSize = 100;
	this.IncrementSize = 15;
	this.MaxSize = 145;
	this.MinSize = 85;
	this.CookieName = "FontSize";
	
	this.Init = function()
	{
		var _this = this;
		
		$(document).ready(function(){ _this.InitOnDocumentLoad(); });
	}
	
	this.InitOnDocumentLoad = function()
	{
		var _this = this;
		
		this.Container = $(this.ContainerSelector);
		this.ButtonsContainer = $(this.ButtonsContainerSelector);
		
		$(this.IncreaseButtonSelector).bind("click",
			function(e)
			{
				_this.OnSizeIncrease(e);
			});
		
		$(this.DecreaseButtonSelector).bind("click",
			function(e)
			{
				_this.OnSizeDecrease(e);
			});
		
		// vyuziti cookie
		var cookieValue = $.cookie(_this.CookieName);
		
		if (cookieValue != null && cookieValue.length > 0)
		{
			this.SetSize(parseInt(cookieValue));
		}
	}
	
	this.OnSizeIncrease = function(e)
	{
		e.preventDefault();
		
		this.SetSize(this.SelectedSize + this.IncrementSize);
	}

	this.OnSizeDecrease = function(e)
	{
		e.preventDefault();
		
		this.SetSize(this.SelectedSize - this.IncrementSize);
	}
	
	this.SetSize = function(size)
	{
		if (size < this.MinSize || size > this.MaxSize) return;
		
		this.SelectedSize = size;
		
		this.Container.css("font-size", String(size) + "%");
		
		var edate = new Date();
		edate.setTime(edate.getTime() + (365 * 24 * 60 * 60 * 1000));
		$.cookie(this.CookieName, String(size), { path: '/', expires: edate });
	}
}

FontSizeManager.prototype = {
	Bind : function(fn, a){
		var _this = this;
		var _args = null;
		
		if (typeof(a) != "Array")
		{
			_args = new Array();
			_args.push(a);
		}
		else _args = a;
		
		return(function(){ return fn.apply(_this, _args); });
	}
}

