(function($) { // hide the namespace   
    $(function () { // document.onload()
		$('body').append($("#page_home .portlet#buzz .overlay"));
		
		$("#page_home .portlet#buzz .news-item[rel]").overlay({
				effect: 'apple',
				absolute: false,
				expose: {
							color: '#000',
							loadSpeed: 200,
							opacity: 0.8
						}
			}); 
		

		// auto newsletter on registration
		$('.mod_registration input[name=newsletter]').attr('checked', true);
		

		// #page_company
		$('body #page_company').append($("#page_company .box").clone().each(function () {
			$(this).attr('id', 'overlay-' + $(this).attr('id')).addClass('overlay');					
			$('.more', $(this)).remove();
		}));
		
		$("#page_company .box .more[rel]").overlay({
				effect: 'apple',
				absolute: false,
				expose: {
							color: '#000',
							loadSpeed: 200,
							opacity: 0.8
						},
				onLoad: function () {
							var wrapper = $('.wrapper', this.getOverlay());
							wrapper.attr('id','flexcroll');							
							wrapper.height(Math.min(wrapper.height(), 350));
							CSBfleXcroll('flexcroll');
							wrapper.attr('id','flexcroll1');	
						}
			}); 
		$("#page_company .box .moretop[rel]").overlay({
				effect: 'apple',
				absolute: false,
				expose: {
							color: '#000',
							loadSpeed: 200,
							opacity: 0.8
						},
				onLoad: function () {
							var wrapper = $('.wrapper', this.getOverlay());
							wrapper.attr('id','flexcroll');							
							wrapper.height(Math.min(wrapper.height(), 350));
							CSBfleXcroll('flexcroll');
							wrapper.attr('id','flexcroll1');	
						}
			}); 
			
		$("#page_company #overviewStats a.more").click(function () {
			$('.more-only', $(this).parents('#overviewStats')).slideToggle();
			CSBfleXcroll('flexcroll');
		});
		
		
		$("img[alt='account_required']").click(function(event) {
			var logged_in = IB.status();
			if (!logged_in)
			{
				if (this.href)
					IB.set_next_action(this.href);
				else if ((this.parentNode) && (this.parentNode.href))
					IB.set_next_action(this.parentNode.href);
				event.preventDefault();
				$("html, body").animate({ scrollTop: 0 }, "slow");
				IB.display_login_message();
				return false;
			}
			return true;
		});
		
		$(".account_required").click(function(event) {
			var logged_in = IB.status();
			if (!logged_in)
			{
				if (this.href)
					IB.set_next_action(this.href);
				event.preventDefault();
				$("html, body").animate({ scrollTop: 0 }, "slow");
				IB.display_login_message();
				return false;
			}
			return true;
		});
				
    });
})(jQuery);

(function($) { // hide the namespace
	
	function updateTips(t) {
		$("#law_guide_popup_validation").text(t);
		$("#law_guide_popup_validation").addClass("ui-state-highlight");
		setTimeout(function() {
			$("#law_guide_popup_validation").removeClass("ui-state-highlight", 1500);
		}, 500);
	}

	function checkLength(o,n,min,max) {
		if ( o.val().length > max || o.val().length < min ) {
			o.addClass("ui-state-error");
			updateTips("Length of " + n + " must be between "+min+" and "+max+".");
			return false;
		} else {
			return true;
		}
	}

    $(function () { // document.onload()
		$("#law_guide_popup").dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			buttons: {
				"Download PDF": function() {
					var bValid = true;
					$("#law_guide_popup_name").removeClass("ui-state-error");
					$("#law_guide_popup_email").removeClass("ui-state-error");

					bValid = bValid && checkLength($("#law_guide_popup_name"),"name",1,40);
					bValid = bValid && checkLength($("#law_guide_popup_email"),"email",6,80);
					if (bValid) {
						$.post("/ajax/post.php", { name: $("#law_guide_popup_name").val(), action: "law_guide", email: $("#law_guide_popup_email").val() } );
						$(this).dialog("close");
						$("#law_guide_popup_confirm").dialog("open");
					}
				},
				Cancel: function() {
					$(this).dialog("close");
				}
			}
		})
		$("#law_guide_popup_confirm").dialog({
			autoOpen: false,
			height: 200,
			width: 300,
			modal: true,
			buttons: {
				"OK": function() {
					$(this).dialog("close");
				}
			}
		});

		$("#law_guide_download").click(function () {
			$("#law_guide_popup").dialog("open");
			return false;
		});
		$("img[alt='law_guide_download']").click(function () {
			$("#law_guide_popup").dialog("open");
			return false;
		});
    });
})(jQuery);

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
 
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
 
    return vars;
}
var source = getUrlVars();
source = source['source'];
