jQuery(document).ready(function(){
		//thickbox replacement
	var closeModal = function(hash)
	{
		var jQuerymodalWindow = jQuery(hash.w);
		//jQuery('#jqmContent').attr('src', 'blank.html');
		jQuerymodalWindow.fadeOut('2000', function()
		{
			hash.o.remove();
			//refresh parent
			if (hash.refreshAfterClose == true)
			{
				window.location.href = document.location.href;
			}
		});
	};
	var openInFrame = function(hash)
	{
		var jQuerytrigger = jQuery(hash.t);
		var jQuerymodalWindow = jQuery(hash.w);
		var jQuerymodalContainer = jQuery('iframe', jQuerymodalWindow);
		var myUrl = jQuerytrigger.attr('href');
		var myTitle = jQuerytrigger.attr('title');
		var newWidth = 0, newHeight = 0, newLeft = 0, newTop = 0;
		jQuerymodalContainer.html('').attr('src', myUrl);
		jQuery('#jqmTitleText').text(myTitle);
		myUrl = (myUrl.lastIndexOf("#")> -1) ? myUrl.slice(0, myUrl.lastIndexOf("#")) : myUrl;
		var queryString = (myUrl.indexOf("?")> -1) ? myUrl.substr(myUrl.indexOf("?") + 1) : null;
		if (queryString != null && typeof queryString != 'undefined')
		{
			var queryVarsArray = queryString.split("&");
			for (var i = 0; i <queryVarsArray.length; i++)
			{
				if (unescape(queryVarsArray[i].split("=")[0]) == 'width')
				{
					var newWidth = queryVarsArray[i].split("=")[1];
				}
				if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'height')
				{
					var newHeight = queryVarsArray[i].split("=")[1];
				}
				if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'jqmRefresh')
				{
					hash.refreshAfterClose = queryVarsArray[i].split("=")[1]
				} else
				{
					hash.refreshAfterClose = true;
				}
			}
			// let's run through all possible values: 90%, nothing or a value in pixel
			if (newHeight != 0)
			{
				if (newHeight.indexOf('%')> -1)
				{
					newHeight = Math.floor(parseInt(jQuery(window).height()) * (parseInt(newHeight) / 100));
				}
				var newTop = Math.floor(parseInt(jQuery(window).height() - newHeight) / 2);
			}
			else
			{
				newHeight = jQuerymodalWindow.height();
			}
			if (newWidth != 0)
			{
				if (newWidth.indexOf('%')> -1)
				{
					newWidth = Math.floor(parseInt(jQuery(window).width() / 100) * parseInt(newWidth));
				}
				var newLeft = Math.floor(parseInt(jQuery(window).width() / 2) - parseInt(newWidth) / 2);
			}
			else
			{
				newWidth = jQuerymodalWindow.width();
			}
			// do the animation so that the windows stays on center of screen despite resizing
			jQuerymodalWindow.css({
				width: newWidth,
				height: newHeight,
				opacity: 1
			}).jqmShow().animate({
				width: newWidth,
				height: newHeight,
				top: newTop,
				left: newLeft,
				marginLeft: 0,
				opacity:1
			}, 'normal');
		}
		else
		{
			// don't do animations
			jQuerymodalWindow.jqmShow();
		}
	}
	jQuery('#modalWindow').jqm({
	//	overlay: 70,
		modal: true,
		trigger: 'a.thickbox',
		target: '#jqmContent',
		onHide: closeModal,
		onShow: openInFrame
	});
});

jQuery(document).ready(function(){
    jQuery("#letter_link").mouseout(function(){
      jQuery("#letter_link").animate({"width": "-=100px"}, "slow");
    });

    jQuery("#letter_link").mouseover(function(){
      jQuery("#letter_link").animate({"width": "+=100px"}, "slow");
    });
});
