$(document).ready(function () {
							
	// homepage rotating banner images					   
	$('#herobanner').before('<div id="nav">').cycle({
			fx: 'fade',
			speed: 900,
			timeout: 6000,
			pager: '#nav'
		});

//  add icons to links
	// Add pdf icons to pdf links
	$("a[href$='.pdf']").addClass("pdf");
	// Add Word icons to word links (doc, rtf, txt)
	$("a[href$='.doc'], a[href$='.docx']").addClass("doc");
	// Add Excel icons to Excel links (xls, xlsx)
	$("a[href$='.xls'], a[href$='.xlsx']").addClass("excel");
	// Add txt icons to document links (doc, rtf, txt)
	$("a[href$='.txt'], a[href$='.rtf']").addClass("txt");
	// Add zip icons to Zip file links (zip, rar)
	$("a[href$='.zip'], a[href$='.rar']").addClass("zip"); 
	// Add email icons to email links
	$("a[href^='mailto:']").addClass("email");
	//Add external link icon to external links - 
	//$('a').filter(function () {
		//Compare the anchor tag's host name with location's host name
	  //  return this.hostname && this.hostname !== location.hostname;
	  //}).addClass("external");
	//You might also want to set the _target attribute to blank
	//$('a').filter(function () {
		//Compare the anchor tag's host name with location's host name
	//   return this.hostname && this.hostname !== location.hostname;
	// }).addClass("external").attr("target", "_blank");

	$('a.popup').bind('click', function (e) {
		popwindow(e);
	});

	function popwindow(e) {
		e.preventDefault();
		var href = $(e.target).attr('href');
		window.open(href, '', 'width=800,height=700,scrollbars=yes,toolbar=no,status=no,directories=no');
	}
	
	/* Lightbox plugin
	
		The following code looks for an anchor with a rel attribute to bind to
		to activate a lightbox
		
		slideshow: all elements must have the same rel attribute to be part of the slideshow
	*/
	
	$("a[rel='map']").colorbox({transition: "fade"});
	$("a[rel='chart']").colorbox({transition: "fade"});
	$("a[rel='gallery']").colorbox({slideshow: true, transition: "fade", slideshowAuto: false});

// form validation
	$("#contact, #subscribe").validate({
		rules: {
			Email: {
				required: true,
				email: true
			}
		},
		messages: {
			Email: {
				required: "Please enter your email address",
				email: "Your email address must be in the format of name@domain.com"
			}
		}
	});

//	Hack to stop Vignette ICE pencils from breaking the layout
    var editOn = $('div[id^="topId"]');
	//	Check if ice editing is on
    if (editOn.length !== 0) {
   //	If it is, move the banner before the pencils
		$('#banner-container').insertBefore('#VC-mainContent').css('left','0');
    };
	
	// add the banner to the news templates
	var aa = $('#VC-article');
		al = $('#VC-articleList');
		bb = $('.banner');
		bc = $('#banner-container');
	//Check if it's a news item or news list page and that there are no banners already on the page
	if (aa.length < 0 || al.length  < 0 && bb.length == 0 && bc.length == 0) {
		//if it is add the news banner 
		$('#VC-pageBody').append('<div id="news" class="banner"/>');
	}
});

