var CheckStrength = function(password){var score = 1;if (password.length < 1) return 0;if (password.length < 4) return 1;if (password.length >= 6) score++;if (password.length >= 8) score++;if (password.length >= 12) score++;if (password.match(/\d+/)) score++;if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) score++;if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,£,(,)]/)) score++;if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) score++;if (password.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,*,?,_,~,£,(,)])|([!,@,#,$,%,^,*,?,_,~,£,(,)].*[a-zA-Z0-9])/)) score++;return score;}
var ScrollWin = function(selector){var t = "#" + selector.split("#")[1];$("#main").animate({scrollTop: $(t).offset().top - 138}, "slow", "easeInQuad");}

var Gp = function(_id, _md, _da, _cc, _ff){ 
	function _out(_type,_msg) {
		try
		{
			_w = 500;
			if (_type=="ok")
			{
				if (_cc == null) _cc = "#main";
				$(_cc).fadeTo("fast", 0.01, function() {
					try
					{
						if(typeof onPageUnload == "function") {onPageUnload(); onPageUnload = null;}
						$("#menubar a.hover,#headermenu a.hover").removeClass("hover");
						$(_cc).html(_msg);
						if(typeof _ff == "function") _ff.call(_ff, $(_cc));
					} catch(err) {}
				});
				$(_cc).fadeTo("fast", 1, function() {if (_md != null) ScrollWin("#" + _md);});
			} else { 
				$("#blogo").stop().animate({backgroundPosition:"(0 -38px)"},"normal","easeInQuad"); _w = 2000;
				window.location = _id;
			}
		} catch(err) {}
		$.timer(_w, function(timer) { $("#blogo").stop().animate({backgroundPosition:"(0 0)"},"normal","easeInBack"); timer.stop(); });
	}
	try
	{
		$("#blogo").css({backgroundPosition:"0 0"}).stop().animate({backgroundPosition:"(0 -19px)"},"normal","easeInBack");
		$.ajax({
			type: "POST",
			url: _id,
			data: _da,
			cache: false,
			timeout: 10000,
			error: function(msg, status, xhr) { _out("err",msg); },
			success: function(msg, sta, xhr) { _ref = xhr.getResponseHeader("Refresh"); if (_ref) window.location = _ref.split(";URL=")[1]; else _out("ok", msg); }
		});
	} catch(err) { _out("err",msg); return false; }
    $.timer(300, function(timer) { try{ $.geekGaTrackEvent("page", "click", _id, ""); } catch(err) {} timer.stop(); });
}

$.fn.LoadHtml = function() {
	try
	{
		if (this.attr("rel")=="external") return true;
		if (this.attr("target")=="_blank") return true;
		var _id = this.attr("href");
		if (!_id) return false;
		var _md = _id.split("#");
		_id = _md[0];
		_md = ((_md.length>1)?_md[1]:null);
		Gp(_id, _md);
		return false;
	} catch(err) { return true; }
}

$.fn.dropDown = function() {
	return this.each(function() {
		$(this).hover(function(){
			$("ul:first",this).stop(true, true).hide().slideDown("fast").show(); 
		},function(){
			$("ul:first",this).stop(true, true).slideUp("slow","easeOutBounce");
		});
	});
}

$.fn.footHover = function() {
	var _hv = $(this).hover(function(){
		clearTimeout(timeout);
		if (_hv.height()<128) _hv.trigger("expand");
	},function(){
		timeout = setTimeout(function(){ _hv.trigger("contract",timeout); }, 1000);
	}).bind("expand",function(){
		$("#ssmenu").fadeIn("fast");
		$("#blogo").css("opacity", 0.40).fadeTo("slow", 1.0);
		_hv.stop().animate({height:128},"slow","easeOutBack",function(){$("#clogo").fadeIn();}); 
	}).bind("contract",function(e,timeout){
		clearTimeout(timeout);
		$("#ssmenu").fadeOut("fast");
		$("#clogo").fadeOut();
		_hv.stop().animate({height:52},"slow","easeOutBounce",function(){$("#blogo").fadeTo("slow", 0.40);});
	});
	setTimeout(function(){ _hv.trigger("mouseleave"); }, 100);
}

$.fn.setForm = function(p,e) {
	if ($(frm).length == 0) { 
		var btf = this;
		var frm = btf.closest("form");
		$("input,textarea:visible:enabled", frm).bind("focus", function(){ $(this).css({borderColor:"#555555"}); });
		$("input,textarea:visible:enabled", frm).bind("blur", function(){ $(this).css({borderColor:"#111111"}); });
		$('input[type!=hidden]:visible:enabled:first', frm).focus(); 
		frm.submit(function(){ btf.trigger("click"); return false; }); 
	}
	this.click(function(){
		var btn = $(this);
		btn.attr("disabled", "disabled");
		var val = frm.serialize() + "&" + btn.attr("name") + "=" + btn.val();   
		Gp(frm.attr("action"), null, val, p, e);
		return false;
	}); 
}

$(document).ready(function() {
	$("#menubar li a, #headermenu li a, #footermenu li a").click(function() { return $(this).LoadHtml($(this)); });
	if($("ul.dropdown").length) { $("ul.dropdown li").dropDown(); }
	$("#logo").css("visibility", "visible");
	if (window.location.href.length<26) $("#logo").css("opacity", 0.0).stop().fadeTo(5000, 1.0);
	$("#blogo").css("opacity", 0.40);
	$("#footer").footHover();
	$("#t1").hide().fadeIn(2000);
	$("#fav").jFav();
    $.timer(300, function(timer) { try{ $.geekGaTrackPage("UA-13082757-1"); } catch(err) {} timer.stop(); });
});
