﻿/*
description:
	extend jQuery to check and uncheck method for input type checkbox or radio
example:
	$("input[@type=checkbox]").check();
	$("input[@type=radio]").uncheck();
*/
jQuery.fn.extend({
	check: function()
	{
		return this.each(function() { this.checked = true; });
	},
	uncheck: function()
	{
		return this.each(function() { this.checked = false; });
	}
});


function pause(millis)
{
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while (curDate - date < millis);
}

//===========================================================================
// Provides a Dictionary object for client-side java scripts
//===========================================================================

function Lookup(key)
{
	return (this[key]);
}
function Delete()
{
	for (c = 0; c < Delete.arguments.length; c++)
	{
		this[Delete.arguments[c]] = null;
	}
	// Adjust the keys (not terribly efficient)
	var keys = new Array()
	for (var i = 0; i < this.Keys.length; i++)
	{
		if (this[this.Keys[i]] != null)
			keys[keys.length] = this.Keys[i];
	}
	this.Keys = keys;
}
function Add()
{
	for (c = 0; c < Add.arguments.length; c += 2)
	{
		// Add the property
		this[Add.arguments[c]] = Add.arguments[c + 1];
		// And add it to the keys array
		this.Keys[this.Keys.length] = Add.arguments[c];
	}
}
function Dictionary()
{
	this.Add = Add;
	this.Lookup = Lookup;
	this.Delete = Delete;
	this.Keys = new Array();
}

//var urls = new Dictionary();
//urls.Add("CodeStore", "http://www.codestore.net");
//urls.Add("NotesTips", "http://www.notestips.com");

//alert("CodeStore can be found at " + urls.Lookup('CodeStore'));
//alert("NotesTips can be found at " + urls.Lookup('NotesTips'));

/*
* Image preview script 
* powered by jQuery (http://www.jquery.com)
* 
* written by Alen Grakalic (http://cssglobe.com)
* 
* for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
*
*/
this.imagePreview = function()
{
	/* CONFIG */
	xOffset = 10;
	yOffset = 30;

	// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result

	/* END CONFIG */
	$("a.imgpreview").hover(function(e)
	{		
		this.t = this.title;
		this.title = "";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		var imgSize = getImgSize(this.href, 350);
		$("body").append("<p id='preview'><img src='" + this.href + "' alt='' style='width:" + imgSize[0] + ";height:" + imgSize[1] + "px;' />" + c + "</p>");
		$("#preview")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px")
			.css("width", imgSize[0] + "px")
			.css("height", imgSize[1]+ "px")
			.fadeIn("fast");
	},
	function()
	{
		this.title = this.t;
		$("#preview").remove();
	});
	$("a.imgpreview").mousemove(function(e)
	{
		$("#preview")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px");
	});
};

function getImgSize(imgSrc, max)
{
	var newImg = new Image();
	newImg.src = imgSrc;	
	var width = newImg.width;
	var height = newImg.height;
		
	if (width > max || height > max)
	{
		var skala = Math.min(max / width, max / height);
		width *= skala;
		height *= skala;
	}
	
	return [width, height];
}