// when the DOM is ready...
$(document).ready(function () {

    var $panels_white = $('#slider_white .scrollContainer > div');
    var $container_white = $('#slider_white .scrollContainer');

    // if false, we'll float all the panels left and fix the width 
    // of the container
    var horizontal = false;

    
    // collect the scroll object, at the same time apply the hidden overflow
    // to remove the default scrollbars that will appear
    var $scroll_white = $('#slider_white .scroll').css('overflow', 'hidden');
	var $scroll_oliver = $('#slider_oliver .scroll').css('overflow', 'hidden');
   	var $scroll_amundson = $('#slider_amundson .scroll').css('overflow', 'hidden');
	var $scroll_manover = $('#slider_manover .scroll').css('overflow', 'hidden');
	var $scroll_miserlis = $('#slider_miserlis .scroll').css('overflow', 'hidden');
	var $scroll_hulbert = $('#slider_hulbert .scroll').css('overflow', 'hidden');
	var $scroll_gallagher = $('#slider_gallagher .scroll').css('overflow', 'hidden');
	var $scroll_sinclair = $('#slider_sinclair .scroll').css('overflow', 'hidden');
	var $scroll_webb = $('#slider_webb .scroll').css('overflow', 'hidden');
	var $scroll_mcatee = $('#slider_mcatee .scroll').css('overflow', 'hidden');
	
    // handle nav selection
    function selectNav() {
        //console.log(this);
		
		$(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
			
    }

    $('#slider_white .profile_tabs').find('a').click(selectNav);
	$('#slider_oliver .profile_tabs').find('a').click(selectNav);
	$('#slider_amundson .profile_tabs').find('a').click(selectNav);
	$('#slider_manover .profile_tabs').find('a').click(selectNav);
	$('#slider_miserlis .profile_tabs').find('a').click(selectNav);
	$('#slider_hulbert .profile_tabs').find('a').click(selectNav);
	$('#slider_gallagher .profile_tabs').find('a').click(selectNav);
	$('#slider_sinclair .profile_tabs').find('a').click(selectNav);
	$('#slider_webb .profile_tabs').find('a').click(selectNav);
	$('#slider_mcatee .profile_tabs').find('a').click(selectNav);
	

    // go find the navigation link that has this target and select the nav
    function trigger(data) {
        var el = $('.profile_tabs').find('a[href$="' + data.id + '"]').get(0);
        selectNav.call(el);
    }

    if (window.location.hash) {
        trigger({ id : window.location.hash.substr(1) });
    } else {
        $('ul.profile_tabs a:first').click();
    }

    // offset is used to move to *exactly* the right place, since I'm using
    // padding on my example, I need to subtract the amount of padding to
    // the offset.  Try removing this to get a good idea of the effect
    var offset = parseInt((horizontal ? 
        $container_white.css('paddingTop') : 
        $container_white.css('paddingLeft')) 
        || 0) * -1;

	
	
    var scrollOptions_white = {
        target: $scroll_white, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: $panels_white,

        navigation: '#slider_white .profile_tabs a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions_oliver = {
        target: $scroll_oliver, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: '#slider_oliver .scrollContainer > div',

        navigation: '#slider_oliver .profile_tabs a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions_amundson = {
        target: $scroll_amundson, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: '#slider_amundson .scrollContainer > div',

        navigation: '#slider_amundson .profile_tabs a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions_manover = {
        target: $scroll_manover, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: '#slider_manover .scrollContainer > div',

        navigation: '#slider_manover .profile_tabs a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions_miserlis = {
        target: $scroll_miserlis, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: '#slider_miserlis .scrollContainer > div',

        navigation: '#slider_miserlis .profile_tabs a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions_hulbert = {
        target: $scroll_hulbert, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: '#slider_hulbert .scrollContainer > div',

        navigation: '#slider_hulbert .profile_tabs a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions_gallagher = {
        target: $scroll_gallagher, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: '#slider_gallagher .scrollContainer > div',

        navigation: '#slider_gallagher .profile_tabs a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions_sinclair = {
        target: $scroll_sinclair, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: '#slider_sinclair .scrollContainer > div',

        navigation: '#slider_sinclair .profile_tabs a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions_webb = {
        target: $scroll_webb, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: '#slider_webb .scrollContainer > div',

        navigation: '#slider_webb .profile_tabs a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	/*
	var scrollOptions_mcatee = {
        target: $scroll_mcatee, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: '#slider_mcatee .scrollContainer > div',

        navigation: '#slider_mcatee .profile_tabs a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	*/
	var scrollOptions_sideNav = {

        //navigation: '.list_none a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions_backtotop = {

        //navigation: '.list_none a',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
    // apply serialScroll to the slider - we chose this plugin because it 
    // supports// the indexed next and previous scroll along with hooking 
    // in to our navigation.
    //$('#slider_white').serialScroll(scrollOptions_white);
	//$('#slider_oliver').serialScroll(scrollOptions_oliver);
	//$('#slider_amundson').serialScroll(scrollOptions_amundson);
	//$('#slider_manover').serialScroll(scrollOptions_manover);
	//$('#slider_miserlis').serialScroll(scrollOptions_miserlis);
	//$('#slider_hulbert').serialScroll(scrollOptions_hulbert);
	//$('#slider_gallagher').serialScroll(scrollOptions_gallagher);
	//$('#slider_sinclair').serialScroll(scrollOptions_sinclair);
	//$('#slider_webb').serialScroll(scrollOptions_webb);
	//$('#slider_mcatee').serialScroll(scrollOptions_mcatee);
    // now apply localScroll to hook any other arbitrary links to trigger 
    // the effect
	// m - added the id in front to restrict links to that div. 
    $('#right_side_nav').localScroll(scrollOptions_sideNav);
	$('#practiceareas').localScroll(scrollOptions_sideNav);
	$('#backtotop1').localScroll(scrollOptions_backtotop);
	$('#backtotop2').localScroll(scrollOptions_backtotop);
	$('#backtotop3').localScroll(scrollOptions_backtotop);
	$('#backtotop4').localScroll(scrollOptions_backtotop);
	$('#backtotop5').localScroll(scrollOptions_backtotop);
	$('#backtotop6').localScroll(scrollOptions_backtotop);
	$('#backtotop7').localScroll(scrollOptions_backtotop);
	$('#backtotop8').localScroll(scrollOptions_backtotop);
	$('#backtotop9').localScroll(scrollOptions_backtotop);
	$('#backtotop10').localScroll(scrollOptions_backtotop);
	$('#backtotop11').localScroll(scrollOptions_backtotop);
	$('#backtotop12').localScroll(scrollOptions_backtotop);
	$('#backtotop13').localScroll(scrollOptions_backtotop);
	$('#backtotop14').localScroll(scrollOptions_backtotop);
	$('#backtotop15').localScroll(scrollOptions_backtotop);
	$('#white').localScroll(scrollOptions_white);
	$('#oliver').localScroll(scrollOptions_oliver);
	$('#amundson').localScroll(scrollOptions_amundson);
	$('#manover').localScroll(scrollOptions_manover);
	$('#miserlis').localScroll(scrollOptions_miserlis);
	$('#hulbert').localScroll(scrollOptions_hulbert);
	$('#gallagher').localScroll(scrollOptions_gallagher);
	$('#sinclair').localScroll(scrollOptions_sinclair);
	$('#webb').localScroll(scrollOptions_webb);
	//$('#mcatee').localScroll(scrollOptions_mcatee);
	//$.localScroll(scrollOptions_webb);
	//$(...).scrollTo();
	
    // finally, if the URL has a hash, move the slider in to position, 
    // setting the duration to 1 because I don't want it to scroll in the
    // very first page load.  We don't always need this, but it ensures
    // the positioning is absolutely spot on when the pages loads.
    scrollOptions_white.duration = 1;
	scrollOptions_oliver.duration = 1;
	scrollOptions_sideNav.duration = 1;
    //$.localScroll.hash(scrollOptions2);
	
	// m - trying to get just element within certain area to scroll
	/*
	$('#white').serialScroll({
		target:'.profile',
		items:'#slider .scrollContainer > div',
		navigation:'.profile_tabs li a',
		duration:500,
		easing:'swing'
					 });
	*/
	
	//-- tab animation	
	
	var navDuration = 150; //time in miliseconds
	var navJumpHeight = "0.45em";
	
	$('.profile_tabs li').hover(function() {
	  $(this).animate({ top : "-="+navJumpHeight }, navDuration);            
	}, function() {
	  $(this).animate({ top : "15px" }, navDuration);
	});
	
	
//-- nav animation2 --
	$('#nav_move').css({ 
	  width: $('#nav2 li:first a').width()+20, 
	  height: $('#nav2 li:first a').height()+20 
	});
	$('#nav2 li:first a').addClass('cur');
	
	$('#nav2 a').click(function() {
	  var offset = $(this).offset();
	  var offsetBody = $('#center_wrapper').offset(); //find the offset of the wrapping div    
	  $('#nav_move').animate(
		{ 
		  width: $(this).width()+20, 
		  height: $(this).height()+20, 
		  left: (offset.left - offsetBody.left - 143) 
		}, 
		{ duration: 350, easing: 'easeInOutCirc' }
	  );
	  $('.cur').removeClass('cur');
	  $(this).addClass('cur');
	  return false;
	});           
	
	
	//-- list animation --
	var fadeDuration = 150; //time in milliseconds
	
	$('#list1 li a').hover(function() {
	  $(this).animate({ paddingLeft: '30px' }, fadeDuration);
	  $(this).children('span').show().animate({ left: -5 }, fadeDuration);
	}, function() {
	  $(this).animate({ paddingLeft: '15px' }, fadeDuration);
	  $(this).children('span').animate({ left: -35 }, fadeDuration).fadeOut(fadeDuration);          
	});
	
	
	$('.see_code').click(function() {
	  if($(this).parent().next().is(':visible')) {
		$(this).html('+ Show Code');
		$(this).parent().next().toggle();
	  } else {
		$(this).html('- Hide Code');
		$(this).parent().next().toggle();            
	  }
	  return false;
	});	
	
	// -- Form Handler
	
	//remove warning class
	$('.warning').remove();
	//AJAX call using $.get()
	$.get('/frags/token.php',function(txt){
	//find element with class="secure"
	$('.secure').append('<input type="hidden" name="ts" value="'+txt+'" />');
	});
	

});