jQuery(document).ready(function() {
// WATERMARKS
	watermark(jQuery('#jseSearch'), 'e.g. Bankruptcy, Civil Litigations, etc.');
	watermark(jQuery('#myCasesSearchbox'), 'Enter a minimum of three characters');
	watermark(jQuery('#supportSearchbox'), 'Search within Support');
	watermark(jQuery('#thankYouSearchbox'), 'Search Transaction List');
	watermark(jQuery('#newsSearchbox'), 'Search within news');
	watermark(jQuery('#newsSignupbox'), 'Signup for Newsletter');

// UNIVERSAL
	// jqtransform
	$('.formFieldList').not(".dialogBox .formFieldList, #filterDeadlines .formFieldList, .skipTransform").jqTransform({imgPath:'/images/jqtransform/'});

	// Tooltips
	$('.infoIcon').cluetip({
		cluezIndex: 9999,
		showTitle: false,
		dropShadow: false,
		width: 250
	});

	// Navigation Dropdown
	function showNav(){
		$(this).children('ul').slideDown();
		$('#caseSearchText').attr('disabled' , true);
	}
	function hideNav(){
		$(this).children('ul').slideUp();
		$('#caseSearchText').removeAttr('disabled');
	}
	var navConfig = {
		over: showNav,
		timeout: 500,
		out: hideNav
	};

	$('#nav li').hoverIntent(navConfig);

	// Give all .button classes jQuery UI button functionality
	$('.button').button();
	
	$('.actionsTrigger').button({
		icons: {secondary: "ui-icon-triangle-1-s"}
	}).click(function(){
		$(this).siblings('.actionsDropdown').toggle();
		return false;
	});

	// Tabs
	$('.tabs').tabs();
	
	// Radio Sets
	$('.radioSet').buttonset();
	
	// Cursor hover for submit buttons.
	$('input.btn').hover(function(){$(this).css({'cursor':'pointer'})});

// HOMEPAGE
	// Main Slideshow
//	$('#slideshow').cycle({
//		autostop: 1,
//		fx: 'fade',
//		speed: 'slow',
//		pause: 1,
//		pager: '#slideshowPager',
//		timeoutFn: function (curr, next, opts, isForward) {
//	        return (opts.currSlide + 1) * 1500;
//	    }
//	});
	
	// Homepage Video
	$('#videoEmbed').click(function(){
//		$('#video').animate({height: '444px'}, 500, function(){
//			$('#videoEmbed object').css({'visibility':'visible'});
//		});
		$('#video').animate({height: '418px'}, 500, function(){
			$('#videoEmbedCont').css({'display':'block'});
		});
		$('#videoCopy').animate({top: '37px'}, 500);
	});

	// Features
	$('#hFeaturesOver').cycle({
		fx: 'fade',
		speed: 'fast',
		timeout: 0,
		next: '.nextFeature',
		prev: '.prevFeature',
		pager: '#featuresPager' 
	});

	$('#hFeatures a').click(function() {
		$('#hFeaturesOverCont').animate({marginTop: '-234px'}, 750, 'easeOutExpo');
		slide = $(this).parent().index();
		$('#featuresPager a:eq(' + slide + ')').trigger('click'); 
	    return false; 
	});

	$('.closeFeatures').click(function() {
		$('#hFeaturesOverCont').animate({marginTop: '0px'}, 750, 'easeInExpo');
	    return false; 
	});

// STEP 1
	// In the coverage any element that doesn't have a child doesn't get a plus image.
	$("#coverage li:not(:has(li))").addClass('noChildren');

	// Tree directory open/close function
	$('#coverage a').click(function(){
		$(this).toggleClass('selected').parent().children('ul').toggle('slow');
		return false;
	});

	$('#saveExpand').click(function(){
		var text = $(this).html();
		if (text == 'Close') {
			$(this).html('Learn More');
			$('#saveSignUp').hide();
		} else {
			$(this).html('Close');
			$('#saveSignUp').show();
		}
		return false;
	});

// SUPPORT
	// Faq reveal functionality
	$('.faqTitle').click(function(){
		$(this).toggleClass('faqTitleOpen').parent().children('.faqContent').toggle();
		return false;
	});

// MEMBERSHIP
	// CC Popup
	$('.addCC').click(function(){
		var popPosition = $(this).offset();
		$('#popBox1').css({'top': popPosition.top - 223, 'left':popPosition.left + 90, 'visibility':'visible'});
		return false;
	});

	$('#closePopBox1').click(function(){
		$('#popBox1').css({'visibility':'hidden'});
		return false;
	});
});

function watermark(obj, text) {
    // set the watermark text
    jQuery(obj).val(text).addClass('watermark');
    jQuery(obj).attr('watermarktext', text);

    // clear on focus
    jQuery(obj).focus(function () {
        // added trim for Opera
        var val = jQuery.trim(jQuery(obj).val()); 
        var val2 = jQuery.trim(text);
        if (val == val2) {
            jQuery(obj).val('').removeClass('watermark');
        }
    });

    // restore on blur
    jQuery(obj).blur(function() {
        if (jQuery.trim(jQuery(obj).val()) == '') {
            jQuery(obj).val(text).addClass('watermark');
        }
    });
}

jQuery.fn.clearWatermark = function () {
    return this.each(function () {
        var $o = $(this);
        if ($o.val() == $o.attr('watermarktext')) {
            $o.val('');
        };
    });
};
