jQuery.fn.realOffset = function() {
	var that = this[0];
	var x = 0;
	var y = 0;
	do {
		x += that.offsetLeft;
		y += that.offsetTop;
	} while (that = that.offsetParent);
	return {left: x, top: y};
}

$(function() {
	$("a[href='#']").click(function(e) {
		e.preventDefault();
	});
});

function modalFormSetup(url, callback) {
	$("#simplemodal-data form:not(.nomodal)").ajaxForm({
		target		: $.modal.impl.d.data,
		beforeSubmit: function() {
			$.modal.impl.d.container.addClass('loading');
			$.modal.impl.d.data.fadeTo('fast', 0.3);
		},
		url			: url,
		success		: function() {
			modalFormSetup(url, callback);
			$.modal.impl.d.data.fadeTo('fast', 1, function() {
				$.modal.impl.d.container.removeClass('loading');
			});
			if ('function' == typeof(callback)) callback();
		}
	});
}

$.modal.defaults.appendTo = "#outer-wrapper";
$.modal.defaults.onShow = function(dialog) {
	// attempt to get simple modal to simply modal
	$.modal.impl.setPosition();
	// Cufon.refresh();
}

$(function() {
	$("#ie6 .dropdown").hover(function(e){
		$(this).addClass('dropdown-hover');
		$("select:visible").addClass("hidden").hide();
	}, function(e){
		$(this).removeClass('dropdown-hover');
		$("select.hidden").removeClass("hidden").show();
	});
	
	$("a.modal").live('click', function(e) {
		e.preventDefault();
		var $this = $(this);
		var options = {};
		if ($this.hasClass('narrow')) {
			options.containerId = 'simplemodal-narrow';
		}
		$.get($this.attr("href"), "", function(data) {
			var modal = $.modal(data,options);
			$('#simplemodal-data .input').cleverlabels();
			modalFormSetup($this.attr("href"), $.modal.defaults.onShow);
		});
	});
	
	$("a.to-top").click(function(e){
		e.preventDefault();
		$("body,html").animate({
			scrollTop: 0
		}, 200);
	});
});

