$(function () {
	$.sifr({path:'/wp-content/themes/CMF2009-ES/scripts/sIFR', font:'Graublau Web Bold', save:true});
	$('#content h2').sifr({
						    flashvars: {
							linkcolor: '#000', // this would overwrite the link color
							emcolor: '#333222' // for styling elements in multi-color sIFR fonts
							}
					});
	$('#content_area.page h3').sifr({color:'#990000'});
	$('#content h2.red').sifr({color:'#990000'});
	$('#content h2, .blog h1').sifr({color:'#211D00'});
	$('.error #content h2').sifr({color:'#990000'});
	$('.post h1').sifr({color:'#990000'});
	$('.page #sidebar h4, .home #sidebar h4').sifr({color:'#990000'});
	$('#assistance h3').sifr({color:'#ffffff'});
});

$(document).ready(function(){

// Hides the accessibility panel, and shows it on button click
$('body').css({margin:"-100px 0px 0px"});
$("#btn_access").toggle(
  function () {
	$('body').animate({margin:"0px"}, "slow");
  },
  function () {
	$('body').animate({margin:"-100px 0px 0px 0px"}, "slow");
  }
);

// Provides enhancement on the Skip to content, making it useful for non-disabled visitors as well
$('#btn_skip').click(function(){
 var target = $('#sidebar');
 $.scrollTo( target, 800 );
});

// Creates the improved readability js options
$('#accessibility_tools').append('<h4>Improve readability</h4><ul id="screen_options"><li><a id="normal_readability" title="Click to view the usual website design">Normal size / Normal contrast</a></li><li><a id="improved_readability" title="Click to view the enlarged design">Larger fonts / Higher contrast</a></li></ul>');

// Stores chosen options on cookie
$('a#normal_readability').click(function() {
$(this).addClass('selected');
$('a#improved_readability').removeClass('selected');
$.cookie('accessibility', null);
$('body').removeClass('accessible');
});

$('a#improved_readability').click(function() {
$(this).addClass('selected');
$('a#normal_readability').removeClass('selected');
$.cookie('accessibility', 'improved', { expires: 7 });
$('body').addClass('accessible');
});

var accessibility = $.cookie('accessibility');

if (accessibility == 'improved') {
$('body').addClass('accessible');
}


// Handles the team profiles
$('#profiles dd').hide();
$("#profiles dt").click(function(){
	$(this).next("dd").slideToggle("slow").siblings("dd:visible").slideUp("slow");
	$(this).toggleClass("active");
	$(this).siblings("dt").removeClass("active");
});

$('.nav_main li a').mouseover(function() {
 $(this).parent().addClass('bubble');
}).mouseout(function() {
 $(this).parent().removeClass('bubble');			
});

var url = window.location.href; 
// Home Parallax
if (url == 'http://www.creativemediafarm.com/') {
$('.home #main_img').replaceWith('<div id="parallax" style="background:url(/wp-content/themes/CMF2009-ES/images/home/homebg.jpg) no-repeat bottom">' + 
'<img src="/wp-content/themes/CMF2009-ES/images/home/compost1.png" width="875" height="330" />' +
'<img src="/wp-content/themes/CMF2009-ES/images/home/compost2.png" width="900" height="330" />' +
'<img src="/wp-content/themes/CMF2009-ES/images/home/compost3.png" width="500" height="250" />' +
'</div>');
$('.home #parallax').jparallax();
} 

if (url == 'http://www.creativemediafarm.com/our-work/mailchimp-email-marketing') {
// Mailchimp Parallax
$('.page-7 img:first').replaceWith('<div id="parallax">' + 
'<img src="/wp-content/themes/CMF2009-ES/images/chimp/jungle2.png" width="900" height="396" />' +
'<img src="/wp-content/themes/CMF2009-ES/images/chimp/jungle5.png" width="650" height="331"/>' +
'<img src="/wp-content/themes/CMF2009-ES/images/chimp/jungle4.png" width="864" height="380"/>' +
'</div>' +
'<p id="catchy_phrase">Get your company into the web jungle!</p>');
$('.page-7 #parallax').jparallax({}, {}, {xtravel:'850px', yparallax:false});
$(".quote").hide();
$('.page-7 #content h4').css("cursor","pointer").click(function () {
$(".quote").slideToggle("slow");
});	
}

});	

// REFERRAL SCRIPT
// Define Referrerers
var msgs = [
{'url':/^http:\/\/(\w+\.)?mailchimp\.com/,      'msg':'Welcome googler, Hope you will find what you looking for'}
,{'url':/^http:\/\/jungle\.mailchimp\.com/,         'msg':'Welcome fellow dzone reader, if you like it please vote it up'}
,{'url':/^http:\/\/ning\.mailchimp\.com/,         'msg':'Welcome digger, if you like it please digg it'}
];


// Find Referral
function DetectReferrer(){
   var ref = document.referrer.toLowerCase();   
   var msg = findMatch(ref);
   // if not null msg found
   if(msg) {
				$.cookie('referral', 'chimp', { expires: 7 });
      }
   } 

// Compare to array
function findMatch(ref) {
   for(var i=0; i<msgs.length; i++)
      if( ( ref=='' && msgs[i].url==null) || (ref>'' && ref.match(msgs[i].url) ) )
         return msgs[i].msg;
   return null;
}

$(document).ready(function(){
$(DetectReferrer);
var referral = $.cookie('referral');
if (referral == 'chimp') {
	$('.page-7 #content h2:first').after("<div class='announce'><h5>Fresh from the farm!</h5>" +
																				"<p>We like to take special care for our Mailchimp visitors. Enter the code <strong>\"CHIMPZILLA\"</strong> into the quote request form below and get a 15% discount on all our Mailchimp related services. We\'ve gone bananas!</p></div>");
$('.page-17 form').before("<div class='announce'><h5>Fresh from the farm!</h5>" +
																				"<p>We like to take special care for our Mailchimp visitors. Enter the code <strong>\"CHIMPZILLA\"</strong> into the quote request form below and get a 15% discount on all our Mailchimp related services. We\'ve gone bananas!</p></div>");	
  //$.sifr({path:'/wp-content/themes/CMF2009-ES/scripts/sIFR', font:'Graublau Web Bold', save:true});	
	$('div.announce h5').sifr({color:'#000000'});
}

$('.page-17 form fieldset.cf-fs3').hide();	

var service = $('.page-17 fieldset.cf-fs2 option[value=Looking for a Mailchimp Expert]').attr("selected");

$(".page-17 fieldset.cf-fs2 select").change( function() {
var service = $('fieldset.cf-fs2 option[selected]').attr("value");
if (service == "Looking for a Mailchimp Expert") {
$('.page-17 form fieldset.cf-fs3').fadeIn();
} else {
$('.page-17 form fieldset.cf-fs3').fadeOut();
}

});


});	

