
$(window).bind('load', function() {
	
	//SET UP AUTO SUBMIT DROP DOWNS
	$('.autosubmit')
		.change(function() { this.form.submit(); })
		.siblings('.submit').hide();
	
	//SET UP URL SUBMIT DROP DOWNS
	$('.urlsubmit select')
		.change(function() { 
			var goto = this.options[this.selectedIndex].value;
			if (goto.length) {
				window.location = goto;
			}
		})
		.siblings('.submit').hide()
		.parent().show();
	
	//LOAD POPUPS FOR CONTACT LINKS
	$('.contact-popup').click(function(e) { showContactDetails(this, e.pageX, e.pageY); return false; });
	
	//ADD BRANDING LINK TO QUIK LINK CONTAINER
	if ($('#branding-link').text()) {
		$('#branding-overlay').bind('click', function() { window.location = $('#branding-link').attr('href'); })
		                 .css('cursor', 'pointer');
	}
});


function showContactDetails(contactLink, mouseX, mouseY) {
	var l = contactLink.href;
	var popupY = mouseY - 250;
	var person = l.substring(l.lastIndexOf("=")+1);
	$('#contact-popup').remove();
	$('body').append('<div id="contact-popup"></div>');
	$('#contact-popup').css('top', popupY)
	                   .append('<div id="contact-popup-top"><div id="contact-popup-detail"><h2 style="height:300px;line-height:300px;text-align:center;color:#AAA;margin:0;">loading...</h2></div></div>')
					   .append('<div id="contact-popup-bottom"></div><!--[if lte IE 6.5]><iframe></iframe><![endif]-->')
					   .show()
					   .click(function() { $(this).remove(); });
	$.get('contact-detail.aspx', {contactID:person}, function(data) { 
		$('#contact-popup-top').html(data)
		                       .append('<p class="contact-popup-close"><a onclick="$(\'#contact-popup\').remove();return false;" href="">Close</a></p>');
		$('#contact-popup').show();
	});
}
