
/** setup jquery live events for any partial postback (updatepanel) sources here **/
$('.document-filters a').live('click', function () { onRequestServed(); });
$('.year-filters a').live('click', function () { onRequestServed(); });
$('.tabbed-list a').live('click', function () { onRequestServed(); });
/** end of live event wire-ups **/

// hero slide for homepages
function swapPromo(obj) {
}

var currentSlide = 1;
var directionVar = "next";
var isAnimating = false;

function promoPrev() {
	if ($(".divscroller").is(":animated")) return;
	directionVar = "prev";
	$('.hero-block').stop();
	$('#divscrollerWrap').cycle('prev');
	$('.hero-block').css({ "display": "none" });
	$('.hero-block').css({ "right": "-350px" });
	$('#divscrollerWrap').cycle('prev');
}

function promoNext() {
	if ($(".divscroller").is(":animated")) return;
	directionVar = "next";
	$('.hero-block').stop();
	$('#divscrollerWrap').cycle('next');
	$('.hero-block').css({ "display": "none" });
	$('.hero-block').css({ "right": "-350px" });
}

var slideStart = false;
var selectObj = new Object();

function changed(curr, next, opts) {
	$('.hero-block').stop();
	$('.hero-block').css({ "display": "block" });
	$('.hero-block').css({ "right": "-350px" });
	$('.hero-block').animate({ "right": "+=387px" }, 1500, "easeOutCirc");
	return;
	var inners = $('.hero-block');
	$(inners).fadeIn(100);
	if (slideStart) {
		$(selectObj).removeClass('selectedon');
		selectObj = "promoSelect" + curr.nextSlide;
		selectObj = document.getElementById(selectObj);
		$(selectObj).addClass('selectedon');
	}
	if (!slideStart) slideStart = true;
}

var blockStr = "";
function beforechange(curr, next, opts) {
	$('.hero-block').stop();
	$('.hero-block').css({ "display": "none" });
}


 //news ticker 

function tickerPrev(){
	tickerDirectionVar="prev";
	$('.news-ticker-items').cycle('prev');
	$('.news-ticker-items').cycle('pause');
  }

  function tickerNext(){
	tickerDirectionVar="next";
	$('.news-ticker-items').cycle('next');
	$('.news-ticker-items').cycle('pause');
  }


// region map
  function linkOver(obj,x,y,x2,y2){
	$('.marker').css({left: (x) +"px"});
	$('.marker').css({top: (y) + "px"});
	$('.marker').css({display:"block"});
	str=obj.title;
	str= "a[title="+ str +"]";
	$(str).css({color:"#716560", textDecoration: "underline"});
	if($('body').hasClass('insurance')) {
	  $(str).addClass('region-map-hover-ins');
	} else if ($('body').hasClass('re-insurance')) {
	  $(str).addClass('region-map-hover-re-ins');
	}
  }

  function linkOut(obj){
	$('.marker').css({display:"none"});
	str=obj.title;
	str= "a[title="+ str +"]";
	$(str).css({color:"#000000", textDecoration: "none"});
	if($('body').hasClass('insurance')) {
	  $(str).removeClass('region-map-hover-ins');
	} else if ($('body').hasClass('re-insurance')) {
	  $(str).removeClass('region-map-hover-re-ins');
	}  
  }

  function onRequestServed()
  {
	  $(".mod-search-entry").focus(function ()
	  {
		  if (this.value == this.defaultValue)
		  {
			  this.value = "";
		  }
	  }).blur(function ()
	  {
		  if (!this.value.length)
		  {
			  this.value = this.defaultValue;
		  }
	  });

	  //searchbox functionality		
      if ($(".search-entry").val() != "")
	  {
		  $(".search-entry").addClass('nobackground');
	  }
	  if ($(".people-search-entry").val() != "")
	  {
		  $(".people-search-entry").addClass('nobackground');
	  }
        if ($(".signup-entry").val() != "") {
            $(".signup-entry").addClass('nobackground');
        }

	  $(".search-entry, .people-search-entry, .signup-entry").focus(function ()
	  {
		  $(this).addClass('nobackground');
	  });
$(".search-entry, .people-search-entry, .signup-entry").blur(function ()
	  {
		  if ($(this).val() == "")
			  $(this).removeClass('nobackground');
	  });

	  //primary navigation hover

	  //$('.hover-menu .nav-section-btn a').css('cursor', 'default');

	  function show()
	  {
		  var menu = $(this);
		  menu.children(".nav-section").show();
		  $('.nav-section-btn', this).addClass('hover');
		  //$('.nav-section-btn a', this).css('cursor', 'default');
	  }

	  function hide()
	  {
		  var menu = $(this);
		  menu.children(".nav-section").hide();
		  $('.nav-section-btn', this).removeClass('hover');
	  }

	  $(".hover-menu").hoverIntent({
		  sensitivity: 4, // number = sensitivity threshold (must be 1 or higher)
		  interval: 150,   // number = milliseconds for onMouseOver polling interval
		  over: show,     // function = onMouseOver callback (required)
		  timeout: 300,   // number = milliseconds delay before onMouseOut
		  out: hide       // function = onMouseOut callback (required)
	  });

	  //contact menu slider
	  function showContacts()
	  {
		  var menu = $(this);
		  $('p', this).addClass('hover');
		  $('#header-contact-menu').css('width', '290px');
		  menu.children("#header-contact-menu ul").animate({ width: 'toggle' }, 350);
	  }

	  function hideContacts()
	  {
		  var menu = $(this);
		  menu.children("#header-contact-menu ul").animate({ width: 'toggle' }, 350, function ()
		  {
			  $('#header-contact-menu').css('width', '70px');
		  });
		  $('p', this).removeClass('hover');
	  }

	  $("#header-contact-menu").hoverIntent({
		  sensitivity: 4, // number = sensitivity threshold (must be 1 or higher)
		  interval: 200,   // number = milliseconds for onMouseOver polling interval
		  over: showContacts,     // function = onMouseOver callback (required)
		  timeout: 300,   // number = milliseconds delay before onMouseOut
		  out: hideContacts       // function = onMouseOut callback (required)
	  });

	  // homepage hero promo area   
	  $('#promo-1').addClass('promoHide');
	  $('.scrollnav').removeClass('promoHide');
	  //$('.group-hero .scrollnav').addClass('promoHide');
	  $('#divscrollerWrap').fadeIn(800, function ()
	  {
		  // Animation complete
	  });

	  $('#divscrollerWrap').cycle({
		  fx: 'scrollHorz',
		  //delay: 500,
		  speed: 1000,
		  timeout: 7000,
		  pause: true,
		  before: function (curr, next, opts) { beforechange(opts); isAnimating = true; },
		  after: function (curr, next, opts) { changed(opts); isAnimating = false; },
		  pager: '#scrollpager',
		  requeueOnImageNotLoaded: true
	  });


	  //group scroller   

	  var groupSlides = $('#group-scroller').cycle({
		  fx: 'scrollHorz',
		  speed: 1000,
		  timeout: 7000,
		  prev: '#prev',
		  next: '#next',
		  pause: true,
		  before: function (curr, next, opts) { infoChange(next) },
		  requeueOnImageNotLoaded: true
	  });


	  //group scroller grab html
	  function infoChange(next)
	  {
		  obj = $('.info', next);
		  $('#promo-info').html($(obj).html());
	  }

	  // news ticker

	  $('.news-ticker-items').cycle({
		  fx: 'scrollVert',
		  //delay: 20,
		  timeout: 6000,
		  speed: 1500,
		  pause: true
	  });

	  //tabbed menu
	  //$('ul.tabbed-list a').click(function () {
	  //$('ul.tabbed-list a').removeClass('selected');
	  //$(this).addClass('selected');
	  //return true;
	  //}).filter(':first').click();

	  //show/hide directions
	  $('.show-btn a').toggle(function ()
	  {
		  $('.directions-bottom').slideDown(600, 'easeInQuad').animate({ color: "#000" }, { duration: 2500, queue: false });
		  $(this).parent().addClass('up');
		  $(this).text('Hide directions');
	  }, function ()
	  {
		  $('.directions-bottom').slideUp(800, 'easeOutQuad').animate({ color: "#E8E7E5" }, { duration: 1000, queue: false });
		  $(this).parent().removeClass('up');
		  $(this).text('Show directions');
	  });

	  //Exco show/hide profile information
	  $('.module-box-exco .show-btn a').toggle(function ()
	  {
		  $(this).parent().prev().slideDown(600, 'easeInQuad').animate({ color: "#000" }, { duration: 2500, queue: false });
		  $(this).parent().addClass('up');
		  $(this).text('Profile information');
	  }, function ()
	  {
		  $(this).parent().prev().slideUp(800, 'easeOutQuad').animate({ color: "#E8E7E5" }, { duration: 1000, queue: false });
		  $(this).parent().removeClass('up');
		  $(this).text('Profile information');
	  });

	  //Site map show/hide information
	  $('.site-map-module h2 .site-links').toggle(function ()
	  {
		  $(this).parent().next().slideDown(1000, 'easeOutQuad');
		  $(this).parent().addClass('up');
	  }, function ()
	  {
		  $(this).parent().next().slideUp(800, 'easeOutQuad');
		  $(this).parent().removeClass('up');
		  //$(this).text('Profile information');
	  });


	  //stripe table
	  $('.stripe-table tr:odd').addClass('odd');

	  //background for expertise modules
	  $('.expertise .left .article-list-module:even, .expertise .right .article-list-module:even').addClass('standard-grey-bg');

	  //float modules
	  $('.team-results-container .module-box:odd').css('float', 'right');


	  //get x,y co-ordinates of region maps

	  // $('<div>',
	  //  
	  //    {
	  //      class: 'coords',
	  //      
	  //      css: {
	  //        position: 'absolute',
	  //        border: '1px solid red',
	  //        top: '0',
	  //        left: '0'
	  //      }
	  //    })
	  //    .appendTo('#content');
	  // 
	  // $('.region-map').mousemove(function(e){ 
	  //   var offset = $(this).offset();
	  //   var relativeX = (e.pageX - offset.left);
	  //   var relativeY = (e.pageY - offset.top);
	  //   $('.coords').html('relativeX = ' + relativeX + ', relativeY = ' + relativeY);
	  // });


	  //ALL WORLD MAPS  

	  //check body class and choose colour and map functions

	  function chooseColour()
	  {
		  if ($('body').is('.insurance-home, .insurance'))
		  {

			  $('.area_hover').mouseover(function ()
			  {
				  tmp = this.title.replace(/ /gi, "_").toLowerCase();
				  $('#' + tmp).stop().fadeTo('100', 1);
				  $('.' + tmp).css({ color: "#ea8a40" });
			  });

			  $('.home-map-links-a,.home-map-links-zoom-a, .world-map-links-a').mouseover(function ()
			  {
				  tmp = this.title.replace(/ /gi, "_").toLowerCase();
				  $('#' + tmp).stop().fadeTo('100', 1);
				  $(this).css({ color: "#ea8a40" });
			  });

			  //              if ($('body').is('.insurance-home')) {
			  //                  $('#continentDiv').html(continentOrange());
			  //                  $('#europeDiv').html(europeOrange());
			  //                  $('#northAmericaDiv').html(northAmericaOrange());
			  //              }
		  } else if ($('body').is('.re-insurance-home, .re-insurance'))
		  {

			  $('.area_hover').mouseover(function ()
			  {
				  tmp = this.title.replace(/ /gi, "_").toLowerCase();
				  $('#' + tmp).stop().fadeTo('100', 1);
				  $('.' + tmp).css({ color: "#71cc98" });
			  });

			  $('.home-map-links-a,.home-map-links-zoom-a, .world-map-links-a').mouseover(function ()
			  {
				  tmp = this.title.replace(/ /gi, "_").toLowerCase();
				  $('#' + tmp).stop().fadeTo('100', 1);
				  $(this).css({ color: "#71cc98" });
			  });
			  if ($('body').is('.re-insurance-home'))
			  {
				  //$('#continentDiv').html(continentGreen());
			  }
		  } else if ($('body').is('.group-home, .group'))
		  {

		      $('.area_hover').mouseover(function () {
		          tmp = this.title.replace(/ /gi, "_").toLowerCase();
		          $('#' + tmp).stop().fadeTo('100', 1);
		          $('.' + tmp).css({ color: "#afa8a1" });
		      });

			  $('.home-map-links-a,.home-map-links-zoom-a').mouseover(function ()
			  {
				  tmp = this.title.replace(/ /gi, "_").toLowerCase();
				  $('#' + tmp).stop().fadeTo('100', 1);
				  $(this).css({ color: "#afa8a1" });
			  });

			  $('#continentDiv').html(continentGroup());

			  $('.home-map-links-a, .area_hover').click(function () {
			      
				  var where = $(this).attr('href');
				  $(where).fadeIn('slow');
				  //$('#' + where + "-info").css({display: "block"});
				  
                  return false;
			  });

			  $('.close-btn').click(function ()
			  {
				  $(this).parent().fadeOut('slow');
				  return false;
			  });

		  }

	  }

	  chooseColour();

	  //world map mouse events

	  $('.area_hover').mouseout(function ()
	  {
		  tmp = this.title.replace(/ /gi, "_").toLowerCase();
		  $('#' + tmp).stop().fadeTo('100', 0, function ()
		  {
		  });
		  $('.' + tmp).css({ color: "#000000" });
	  });

	  $('.home-map-links-a,.home-map-links-zoom-a, .world-map-links-a').mouseout(function ()
	  {
		  tmp = this.title.replace(/ /gi, "_").toLowerCase();
		  $('#' + tmp).stop().fadeTo('100', 0);
		  $(this).css({ color: "black" });
	  });
	  var lastObj = new Object();
	  var lastLayer = new Object();

	  $('.home-map-links-a, .area_hover').click(function () {
	      if (!this.href.match(/#$/))
	          return true;

	      tmp = this.title.replace(/ /gi, "_").toLowerCase() + "_map";
	      $('#' + tmp).stop().fadeTo('200', 1);
	      lastLayer = document.getElementById('#' + tmp);
	      $('#clearMapsLink').css({ display: "block" });

	      return false;
	  });

	  $('.world-map-links-a').click(function ()
	  {
		  tmp = this.title.replace(/ /gi, "_").toLowerCase() + "_map";
		  $('#' + tmp).stop().fadeTo('200', 1);
		  lastLayer = document.getElementById('#' + tmp);
		  $('#clearMapsLink').css({ display: "block" });

		  return (!this.href.match(/#$/));
	  });

	  $('.home-map-links-zoom-a').click(function ()
	  {
		  return;
	  });

	  $('#video-container').css('z-index', '200');

	  // finish onRequestServed()
  }
  

  //document ready
  $(document).ready(function ()
  {
	  onRequestServed();
  });
  

//EXTRAS FOR WORLD MAP  


//group map functions

function continentGroup () {
  returnString="<img src=\"/images/main/home-map-group/world_europe.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"europe\" />";
  returnString+="<img src=\"/images/main/home-map-group/world_north_america.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"north_america\" />";
  returnString += "<img src=\"/images/main/home-map-group/world_south_america.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"latin_america\" />";
  returnString += "<img src=\"/images/main/home-map-group/world_mena.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"mena\" />";
  returnString+="<img src=\"/images/main/home-map-group/world_africa.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"africa\" />";
  returnString+="<img src=\"/images/main/home-map-group/world_asia.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"asia\" />";
  returnString+="<img src=\"/images/main/home-map-group/dummy.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" style=\"display:block;\" id=\"europe\" usemap=\"#map1\" />";
  return returnString;
}


//orange map functions

function continentOrange () {
  returnString="<img src=\"/images/main/home-map-insurance/world_europe.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"europe\" />";
  returnString+="<img src=\"/images/main/home-map-insurance/world_north_america.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"north_america\" />";
  returnString+="<img src=\"/images/main/home-map-insurance/dummy.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" style=\"display:block;\" id=\"europe\" usemap=\"#map1\" />";
  return returnString;
}

function northAmericaOrange () {
  returnString="<img src=\"/images/main/home-map-insurance/bermuda.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlayZoom\" id=\"bermuda\" />";
  returnString+="<img src=\"/images/main/home-map-insurance/canada.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlayZoom\" id=\"canada\" />";
  returnString+="<img src=\"/images/main/home-map-insurance/us.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlayZoom\" id=\"us\" />";
  returnString+="<img src=\"/images/main/home-map-insurance/dummy.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" style=\"display:block;\" id=\"northamerica\" usemap=\"#map2\" />";
  return returnString;
}

function europeOrange () {
  returnString="<img src=\"/images/main/home-map-insurance/uk.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlayZoom\" id=\"uk\" />";
  returnString+="<img src=\"/images/main/home-map-insurance/ireland.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlayZoom\" id=\"ireland\" />";
  returnString+="<img src=\"/images/main/home-map-insurance/switzerland.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlayZoom\" id=\"switzerland\" />";
  returnString+="<img src=\"/images/main/home-map-insurance/dummy.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" style=\"display:block;\" id=\"europe\" usemap=\"#map3\" />";
  return returnString;		  
}


//end orange map functions


// green map  functions
function continentGreen () {
  returnString="<img src=\"/images/main/home-map-reinsurance/world_europe.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"europe\" />";
  returnString+="<img src=\"/images/main/home-map-reinsurance/world_north_america.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"north_america\" />";
  returnString+="<img src=\"/images/main/home-map-reinsurance/world_south_america.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"south_america\" />";
  returnString+="<img src=\"/images/main/home-map-reinsurance/world_africa.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"africa\" />";
  returnString+="<img src=\"/images/main/home-map-reinsurance/world_asia.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" id=\"asia\" />";
  returnString+="<img src=\"/images/main/home-map-reinsurance/dummy.gif\" width=\"376\" height=\"245\" alt=\"\" class=\"mapOverlay\" style=\"display:block;\" id=\"europe\" usemap=\"#map1\" />";
  return returnString;
}

//end green map functions


function clearMaps(){
  $('.hiddenMaps').fadeOut('fast');
  $('#clearMapsLink').css({display: "none"});
}

// end clear maps



/*=======================   Event Calendar events   ========================*/

function showEventDetails(EventId) {
    $('.events').fadeOut(100);
    $('.' + EventId).fadeIn(200);
}

function hideEventDetails() {
    $('.event').fadeOut(100);
    $('.events').fadeIn(200);
}
