$(document).ready(function(){
	$('#slides').cycle({ 
		fx:     'fade', 
		speed:  '600', 
		timeout:  '7000',
		pause: 1,
		pauseOnPagerHover: 1,
		pager:  '#slide-thumbs',
		pagerEvent: "mouseover",
		pagerAnchorBuilder: function(index, slide) {  
			return '#slide-thumbs li:eq(' + index + ') a'; 
		} 
	});
	$('#slide-thumbs a').click(function () { window.location = $(this).attr("href"); });

	//Link icons___________________________________________
	$(function() {
		// Customize variables for your site
		// External link icon image
		var external = '<img src="http://giving.missouri.edu/images/icons/external.png" alt="external link" title="external link" class="external-icon" width="12" height="11"/>';
		// Email link icon image
		var email = ' <img src="http://giving.missouri.edu/images/icons/email.png" alt="email link" title="email link" class="inline-icon" width="16" height="16"/>';
		// Each file type image
		var file_types = {
			pdf: '<img src="http://giving.missouri.edu/images/icons/pdf.png" alt="PDF link" title="PDF link" class="inline-icon" width="16" height="16"/>',
			doc: '<img src="http://giving.missouri.edu/images/icons/doc.png" alt="Word document link" title="Word document link" class="inline-icon" width="16" height="16"/>',
			docx: '<img src="http://giving.missouri.edu/images/icons/doc.png" alt="Word document link" title="Word document link" class="inline-icon" width="16" height="16"/>',
			xls: '<img src="http://giving.missouri.edu/images/icons/xls.png" alt="Excel document link" title="Excel document link" class="inline-icon" width="16" height="16"/>',
			xlsx: '<img src="http://giving.missouri.edu/images/icons/xls.png" alt="Excel document link" title="Excel document link" class="inline-icon" width="16" height="16"/>',
			ppt: '<img src="http://giving.missouri.edu/images/icons/pp.png" alt="PowerPoint document link" title="PowerPoint document link" class="inline-icon" width="16" height="16"/>',
			pptx: '<img src="http://giving.missouri.edu/images/icons/pp.png" alt="PowerPoint document link" title="PowerPoint document link" class="inline-icon" width="16" height="16"/>'
		};
		// If anchor has this class, it will not add icon
		var no_icon = 'no-icon'

		// Add this class to each element you'd like the icons to appear in
		var container = '.ex-icons'
		
	 	// Select each anchor that doesn't contain an image or have the no_icon class
		$(container + ' ' + 'a:not(:has(img))a:not(.' + no_icon + ')').each(function() {
	 
			var $a = $(this);
			var link_class = $a.attr('class');
			var href = $a.attr('href');
			var href_array = href.split('.');
			var extension = href_array[href_array.length - 1];
			var image = file_types[extension];
	 		 		
			// If an extenal link, insert icon inside the anchor tag
			if (this.hostname && this.hostname !== location.hostname){
				$a.append(external);
			}
			// If the href is an email link insert icon after the anchor tag
			if (href.match(/^mailto:/)){
				$a.append(email);
			}
			// If the href extension matches one in the file_types array insert icon after the anchor tag
			if (image){
				$a.before(image);
			}
		});
	});

});
