/*****************************   anDeRan   ************************************/

Cufon.replace("h3");
Cufon.replace("#h-nav", { hover: { color: "#C00"} });

jQuery(function($) {
	var tabs = $("ul.t-nav li");
	tabs.click(function () {
		tabs.removeClass("t-on");
		$(this).addClass("t-on");
		$("div.nav-c").removeClass("c-on");
		var div = $("#" + $(this).attr("id").replace("t", "c"));
		div.addClass("c-on");
	});

	$("#langs ul").append('<input type="hidden" name="lang" id="lang" />').click(function () {
		$(this).stop().animate({height: 72}, "fast", "swing", function () {
			$(this).css("border-bottom-width", "1px");
		});
	});
	$("#langs li a").hover(function () {
		$(this).css("background-color", "#F8F8F8");
	}, function () {
		$(this).css("background-color", "#FFF");
	});
	$(document).click(function (e) {
		var e = e || event;
		var obj = e.srcElement || e.target;
		if (obj.className.indexOf('li-first') == -1 || parseInt(obj.parentNode.style.borderBottomWidth, 10) == 1) {
			$("#langs ul").stop().animate({height: 24}, "fast", "swing", function () {
				$(this).css("border-bottom-width", "0");
			});
		}
	});

	window.copy_num = 1;
	window.addMember = function () {
		var form = $("form.form");
		var div = $("<div>").attr("class", "member");
		form.find("p.copy").each(function () {
			div.append($(this).clone().removeClass("copy"));
		});
		copy_num++;
		div.find("label, input, select").each(function () {
			if (this.nodeName.toLowerCase() == 'label') {
				$(this).attr("for", $(this).attr("for") + '-' + copy_num);
			} else {
				if (this.nodeName.toLowerCase() == 'input') {
					$(this).val('');
				}
				$(this).attr("id", $(this).attr("id") + '-' + copy_num);
				$(this).attr("name", $(this).attr("name") + '-' + copy_num);
			}
		});

		div.appendTo("div.reg-right");
		$("<p>").attr("class", "remove").html('<input type="hidden" name="key[]" value="' + copy_num + '" /><img src="/images/common/remove.gif" width="16" height="16" alt="" onclick="removeMember(this)" />').appendTo(div);
		if ($.browser.msie && $.browser.version < 7) {
			div.css("position", "static");
			div.html('<div style="position: relative">' + div.html() + '</div>');
		}
		div.slideDown();
		$('html, body').animate({scrollTop: div[0].offsetTop}, 'slow');
		return false;		
	};

	window.removeMember = function (img) {
		if ($.browser.msie && $.browser.version < 7) {
			var div = $(img.parentNode.parentNode.parentNode);
		} else {
			var div = $(img.parentNode.parentNode);
		}
		div.slideUp("normal", function () {
			div.remove();
		});
	};

	if (jQuery().fancybox) {
		$("div.fancybox a, a.fancybox").fancybox({
			'zoomOpacity'   : true,
			'overlayShow'   : false,
			'zoomSpeedIn'   : 500,
			'zoomSpeedOut'  : 500,
			'overlayShow'   : true,
			'overlayColor'  : '#000',
			'overlayOpacity': 0.5
		});
	}

	$(document.body).prepend('<div id="hint"></div>');
	$(".partners img").hover(function () {
		var div = $("#hint");
		var txt = $(this).attr("alt");
		if (txt.length) {
			div.html(txt);
			div.stop(true, true).fadeIn("fast");
			$(this).mousemove(function (e) {
				e = e || event;
				var div = $("#hint");
				div.css("top", e.clientY + (document.documentElement.scrollTop || window.scrollY || document.body.scrollTop) + 20 + 'px');
				div.css("left", e.clientX + (document.documentElement.scrollLeft || window.scrollX || document.body.scrollLeft) + 'px');
			});
		}
	}, function () {
		var div = $("#hint");
		div.stop(true, true).fadeOut("fast");
	});
});
