/*********************************************************************************************
*	BEGIN: jQuery Extensions
*/
$.fn.extend({/*
  exists: function(obj) {
    return obj.length > 0 ? true : false;
  },*/
  fnExists: function(obj) {
    return typeof(obj) == 'function' ? true : false;
  },
  isUndefined: function(obj) {
    return typeof(obj) == 'undefined' ? true : false;
  }
});

jQuery.fn.exists = function() {
	try {
		return jQuery(this).length != 0 ? true : false ;
	} catch (err) {
		// do nothing
	}
};


/*
*	END: jQuery Extensions
*********************************************************************************************/

/*********************************************************************************************
*	BEGIN: Global Variables
*/

// Set user agent
var userAgent = navigator.userAgent.toLowerCase();

/*
*	END: Global Variables
*********************************************************************************************/

/*****************************************************************************************************
 * BEGIN: Functions
 */
// -------------------------------------------------------------------------
// Begin "Browser detection"
function browserDetection() {
	jQuery.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); 
	if(jQuery.browser.msie) { // Is this a version of IE?
		jQuery("body").addClass("IE");        
		jQuery("body").addClass("IE" + jQuery.browser.version.substring(0,1));
	}
	if(jQuery.browser.chrome) { // Is this a version of Chrome?
		jQuery("body").addClass("Chrome");
		userAgent = userAgent.substring(userAgent.indexOf("chrome/") +7);
		userAgent = userAgent.substring(0,1);
		jQuery("body").addClass("Chrome" + userAgent);  
		jQuery.browser.safari = false; // If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
	}
	if(jQuery.browser.safari) { // Is this a version of Safari?
		jQuery("body").addClass("Safari");        
		userAgent = userAgent.substring(userAgent.indexOf("version/") +8);
		userAgent = userAgent.substring(0,1);
		jQuery("body").addClass("Safari" + userAgent);
	}
	if(jQuery.browser.mozilla) { // Is this a version of Mozilla?
		if(navigator.userAgent.toLowerCase().indexOf("firefox") != -1) { //Is it Firefox?
			jQuery("body").addClass('Firefox');
			userAgent = userAgent.substring(userAgent.indexOf("firefox/") +8);
			userAgent = userAgent.substring(0,1);
			jQuery("body").addClass("Firefox" + userAgent);
		} else { // If not then it must be another Mozilla
			jQuery("body").addClass("Mozilla");
		}
	}
}

// End "Browser detection"


function checkForm() {
	var inputs = $(".form :input").validator({
		messageClass: "errmessage",
		position: "bottom left"
	});
	
	return inputs.data("validator").checkValidity();
}
/*
 * End: Functions
 ****************************************************************************************************/

/*********************************************************************************************
*	BEGIN: safe jQuery load
*/
jQuery(browserDetection);

jQuery(function($) {
	
	
	/* BEGIN: Homepage Hero initialization */
	if($("#HeroItems").children().length > 1) {
		for(var i=0; i<$("#HeroItems").children().length; i++) {
			$("#Pager").append('<a href="#"></a>');
		}
	}
	if($('#HeroItems').length != 0) {
		$('#HeroItems').cycle({
			fx:'scrollHorz',
			speed: 600,
			timeout: 8000,
			pager: '#Pager',
			pagerAnchorBuilder: function(idx, slide) { 
				return '#Pager a:eq(' + idx + ') '; 
			},
			activePagerClass: 'active',
			allowPagerClickBubble: true,
			pause: 1,
			cssAfter: {background:'transparent'},  
			cssBefore: {background:'transparent'}
		});
	}
	/* End: Homepage Hero initialization */

	/* Begin: Attorney Image hover bind */
	$("a.attorney_name").hover(function() {
		$(this).parent().prev().children("a.attorney_thumb").css("background-position","0 -150px");
	}, function() {
		$(this).parent().prev().children("a.attorney_thumb").css("background-position","0 0");
	});
	/*
	$("a.attorney_thumb").hover(function() {
		$(this).css("background-position","0 -150px");
	}, function() {
		$(this).css("background-position","0 0");
	});*/
	/* End: Attorney Image hover bind */
	
	/* Attorney Ovelay
	**********************************************************************************************************/
	if($('.attorney_detail_image_overlay').exists) {
		$('a.overlay_trigger[rel]').overlay({
			mask: '#000000',
			loadSpeed: 100,
			opacity: .8
		});
	}

	/* Begin: social media icon slide */
	$(".social_media a").hover(function() {
		$(this).animate({marginRight:"-13px"}, 200);
	}, function() {
		$(this).animate({marginRight:"0px"}, 200);
	});
	/* End: social media icon slide */
});
/*
 * End: Custom jQuery
 ****************************************************************************************************/
