//init cufon font replacement
Cufon.replace('h2')('h3')('h4', {hover: true})('h5')('h6')('p.toptext', {hover: true});

$(document).ready(function() {
	
	//remove default value of search form on focus
	$('#s').each(function() {
		var s = $(this);
		s.focus(function() {
			if (s.val() == 'search...') {
				s.val('');	
			}
			s.css('color','#444444');
		});
		s.blur(function() {
			if (s.val() == '') {
				s.css('color','#959595').val('search...');
			}
		});
	});
									
	//add loading div for twitter updates
	$('#latest_tweet').html('<div class="loading">&nbsp;</div>');
	
	// Disable caching of AJAX responses
	$.ajaxSetup ({
		cache: false
	});

	//load quote via ajax
	if ($('#display_quote').length > 0) {
		$('#display_quote').load('/wordpress/wp-content/themes/Sentiment_Theme_v2.1/includes/get_quote.php', function () {
			Cufon.replace('blockquote');
		});
	}
	
	$('#slider').cycle({
		timeout: 5000,
		speed: 2000
	});
	
	//newsletter modal dialog box
	
	//add overlay to DOM
	$('body').append('<div id="overlay"></div>');

	//add modal box to DOM
	$('body').append('<div id="dialogwrapper"><div id="modal"><div id="modaltop"></div><div id="modalcontent"><a id="closeicon" href="#" class="closelink"><img src="/wordpress/wp-content/themes/Sentiment_Theme_v2.1/images/close-icon.png" alt="" /></a><h3>Newsletter</h3><p>Please enter your name and email address to sign up for our newsletter. You can <a href="http://www.sentiment.co.uk/newsletter/unsubscribe">unsubscribe</a> at any time.</p><form action="http://carronmedia.createsend.com/t/r/s/hihuur/" method="post" id="subForm"><div><label for="name">Name:</label><input type="text" name="cm-name" id="name" /></div><div><label for="hihuur-hihuur">Email:</label><input type="text" name="cm-hihuur-hihuur" id="hihuur-hihuur" /></div><div id="newssubmitwrapper"><input id="newslettersubmit" type="submit" value="Subscribe" /></div></form><a id="closelinkbottom" href="#" class="closelink">Close window</a></div><div id="modalbottom"></div></div></div>');
	
	//modal box
	$('#newsletter').click(function(e) { 
											  
		Cufon.replace('h3');

		var overlay = $('#overlay');
		var target = $('#dialogwrapper');  
		var maskHeight = $(document).height();  
		var maskWidth = $(window).width();  

		overlay.css({'width':maskWidth+'px','height':maskHeight+'px', 'opacity':0.8}).fadeIn(500);    

		var winH = $(window).height(); 
		var winW = $(window).width();  

		target.css({'top':winH/2-target.height()/2+'px','left': winW/2-target.width()/2+'px'}).fadeIn(500);   
		
		return false;
	});  

	$('.closelink, #overlay').click(function (e) {  
		$('#overlay, #dialogwrapper').fadeOut(300); 
		return false;
	});
	
	//change form input field style on focus
	$('input[type="text"],textarea').focus(function() {
		$(this).addClass("focusField");
	});
	$('input[type="text"],textarea').blur(function() {
		$(this).removeClass("focusField");
	});

	
});

