// jQuery rules
$(function() {
	/** 
	 * Opens external links in a new window
	 * 
	 * Yes, this is normally bad practice but the frequency of this happening is
	 * minimal at worst.
	 */
	$('a.external').click(function(){
        window.open(this.href);
        return false;
    });
    
	// Hide what needs to be hidden
	$('.no-show').css('display', 'none');
	
	// Setup the search box message
	if ($('#search').val() == '') {
		$('#search').val($('#search').attr('title'));
	}
	// Now handle what happens when focus is given to it or removed from it
	$('#search').focus(function() {
		// See if the input field is the default
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
		}
	})
	.blur(function() {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	});
	
	// THis is not working like I expected it to
	// $('.goto-offer-contact').bind('click', tb_remove);
	//$('label acronym').cluetip({splitTitle: '|', positionBy: 'bottomTop', topOffset: 30});
	
	// This brings focus to the first form input field that is visible and enabled
	$("#container-content input:visible:enabled:first").focus();
	
	$('a.scroll-to').click(function() {
		var loc = $(this).attr('href');
		var scrollto = loc.substring(loc.indexOf('#'));
		$(scrollto).ScrollTo(800);
		return false;
	});
	
	$('a.return-to-top').click(function() {
		$('#top').ScrollTo(800);
		return false;
	});
	
	
	/* ---- CONTACT US -> REFERRAL PAGE ---- */
	// get the total amount of referral boxes we can display
	var rc = $('#referral_count').val();
	
	// set the referral box counter
	var rb = 1;
	
	// Hide the additional referral box's
	$('.hidden-referral').hide();
	$('#add-referral').removeClass('hide');
	
	// Reveal another referral box's when the button is clicked
	$('#add-referral-button').click( function () {
		// increment the counter
		rb++;
		// show the next referral box
		$('#referral_'+rb).show();
		// if we have reached the max amount of referral boxes to show, hide the add button
		if (rb == rc) {
			$('#add-referral-button').hide();
		}
	});
	/* ------------------------------------- */
});