$(document).ready(function() {
  shownzmap();
  var path = location.href;
  var spath = location.href.split( '/' );
  var newURL = location.protocol+"//"+location.host;
  if (spath[3]) { newURL += "/"+spath[3];}
  if (!spath[4]) { newURL += "/"; }
  if (spath[4]) { newURL += "/"+spath[4];}
  if (spath[5]) { newURL += "/"+spath[5]+"/"; }

  $("#submenu ul li a[href='" + [newURL] + "']").parents("li").addClass("active"); 
  $(".pagecontent_left ul li a[href='" + [path] + "']").addClass("active");
  
  $('a.lbimage').lightBox({
   fixedNavigation:true,
   imageLoading: '/resources/images/lightbox-ico-loading.gif',
   imageBtnClose: '/resources/images/lightbox-btn-close.gif',
   imageBtnPrev: '/resources/images/lightbox-btn-prev.gif',
   imageBtnNext: '/resources/images/lightbox-btn-next.gif'});


    $('acronym[title]').qtip({
		style: { 
			background: '#f8f5f0',
			color: '#333333',
      		border: {			
			radius: 0,
			color: '#dddac9'
		}
		}
	});

   $('a#sitetag[rel]').each(function()
   { 
      $(this).qtip(
      {
         content: {       
            text: '<img class="throbber" src="/resources/images/loader.gif" alt="Loading..." />',
            url: $(this).attr('rel'), // Use the rel attribute of each element for the url to load
            title: {
               text:  false, 
               button: 'Close',
			   color: '#FFFFFF'
            }
         },
         position: {
            corner: {
               target: 'bottomMiddle', // Position the tooltip above the link
               tooltip: 'topMiddle'
            },
            adjust: {
               screen: true // Keep the tooltip on-screen at all times
            }
         },
         show: { 
            when: 'click', 
            solo: true // Only show one tooltip at a time
         },
         hide: 'unfocus',
         style: {
			background: 'url(/resources/images/bg50.png) repeat',			
			color: '#FFFFFF',
			tip: true, // Apply a speech bubble tip to the tooltip at the designated tooltip corner
            border: {
               width: 0,
               radius: 0,
			   color: '#333333'
            },
            width: 400 // Set the tooltip width
         }
		
      })
   });
  
	$('a.readmore').click(function() {
		var myid =  $(this).attr("rel");		
		$(this).text($(this).text() == 'Read more about this group' ? 'Hide details' : 'Read more about this group');		
		if ($(this).text() == 'Hide details') {
			$(this).removeClass("readmore");	
			$(this).addClass("arrowUp");
		}
		if ($(this).text() == 'Read more about this group') {
			$(this).removeClass("arrowUp");	
			$(this).addClass("readmore");	
		}
		$("#det_"+myid+"").slideToggle(400);
		return false;
	});
  
});

function clearText(theField) {
   if (theField.defaultValue == theField.value)
   theField.value = '';
}

function addText(theField) {
   if (theField.value == '')
   theField.value = theField .defaultValue;
} 

function shownzmap()
{
   
    $('#newzealandmap area[title]').each(function(){
      $(this).qtip({         
         show: {
            when: { event: 'mouseover' },
            effect: { type: 'grow' }
         },
		 content: {
         text: false
		},

		 style: { 
			background: '#0895d3',
			color: 'white',
      		border: {			
			radius: 2,
			color: '#FFFFFF'
		},
		tip: 'leftMiddle'
		},
         hide: {                               
            fixed: true
         },
         position: {            
			target: 'mouse',
            adjust: {
                  screen: true,
                  scroll: false,
				  mouse:true,
				  y: 15
            }
         },
         api: {
            onHide: function(){
               // Reset the scroll position
               this.elements.content.children('div').css({ scrollTop: 0 });
            }
         },
		hide: { when: 'mouseout', fixed: true }
      })
   });
}  
