// JavaScript Document
Cufon.replace('.style1', {
	color: '-linear-gradient(#3b0307, #9d0d16, #9d0d16, #3b0307)',
	fontFamily: 'ITCAmericanTypewriter',
	hover:true
});
Cufon.replace('.style1 span', {
	color: '-linear-gradient(#243552, #1c2940, #1c2940, #243552)',//'#1c285a',//'-linear-gradient(#3b0307, #9d0d16, #9d0d16, #3b0307)',
	fontFamily: 'ITCAmericanTypewriter',
	hover:true
});

Cufon.replace('label.style2, .field-text.style2', {
	fontFamily: 'ITCAmericanTypewriter',
	hover:true
});

Cufon.replace('#context-menu li a, li.title, .brands li a, .product-menu-title, .tabs a', {
	fontFamily: 'ArtBrush',
	textShadow: '#999999 1px 1px',
	hover: true
});

Cufon.replace('.font2, .artbrush, .footnote, .gallerysearch, .block-button-wide, .block-button, #good-housekeeping h2.artbrush', {
	fontFamily: 'ArtBrush',
	hover: true
});

Cufon.replace('h2.style2, h3.style2', {
	color: '-linear-gradient(#3b0307, #1a1818, #1a1818, #3b0307)',
	fontFamily: 'ITCAmericanTypewriter'
});

Cufon.replace('h3.style4', {
	color: '-linear-gradient(#ffffff, #ffffff, #ffffff, #ffffff)',
	fontFamily: 'ITCAmericanTypewriter'
});

Cufon.replace('h2.style3', {
	color: '-linear-gradient(#243552, #1c2940, #1c2940, #243552)',
	fontFamily: 'ITCAmericanTypewriter'
});

Cufon.replace('.flyout ul li a, #home_box h2', {
	fontFamily: 'ITCAmericanTypewriter',
	hover:true
});

// <=IE6 check
var isIE8OrLower = ($.browser.msie && ($.browser.version.substr(0,2)=='8.' || $.browser.version.substr(0,2)=='7.' || $.browser.version.substr(0,2)=='6.' || $.browser.version.substr(0,2)=='5.'));

var isIE6OrLower = ($.browser.msie && ($.browser.version.substr(0,2)=='6.' || $.browser.version.substr(0,2)=='5.'));

// This is where all the base js script stuff happens.

$(document).ready(function(){

	// If the ticker is on the page
	if ( $("ul#ticker").length ) {
		$(function(){
			$("ul#ticker").liScroll();
		});
	}
	
	// initialise ajax forms
   	$('.ajaxForm').ajaxForm();
	
	// If the newletter form is on the page
	if ( $("#signup-input").length ) {
	
		$('#signup-input').mouseover(function() {
			$('#signup-input').switchClass( 'search-colour', 'search-alt-colour', 300 );
		});
		
		$('#signup-input').mouseout(function() {
			$('#signup-input').switchClass( 'search-alt-colour', 'search-colour', 300 );
		});
	}
	
	$(' #name, #uiulir-uiulir, #s-keywords, #recipe-description, #ingredients, #preparation-time, #cooking-time').defaultValue();

	
	// Load up the default location, if we are on the the TTF page
	if ( $("#ttf-content-group").length ) {
		$.get("/oat_so_simple/track_the_fleet/london",function(data){ $("#ttf-content-group").html(data);});
	}
	
	// assign menu rollovers for graceful fades
	
	$('.flyout li.nav').hover(function(){
			$('span',this).addClass('active').find('ul').stop(false,true).fadeIn(300);
			//$('span',this).addClass('active').find('ul').show('drop',{direction: "down"},300);
		},function(){
			$('span',this).removeClass('active').find('ul').stop(false,true).fadeOut(300);
			//$('span',this).removeClass('active').find('ul').hide('drop',{direction: "down"},300);
	});
	
	// show tooltips on a.tooltip
	if( isIE8OrLower ){
		$('a.tooltip-link').tooltip();
	}else{
		$('a.tooltip-link').tooltip({ effect: 'fade'});
	}
	 
	 
	 //masthead signup handler
	 $('#newsletter-form').submit(function(){
	 
	$('#newsletter-form .message').fadeOut(50, function() {
		$(this).remove();
	});
	
	$(this).fadeTo('slow', 0.5);
	
		var fields = $(this).serializeArray();
		$.post('/info/ajax_signup/',
			   fields,
			   function(data){
					
				$this = $("#newsletter-form");
				
				   if( data == '0' ){
					   //success
					   $("#newsletter-form").fadeTo('fast', 1);
					   $("#newsletter-form").empty();
					   $('#newsletter-form').prepend("<p class='message success-message'>Thank you, we will send you Quaker offers, news and recipes shortly!</p>");
				   }else if( data == '1' ){
					   //invalid email
					   $("#newsletter-form").fadeTo('fast', 1);
					   $('#newsletter-form').prepend("<p class='message error-message'>Invalid email</p>");
				   }else{
					   $("#newsletter-form").fadeTo('fast', 1);
					   $('#newsletter-form').prepend("<p class='message error-message'>Error, please try again</p>");
				   }
				   Cufon.refresh();
		});

		return false;
	 });
	 
	 /*$('.flyout a[href$="' + window.location.pathname + '"]').closest('li').addClass('current');*/
	 
	///////////////////////////////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////////////
	// limit textarea fields
	
	var onEditCallback = function(remaining){
		var id = $(this).attr('id');
		$('#charsRemaining_'+id).text("(Remaining: " + remaining + " chars)");
		if(remaining > 0){
			$(this).removeClass('character-limit-not-reached');
		}
	}

	var onLimitCallback = function(){
		$(this).addClass('character-limit-reached');
	}
	
	if(typeof $('textarea[maxlength]').limitMaxlength != 'undefined'){
		$('textarea[maxlength]').limitMaxlength({
			onEdit: onEditCallback,
			onLimit: onLimitCallback
		});
	}
	
	// END limit textarea fields
	///////////////////////////////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////////////
	 
});

function showSignupForm(){
	$('#masthead-signup-link a').text('');
	$('#masthead-signup-form').fadeIn();
	$('#signup-input').focus();
}

function hideSignupForm(){
	$('#masthead-signup-link a').text('Sign up for our Newsletter');
	Cufon.refresh();
	$('#masthead-signup-form').fadeOut();
}

function showFormResponse(response,popupOptions,form)
{
	var popupOptions = typeof(popupOptions)=='undefined' ? {} : popupOptions;
	var message = '';
	if( typeof( response['title'] ) != 'undefined' ) message+=('<h2>'+response['title']+'</h2>');
	if( typeof( response['subheading'] ) != 'undefined' ) message+=('<h3>'+response['subheading']+'</h3>');
	if( typeof( response['message'] ) != 'undefined' ) message+=('<p>'+response['message']+'</p>');
	if( typeof( response['extra'] ) != 'undefined' ) message+=(response['extra']);
	if( typeof( response['errors'] ) != 'undefined' ) message+=('<ul class="errors">'+response['errors']+'</ul>');
	
	// re-show form link
	if(typeof(response.showFormLink) != 'undefined' && response.showFormLink == true)
	{
		var showFormLinkLabel = typeof(response.showFormLinkLabel) != 'undefined' ? response.showFormLinkLabel : 'Show form again';
		message+=('<p><a class="reShowFormLink" href="javascript:void(null);" onclick="javascript:$(\'#'+$(form).attr('id')+'\').show(0);$(\'#fancybox-content .formResponse\').hide(0)">'+showFormLinkLabel+'</a></p>');
	}
	
	// use either popup or inline, depending if popup is already open
	var popupIsOpen = $('#fancybox-wrap').is(':visible');
	
	if( message!='' ){
		if(popupIsOpen && $('#fancybox-content .formResponse').length > 0){	
			$('#fancybox-content .formResponse').addClass(response['type']).html(message).show();
		}else if(!popupIsOpen){
			popup(message,popupOptions);	
		}else{
			message= '';
			if( typeof( response['title'] ) != 'undefined' ) message+=(''+response['title']+"\n");
			if( typeof( response['subheading'] ) != 'undefined' ) message+=(response['subheading']+"\n");
			if( typeof( response['message'] ) != 'undefined' ) message+=("\n"+response['message']+"\n");
			if( typeof( response['extra'] ) != 'undefined' ) message+=(response['extra']);
			if( typeof( response['errors'] ) != 'undefined' ) message+=("\n"+response['errors'].replace(/(<([^>]+)>)/ig,""));
			alert(message);
		}
	}
					
	// hide form					
	if( typeof( response.hideForm ) != "undefined" && response.hideForm ){
		$(form).hide(0);
	}
	
	// clear form
	if(typeof(response.clearform) != 'undefined' && response.clearform == true)
	{
		form.reset();
	}
}





(function(c){c.fn.extend({defaultValue:function(e){if("placeholder"in document.createElement("input"))return!1;return this.each(function(){if(c(this).data("defaultValued"))return!1;var a=c(this),h=a.attr("placeholder"),f={input:a};a.data("defaultValued",!0);var d=function(){var b;if(a.context.nodeName.toLowerCase()=="input")b=c("<input />").attr({type:"text"});else if(a.context.nodeName.toLowerCase()=="textarea")b=c("<textarea />");else throw"DefaultValue only works with input and textareas";b.attr({value:h,
	"class":a.attr("class")+" empty",size:a.attr("size"),style:a.attr("style"),tabindex:a.attr("tabindex"),rows:a.attr("rows"),cols:a.attr("cols"),name:"defaultvalue-clone-"+((1+(new Date()).getTime())*65536|0).toString(16).substring(1)});b.focus(function(){b.hide();a.show();setTimeout(function(){a.focus()},1)});return b}();f.clone=d;d.insertAfter(a);var g=function(){a.val().length<=0?(d.show(),a.hide()):(d.hide(),a.show().trigger("click"))};a.bind("blur",g);g();e&&e(f)})}})})(jQuery);


