$(document).ready(function() {
	initPage();
	inlinePopUp();
	$(".clickedTab").click(function() {
			var currentID = $(this).attr('id');
			$("#" + currentID).parent('li').siblings().removeClass('selected');
			$("#" + currentID).parent('li').addClass('selected');		
			$(this).parent().parent().siblings().children().hide();
			$(this).parent().parent().siblings().children('.' + currentID).show();
		});	
		
	$(".reachTab").click(function() {
			var currentID = $(this).attr('id');
			$("#" + currentID).parent('li').siblings().removeClass('selected');
			$("#" + currentID).parent('li').addClass('selected');	
			$(this).parent().parent().parent().siblings().children().hide();
			$(this).parent().parent().parent().siblings().children('.' + currentID).show();
		});	


});

function initPage(){
	if (document.getElementById('topNavigation')) {
		$("#topNavigation li").hoverIntent({
			 over: showSubMenu,
			 timeout: 300,   
			 out: hideSubMenu 
		});	
		 addSelectedClassHome('#topNavigation');		
	}
	if (document.getElementById('profileDocuments')) tileDocuments('#profileDocuments');
	if (document.getElementById('menu_ourservices')) {
		addSelectedClass('#menu_ourservices');
		addSelectedtoRoot('#menu_ourservices');
		addSelectedtoSubReach();
		$("#ReachNav").hoverIntent({
			 over: showReachSubMenu,
			 timeout: 300,   
			 out: hideReachSubMenu 
		});	  
	}	
	
	if (document.getElementById('reportTypeSelector')) addSelectedClassToRadio('#reportTypeSelector');

}	



//Selected Class for Menus//
function addSelectedClass(e) {
	$(e + ' li a').each(function(){  
            if (window.location.href == this.href){
				$(this).parent('li').addClass('selected');
            }
        });
}

//Select Class Root Directory//
function addSelectedtoRoot(e) {
	if (e == '#menu_ourservices') {
		if (window.location.pathname == "/legal-marketing/") {
			$(e).children('li:first').addClass('selected');
		}
	}
	
	else if (e == '#anayltics_navigation') {
		if (window.location.pathname == "/anna/analytics/") { //This will need to change when Anayltics is worked on//
			$(e).children('li:first').addClass('selected');
		}
	}
}

//Universal Top Nav//
function addSelectedClassHome(e) {
	var str = window.location.href;
	if ( str.indexOf("/law-news/") >= 0) {$('#topNavLawNews').addClass('selected');}	
	if ( str.indexOf("/findlawyer/") >= 0) {$('#topNavFindLawyer').addClass('selected');}	
	if ( str.indexOf("/browse/legal-news.aspx") >= 0) {$('#topNavBrowse').addClass('selected');}	
	if ( str.indexOf("/legal-news/") >= 0 | str.indexOf("rssWidgets.aspx") >=0 ) {$('#topNavFollow').addClass('selected');}
	if ( window.location.pathname == "/" | window.location.pathname == "") {$('#topNavHome').addClass('selected');}
}

function addSelectedtoSubReach(){
	var str = window.location.href;
	if ( str.indexOf("who-is") >= 0) {$('#ReachNav').addClass('selected');}	
}


//Profile Pages//
function tileDocuments(e) { /* Magazine Layout for Profile Page */	
	    var numOfDocument = $(e).children('li').length;
		if (numOfDocument > 3) {
			for (i = 1; i < numOfDocument; i++) {
				$(e).children('li').next().addClass('item');
			}		
			$(e).children('li:first').addClass('first-item');	
			$(e).children('.item').wrapAll('<div id="profile_masonry">');	
		}
		$('#profile_masonry').masonry({
          itemSelector: '.item',
          isFitWidth: true,
		  gutterWidth: 50
      });
}


//Law-news//
function tileLegalFeeds(e) {
		$(e).children('li:nth-child(1)').children().remove('.lf_logo');
		$(e).children('li:nth-child(1)').addClass('latest-item');
		$(e).children('li:nth-child(1)').removeClass('odd');
}

//Law-news//
function legalFeedsHighlight(e) {
		$(e).children('li:nth-child(1)').children().remove('.lf_logo');
		$(e).children('li:nth-child(1)').addClass('latest-item');
		$(e).children('li:nth-child(1)').removeClass('odd');
}

//Our Services//
function goTestimonials() { window.location.replace('/legal-marketing/testimonials.aspx'); }



/* See more slider */
function seeMoreExpand(e) {
	if ($(e).children('.moreLessLink').text()=="See more")
	{
		$(e + ' .hide').slideDown(800);
		$(e).children('.moreLessLink').html("See less<img src='/img/arrow-redblock-up.gif' />");
	    $('html,body').animate({scrollTop: $(e).offset().top},'slow');
	}
	else 
	{
		$(e + ' .hide').slideUp(800);
		$(e).children('.moreLessLink').html("See more<img src='/img/arrow-redblock-down.gif' />");
	    $('html,body').animate({scrollTop: $(e).parent().offset().top},'slow');
	}
}

/* On Hover, Hide/Show Hidden Div */

function showHiddenDiv() {
	$(".larger_view").fadeOut();
	$(this).siblings('div').fadeIn('slow');
}

function hideHiddenDiv() {
	$(this).siblings('div').fadeOut('slow');
}

/* Hide / Show Sub Menu on Main Nav */
function showSubMenu() {
	if ($(this).children('div').attr('class') == 'mega-content') {
		$(this).addClass('hoverIntent');
		$(this).children('.mega-content').slideDown('slow');
	}
}

function hideSubMenu() {
	if ($(this).children('div').attr('class') == 'mega-content') {
		$(this).removeClass('hoverIntent');
		$(this).children('.mega-content').slideUp('slow');
	}
}

function showReachSubMenu() {
	$("#ReachSubMenu").show();
}

function hideReachSubMenu() {
	$("#ReachSubMenu").hide();
}



/* Inline Modal Dialog */
function inlinePopUp() {
	$(".inline-popup").click(function() {
		$(this).siblings('.inline-pop-frame').fadeIn();
	});

	$(".inline-popup-close").click(function() {
		$('.inline-pop-frame').fadeOut();
	});

}
	
function goTop() {  $('html, body').animate({scrollTop: '0px'}, 800); } /* Animate going to the top of the page */

/* Video Slider */
function slide_left() {
	$("#ourservices_video_slider li:visible").eq(0).addClass("first");
	var firstSlide = $("#ourservices_video_slider").children(".first").index();
	if (firstSlide != 0) { $("#ourservices_video_slider").children("li:nth-child("+ firstSlide + ")").animate({width:'toggle'},400) }
	$("#ourservices_video_slider").children(".first").removeClass("first");
}

function slide_right() {
	$("#ourservices_video_slider li:visible").eq(0).addClass("first");
	var firstSlide = $("#ourservices_video_slider").children(".first").index();
	var lastSlide = $("#ourservices_video_slider").children("li").length;
	if (firstSlide != lastSlide - 4 ) {	$("#ourservices_video_slider").children(".first").animate({width:'toggle'},400);
;  }
	$("#ourservices_video_slider").children(".first").removeClass("first");
}


/* Legacy Scripts */

function checkAll1(field)
{
	for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll1(field)
{
	for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}

function sendit() {

    var fromLocation = escape(document.location);
    var fromTitle = escape(document.title);
    var sendWindow;

    sendWindow = window.open ("/inc/sendToColleague.aspx?loc=" + fromLocation + "&title=" + fromTitle,"SendToColleague","toolbar=0,scrollbars=1,location=0,statusbar=0,status=0,menubar=0,resizable=0,width=400,height=650");
    sendWindow.focus ();
}

/*Target Anchors for IE browsers*/
function sfTarget () {
	var sfEls= document.getElementsByTagName("div");
	var aEls = document.getElementsByTagName("a");
	document.lastTarget = null;
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].id) {
			if (location.hash==("#" + sfEls[i].id)) {
				sfEls[i].className+=" sftarget";
				document.lastTarget=sfEls[i];
			}
			for (var j=0; j<aEls.length; j++) {
				if (aEls[j].hash==("#" + sfEls[i].id)) aEls[j].targetEl = sfEls[i]; aEls[j].onclick = function() {
					if (document.lastTarget) document.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\b"), "");
					if (this.targetEl) this.targetEl.className+=" sftarget"; document.lastTarget=this.targetEl;
					return true;
				}
			}
		}
	}
}

/*window.onload=sfTarget;*/

