$(document).ready(function(){

	var date = new Date();
		var d = date.getDate();
		var m = date.getMonth();
		var y = date.getFullYear();
		
		$('#calendar').fullCalendar({
			header: {
				left: 'prev,next today',
				center: 'title',
				right: 'month,basicWeek,basicDay'
			},
			editable: true,
			events: [
				{
					title: 'All Day Event',
					start: new Date(y, m, 1)
				},
				{
					title: 'Long Event',
					start: new Date(y, m, d-5),
					end: new Date(y, m, d-2)
				},
				{
					id: 999,
					title: 'Repeating Event',
					start: new Date(y, m, d-3, 16, 0),
					allDay: false
				},
				{
					id: 999,
					title: 'Repeating Event',
					start: new Date(y, m, d+4, 16, 0),
					allDay: false
				},
				{
					title: 'Meeting',
					start: new Date(y, m, d, 10, 30),
					allDay: false
				},
				{
					title: 'Lunch',
					start: new Date(y, m, d, 12, 0),
					end: new Date(y, m, d, 14, 0),
					allDay: false
				},
				{
					title: 'Birthday Party',
					start: new Date(y, m, d+1, 19, 0),
					end: new Date(y, m, d+1, 22, 30),
					allDay: false
				},
				{
					title: 'Click for Google',
					start: new Date(y, m, 28),
					end: new Date(y, m, 29),
					url: 'http://google.com/'
				}
			]
		});


  //Location and Hours page.
  var txt = $('#merc_center').html();
  $('#location_info').html(txt);
  $("#jumpMenu").change(function() { 
   var loc = $(this).val();
   var txt = $('#'+loc).html();
   $('#location_info').html(txt);
  });

$("#merc_stcharles_link").easyTooltip({
  		useElement: "merc_stcharles"	
  	});
$("#merc_carmel_link").easyTooltip({
  		useElement: "merc_carmel"	
  	});
$("#merc_stjoseph_link").easyTooltip({
  		useElement: "merc_stjoseph"	
  	});
$("#merc_savannah_link").easyTooltip({
  		useElement: "merc_savannah"	
  	});
$("#merc_walmart_link").easyTooltip({
  		useElement: "merc_walmart"	
  	});
$("#merc_center_link").easyTooltip({
  		useElement: "merc_center"	
  	});
$("#merc_jersey_link").easyTooltip({
  		useElement: "merc_jersey"	
  	});
$("#merc_maine_link").easyTooltip({
  		useElement: "merc_maine"	
  	});
  	
  // MEGA NAV FUNCTIONS
	function megaHoverOver(){
    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
	}
	
	//On Hover Out
	function megaHoverOut(){
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
	      $(this).hide();  //after fading, hide it
	  });
	}
	
	//Set custom configurations
	var config = {
	     sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
	     interval: 50, // number = milliseconds for onMouseOver polling interval
	     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
	     timeout: 200, // number = milliseconds delay before onMouseOut
	     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};

	$("ul#mega-nav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
	$("ul#mega-nav li").hoverIntent(config); //Trigger Hover intent with custom configurations
	
  // $('a[href^="http://www."]').click(function()
  // {
  //   return confirm('You are about to view a website outside of mercantilebk.com.  This site link is provided only as an account resource tool.  Some of its content may not represent Mercantile Bank and the Bank may not be held liable for information and transactions outside of our direct control.  Please select OK to continue.');
  // });
  // 
  // $('a[href^="https://www."]').click(function()
  // {
  //   return confirm('You are about to view a website outside of mercantilebk.com.  This site link is provided only as an account resource tool.  Some of its content may not represent Mercantile Bank and the Bank may not be held liable for information and transactions outside of our direct control.  Please select OK to continue.');
  // });  
  

	$('a[href^="mailto:"]').click(function()
	{
	  return confirm("WARNING:  Please note that any e-mail directed from this location is not secure or encrypted.\n\nMercantile Bank encourages you NOT to include any sensitive financial information in your e-mail correspondence.  Information such as account balances, account numbers, personal identification numbers (PINs), Social Security numbers, and/or any other information that you consider sensitive should NOT be included.\n\nBy clicking OK, you acknowledge your understanding of this cautionary statement and would like to continue e-mailing Mercantile Bank.\n\n");
	});	
	
	
	//Gallery Functions
	$(function() {
	    var galleries = $('.ad-gallery').adGallery( {
            thumb_opacity: 0.4,
            start_at_index: 2,
            animation_speed: 600,
			width: 630,
			height: false,
			display_next_and_prev: false,
            display_back_and_forward: false,
			slideshow: {
				autostart: true,
				stop_on_scroll: false
			},
			effect: 'fade' // or 'slide-vert', 'fade', or 'resize', 'none'
	});
	  });
	
	
	
	//Show/Hide of Navigation	
	$('div.visibility> .row:gt(0)').hide();  
	  $('div.visibility> .click').click(function() {
	    $(this).next('.row:hidden').slideDown('fast')
	    .siblings('.row:visible').slideUp('fast');
	  });
	  
	  
	// DATE & TIME PICKER
  $('input.datetime').datetimepicker({
    dateFormat: 'yy-mm-dd',
    timeFormat: 'hh:mm:ss',
    changeYear: true
  });
  
	$('.tabs a').click(function(){
		switch_tabs($(this));
	});
	switch_tabs($('.defaulttab'));

  $('.personalize li').click(function(){
		set_avatar($(this));
	});
	
  $('.location_select').change(function(){
		set_location($('.location_select :selected'));
	});	
	
	$('div.gender_avatars').hide();
  $('#gender_select input').click(function(){
		set_gender($(this));
	});
	
	var loc = $('#location').val();
	if(loc)
	{
    $('#customer-service-bg').css("background-image", "url("+loc+")");  
  }
 
})

function switch_tabs(obj)
{
	$('.tab-content').hide();
	$('.tabs a').removeClass("selected");
	var id = obj.attr("rel");
 
	$('#'+id).show();
	obj.addClass("selected");
}

function set_gender(obj)
{
	var gender = obj.val();
	var img = obj.children().attr("rel");
	$('#'+gender).slideDown('fast')
	.siblings('.gender_avatars').slideUp('fast');
}

function set_avatar(obj)
{
	var id = obj.attr("rel");
	var img = obj.children().attr("rel");
	$('#avatar_id').val(id);
	$('#avatar').attr('src',img);
	$('.personalize li').removeClass("selected");	
  obj.addClass("selected");
}

function set_location(obj)
{
	var loc = obj.attr("rel");
	$('#customer-service-bg').css("background-image", "url("+loc+")");  
}

//Tool Tips
$(function(){
$(".addToolTip").tipTip({maxWidth: "300px", edgeOffset: 10});




//Modal Window

//select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = $(this).attr('href');
     
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
     
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect    
        $('#mask').fadeIn(1000);   
        $('#mask').fadeTo("slow",0.8); 
     
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
               
        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);
     
        //transition effect
        $(id).fadeIn(2000);
     
    });
     
    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .window').hide();
    });    
     
    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    });        


});



