// ---------------------------------------------------------------------------------- Is Font Face Supported
	
	//http://paulirish.com/2009/font-face-feature-detection/


	var isFontFaceSupported = (function(){  
	var 
	sheet, doc = document,
	head = doc.head || doc.getElementsByTagName('head')[0] || docElement,
	style = doc.createElement("style"),
	impl = doc.implementation || { hasFeature: function() { return false; } };
	 
	style.type = 'text/css';
	head.insertBefore(style, head.firstChild);
	sheet = style.sheet || style.styleSheet;
	 
	var supportAtRule = impl.hasFeature('CSS2', '') ?
	        function(rule) {
	            if (!(sheet && rule)) return false;
	            var result = false;
	            try {
	                sheet.insertRule(rule, 0);
	                result = !(/unknown/i).test(sheet.cssRules[0].cssText);
	                sheet.deleteRule(sheet.cssRules.length - 1);
	            } catch(e) { }
	            return result;
	        } :
	        function(rule) {
	            if (!(sheet && rule)) return false;
	            sheet.cssText = rule;
	 
	            return sheet.cssText.length !== 0 && !(/unknown/i).test(sheet.cssText) &&
	              sheet.cssText
	                    .replace(/\r+|\n+/g, '')
	                    .indexOf(rule.split(' ')[0]) === 0;
	        };
	 
	return supportAtRule('@font-face { font-family: "font"; src: "font.ttf"; }');
	})()



// ---------------------------------------------------------------------------------- Fixed Content -- make sure it is visible
	
	
	is_mobile_safari = function()
	{
	    if( navigator.userAgent.match( /(iPod|iPhone|iPad)/ ) )
	    {
	        return true
	    }
	    else
	    {
	        return false
	    }
	}
	
	
	
	change_to_static_if_too_small = function(contentContainer, tooSmallClassName)
	{
		viewportheight = window.innerHeight;
		viewportwidth = window.innerWidth;
		
		pageContainerObject = $('#page-container');
		objectToApplyClass = $(contentContainer);
		
		//alert(objectToApplyClass.height());
		//alert($('#page-container').width());
		
		if (viewportheight < objectToApplyClass.height() || viewportwidth < pageContainerObject.width() || is_mobile_safari())
		{
			 objectToApplyClass.addClass(tooSmallClassName);
		}
		else
		{
			objectToApplyClass.removeClass(tooSmallClassName);
		}
	}
	
	make_sure_fixed_content_is_visible = function()
	{
		change_to_static_if_too_small('#related-content', 'too-small');
		change_to_static_if_too_small('#menu-container', 'too-small');
	}
	
	
	$(document).ready(make_sure_fixed_content_is_visible)
	$(window).resize(make_sure_fixed_content_is_visible)
	

// ---------------------------------------------------------------------------------- Hero Wide click function (for search and archive)

	link_all_hero_wide_images = function()
	{
		$('.hero-images-wide li').bind('click', function(field) {
			document.location.href = this.getElementsByTagName('a')[0]
		});
	}
	
	$(document).ready(link_all_hero_wide_images)




	enable_font_face_body_style = function()
	{
		if (!isFontFaceSupported)
		{
			$('body').removeClass('font-face-supported')
		}
	}
	$(document).ready(enable_font_face_body_style)
	


// ---------------------------------------------------------------------------------- Current Menu Item (allows for relative paths instead of absolute required by wordpress menus for current-menu-item class to be applied)

	enable_current_menu_item = function()
	{
		$('#main-menu li').each(function ()
		{
		     if ($(this).find("a").attr("href") == window.location.href.replace(/.*\/\/[^\/]*/, ''))
		     {
		         $(this).addClass("current-menu-item");
		     }
		});
	}
	$(document).ready(enable_current_menu_item)



// ---------------------------------------------------------------------------------- Categories


	enable_see_all_categories = function()
	{
		$('.see-all').each(function(index, element)
		{
			var container = $(this).parent()
			var id = 'see-all-' + index;
		    $(container).attr('id', id)
		    
		    $(this).bind('click', function()
			{	
				height = $("#" + id + " .categories").height()
				
				if ($("#" + id + " .categories-box").height() > 0)
				{
					$("#" + id + " .categories-box").stop().animate({'height': '0'},200);
					$("#" + id + " .see-all a").text('See All Tags')
					$("#" + id + " .see-all a").removeClass('expanded')
				}
				else
				{
					$("#" + id + " .categories-box").stop().animate({'height': height},200);
					$("#" + id + " .see-all a").text('Hide All Tags')
					$("#" + id + " .see-all a").addClass('expanded')
				}
				return false;
			});
		    
		    
		    
		    
		});
		

	}
	
	$(document).ready(enable_see_all_categories)




// ---------------------------------------------------------------------------------- Mail Press Code for Form (AJAX)

	
	
	var mp_form = {
	
		selectors : {
			submit  : 'div.MailPress input.mp_submit', 
			form    : 'form.mp-form', 
			formdiv : 'div.mp-formdiv', 
			loading : 'div.mp-loading', 
			messageIntial : 'div.mp-inital',
			messageSuccess : 'div.mp-message-success',
			messageAlready : 'div.mp-message-alread-subscribed',
			unknownError : 'div.mp-message-error',
			messageValidEmail : 'div.mp-message-valid-email',
			
		}, 
	
		init : function() {
			jQuery(mp_form.selectors.submit).click( function() { mp_form.ajax(jQuery(this).parents('.MailPress')); return false;} );
		}, 
	
		ajax : function(div) {
			var data = {};
			jQuery(mp_form.selectors.form+' [type!=submit]',  div).each(function(){
				data[ jQuery(this).attr('name') ] = jQuery(this).val();
			});
			
			jQuery(mp_form.selectors.messageIntial, div).fadeTo(500,0, callback = function(){mp_form.hide(mp_form.selectors.messageIntial, div)});
			jQuery(mp_form.selectors.formdiv, div).fadeTo(500,0, callback = function(){mp_form.hide(mp_form.selectors.formdiv, div)});
			jQuery(mp_form.selectors.messageValidEmail, div).fadeTo(500,0, callback = function(){mp_form.hide(mp_form.selectors.messageValidEmail, div)});
			
			jQuery(mp_form.selectors.loading, div).css('visibility', 'visible');
		 	jQuery(mp_form.selectors.loading, div).fadeTo(500,1);
	
			//¤ ajax
			jQuery.ajax({
				data: data,
				beforeSend: null,
				type: "POST", 
				url: $('#fin-subscribe-form').attr('action'),
				success: mp_form.callback
				});
		}, 
	
		callback : function(r) {
		 	var mess  = jQuery('message',r).text();
		 	var email = jQuery('email',r).text();
		 	var name  = jQuery('name',r).text();
		 	var id    = jQuery('id',r).text();
			var div   = jQuery('#' + id);
	
			//jQuery(mp_form.selectors.form+' [name=email]',  div).val(email);
			//jQuery(mp_form.selectors.form+' [name=name]',  div).val(name);
	
			var loadForm = false;
			if (mess.indexOf('Waiting for your confirmation') >= 0)
			{
				messageDiv = mp_form.selectors.messageSuccess
			}
			else if (mess.indexOf('You have already subscribed') >= 0)
			{
				messageDiv = mp_form.selectors.messageAlready
			}
			else if (mess.indexOf('Enter a valid email !') >= 0)
			{
				messageDiv = mp_form.selectors.messageValidEmail
				loadForm = true;
				$("#email-address").addClass('errors')
			}
			else
			{
				messageDiv = mp_form.selectors.unknownError
			}
	
		 	jQuery(mp_form.selectors.loading, div).fadeTo(500,0, callback = function(){mp_form.hide(mp_form.selectors.loading, div)});
		 	jQuery(messageDiv, div).css('visibility', 'visible');
			jQuery(messageDiv, div).fadeTo(1000,1);

			if (loadForm)
			{
				jQuery(mp_form.selectors.formdiv, div).css('visibility', 'visible');
				jQuery(mp_form.selectors.formdiv, div).fadeTo(1000,1);
			}

			//jQuery(messageDiv, div).append(mess);
			

			
			

	
		 	
		},
		
		hide: function(selector, div) {
			jQuery(selector, div).css('visibility', 'hidden');
		}

	}
	jQuery(document).ready( function() { mp_form.init(); } );



// ------------------------------------------------------------------------

	var set_min_height = function()
	{
		bodyHeight = $('body').height()
		$('#page-content').css('min-height', bodyHeight - 40);
	}

	$(document).ready(set_min_height)
	$(window).resize(set_min_height)




