/* RESEN */
/* Javascript Functions
----------------------------------------------------------------------------- */


	$(document).ready(function() {
	
	//	$('#page-index #news ul.content > li:nth-child(3), #page-index #news ul.content > li:nth-child(4)').addClass('small');

		Cufon.replace('h4, #blurbs div.body', {
		    hover: true,
		    hoverables: { h4: true }
		});
		$('h4').css('visibility', 'visible');
				
		language();
		actions();
		replaceSubmitButtons();
		
		if ($('#hidesidebar').length > 0) $('#sidebar').hide();
		
	});
	
	$(window).load(function() {

		slideshows();
		services();
		if (section == "material") fileIcons();
		alerts();
		$('body').removeClass('loading');
		
	});
		

/* FUNCTION: LINK BEHAVIORS
----------------------------------------------------------------------------- */

	
	function actions() {

		
/* Back Link */


		$('a[href=#back]').click(function() {
		
			history.go(-1);
			return false;
		
		});
		
		
/* Social Bookmarks */
			

		if ($('ul.share').length > 0) {
		
			var itemTitle = $('ul.share').parent().children('h4').text();
		
			$('ul.share .facebook a').attr('href', 'http://www.facebook.com/sharer.php?u=' + location.href);
			$('ul.share .delicious a').attr('href', 'http://del.icio.us/post?v=4&noui&jump=close&url=' + location.href + '&title=' + itemTitle);
			$('ul.share .stumbleupon a').attr('href', 'http://www.stumbleupon.com/submit?url=' + location.href + '&title=' + itemTitle);
			$('ul.share .digg a').attr('href', 'http://digg.com/submit?phase=2&url=' + location.href + '&title=' + itemTitle);

		}
	
	}

	
/* FUNCTION: REPLACE SUBMIT BUTTONS
----------------------------------------------------------------------------- */


	function replaceSubmitButtons() {
	
	
/* Replace Buttons */

	
		$('input[type=submit]').each(function() {
					
			var language = $(this).attr('value');
			$(this).parent().addClass('submit');
			$(this).after('<a class="action submit" href="#submit">' + language + '</a>');

		});
		

/* Button Click */

	
		$('a.submit').click(function() {

			$(this).parents('form').submit();
			return false;
			
		});
	
		
/* Form Submit */


		$('form').submit(function() {
			
			if ($(this).attr('action').match('actions')) {
			
				var action = window.location.href.replace(window.location.protocol + "//" + window.location.hostname, '');
				$(this).attr('action', action);
				
			}
			
		});
	
	
	}
	
	
/* FUNCTION: ALERT
----------------------------------------------------------------------------- */


	function alerts() {
	
		$('div.alert').each(function() {
		
			$(this).prependTo('body').slideDown('fast');
		
		});
		
		$('div.alert').click(function() {
		
			$(this).slideUp('fast');
		
		});
			
	}
	
	
/* FUNCTION: SLIDESHOWS
----------------------------------------------------------------------------- */


	function slideshows() {
	
	
/* Header Image */


		if ($('#headerimage ul.content').length > 0) {
		
			$('#headerimage ul.content').cycle({
				fx: 'fade',
				speed: 900, 
				timeout: 5000,
				random: 1
			});
			
			$('#headerimage').fadeIn('slow');
		
		}


/* Blurbs */


		if ($('#blurbs ul.content').length > 0) {

			$('#blurbs ul.content').cycle({
				fx: 'fade',
				speed: 900, 
				timeout: 12000,
				random: 1
			});
			
			$('#blurbs').fadeIn('slow');
		
		}

	}
	
	
/* FUNCTION: SERVICES
----------------------------------------------------------------------------- */


	function services() {
	
		$('#services h4').click(function() {
		
			$('#services h4').removeClass('selected');
			$(this).addClass('selected');
			Cufon.replace('#services h4');
		
			var $info = $('#main > #info');
			var heading = $(this).text();
			var copy = $(this).siblings('div.body').html();
				
			$info.animate({
			
				'height': 'toggle',
				'opacity': 'toggle'
			
			}, 200, function() {
			
				$info.children('h4').text(heading);
				Cufon.replace('#info h4');
				$info.children('.body').html(copy);
				$info.animate({
				
					'height': 'toggle',
					'opacity': 'toggle'
				
				}, 200);
			
			});
			
		});
	
	}
	
	
/* FUNCTION: FILE ICONS
----------------------------------------------------------------------------- */

	
	function fileIcons() {
	
		// IMAGES
		$('#material a[href$=pdf] img').attr('src', '/images/icons/icon-image.png');
		$('#material a[href$=ai] img').attr('src', '/images/icons/icon-ai.png');
		$('#material a[href$=eps] img').attr('src', '/images/icons/icon-image.png');
		$('#material a[href$=tif] img').attr('src', '/images/icons/icon-image.png');
		$('#material a[href$=bmp] img').attr('src', '/images/icons/icon-image.png');
		$('#material a[href$=jpg] img').attr('src', '/images/icons/icon-image.png');
		$('#material a[href$=jpeg] img').attr('src', '/images/icons/icon-image.png');
		$('#material a[href$=gif] img').attr('src', '/images/icons/icon-image.png');
		$('#material a[href$=png] img').attr('src', '/images/icons/icon-image.png');

		// VIDEOS
		$('#material a[href$=fla] img').attr('src', '/images/icons/icon-fla.png');
		$('#material a[href$=flv] img').attr('src', '/images/icons/icon-flv.png');
		$('#material a[href$=swf] img').attr('src', '/images/icons/icon-swf.png');
		$('#material a[href$=mov] img').attr('src', '/images/icons/icon-video.png');
		$('#material a[href$=mpg] img').attr('src', '/images/icons/icon-video.png');
	
		// DOCUMENTS
		$('#material a[href$=doc] img, a[href$=docx] img').attr('src', '/images/icons/icon-doc.png');
		$('#material a[href$=xls] img, a[href$=xlsx] img').attr('src', '/images/icons/icon-xls.png');
		
		// ARCHIVES
		$('#material a[href$=zip] img').attr('src', '/images/icons/icon-zip.png');

	}