// EXTERNAL LINKS IN A NEW WINDOW
function oc(a) {
	var o = {};
	for(var i=0;i<a.length;i++){o[a[i]]='';}
	return o;
}
function buildExternal() {
	$('a').each(function(){
		try{
			domain = $(this).attr("href").match(/:\/\/(.[^/]+)/)[1];
			exceptions = new Array('www.rawlsmcnelis.com');
			/* OPEN PDFS AND EXTERNAL LINKS IN NEW WINDOW */
			if((domain in oc(exceptions)) || ($(this).attr("href").indexOf('.pdf') !== -1)){}else{
				$(this).unbind('click').bind('click',function(){
					window.open($(this).attr("href"));
					return false;		
				});
			}
		}catch(e){}		
	});
}

$(function(){

	if(typeof console === "undefined") {
		console = { log: function() { } };
	}
	
	var $ = jQuery;
	
	var RMM	=	{
	
		ui: function(){
			// MAIN NAV (HEADER)
			if ($('#header .main-nav ul li').length > 0) {
				$('#header ul li').hover(function() {
					$(this).addClass('over');
				}, function() {
					$(this).removeClass('over');
				});
			}
			// SLIDESHOW
			if ($('#slideshow').length > 0) {
				$('#slideshow').after('<div id="slideshow-nav">').cycle({ 
					fx: 'fade',
					cleartypeNoBg: true,
					activePagerClass: 'active',
					timeout: 6000,
					pager: '#slideshow-nav'
				});
			}
			// TEAM THUMBNAILS
			if ($('.team-member').length > 0) {
				$('.team-member:nth-child(6n)').addClass('team-member-last');
				$('.team-member').children('a').children('span').children('img').animate({
					width:'138', height:'118', left:'0', top:'0'
				}, 200);
				$('.team-member').mouseenter(function(e) {
					$(this).children('a').children('span').children('img').animate({
						width:'178', height:'158', left:'-20', top:'-20'
					}, 200);
				}).mouseleave(function(e) {
					$(this).children('a').children('span').children('img').animate({
						width:'138', height:'118', left:'0', top:'0'
					}, 200);
				});
			}
			// FAQ
			if ($('#faq-list').length > 0) {
				$('#faq-list h2 a.closed').live('click', function(){
					$(this).parent().next('.faq-answer').slideDown();
					$(this).removeClass('closed');
					$(this).addClass('open');
					return false;
				});
				$('#faq-list h2 a.open').live('click', function(){
					$(this).parent().next('.faq-answer').slideUp();
					$(this).removeClass('open');
					$(this).addClass('closed');
					return false;
				});
			}
			// CLEARING FLOATS
			$('.cleared').append('<span class="clear"></span>');
			// EXTERNAL LINKS
			buildExternal();
		},

		init: function(){
			RMM.ui();
		}
			
	};
	
	RMM.init();

});
