// Twitter settings
var twitterUsername = 'sabrewebdesign'; 	// Your Twitter username
var tweetCount = 2; 						// How many Tweets to display

// Cufon settings
if (typeof(Cufon) != 'undefined') {
	Cufon.replace('h1')('h2')('h3');											// Every h1 h2 h3
	Cufon.replace('.footer-header h1', {										// Footer header h1
		color: '-linear-gradient(#fcfcfc, #e7e7e7, rgb(0, 0, 0))',
		textShadow: '#000000 2px 2px 0px'
	});
	Cufon.replace('.stick-out-text h1', {										// Homepage stick out text h1
		color: '-linear-gradient(#f9f9f9, #eeeeee, rgb(0, 0, 0))',
		textShadow: '#000000 -1px -1px 0px'
	});
	Cufon.replace('.sub-page-header h1, .page-header h1', {						// Page header h1
		color: '-linear-gradient(#f9f9f9, #ffffff, #e1e1e1,  rgb(0, 0, 0))',
		textShadow: '#000000 1px 1px 0px'
	});
	Cufon.replace('.nav-outer ul li a', {hover: true});							// Navigation
}

$(window).load(function() {
	// Start the homepage slider
	if ($.fn.nivoSlider) {
		$('#slider').nivoSlider({
			controlNav: false
		});
	}
	
	// Get the Twitter feed
	if (twitterUsername) {
		(function() {
			var b = document.createElement('script'); b.type = 'text/javascript'; b.src = 'js/twitter.js'; b.defer = 'defer';
			var t = document.createElement('script'); t.type = 'text/javascript'; t.src = 'http://twitter.com/statuses/user_timeline/' + twitterUsername + '.json?callback=twitterCallback2&count=' + tweetCount; t.defer = 'defer';
			var h = document.getElementsByTagName('head')[0]; h.appendChild(b); h.appendChild(t);
		})();
	}
});


$(document).ready(function() {	
	// Hide homepage content
	$('#homepage-content-wrap').hide().addClass('hc-hidden');
	$('#homepage-content-toggle').click(function() {		
		var contentWrapper = $('#homepage-content-wrap');
		if (contentWrapper.hasClass('hc-hidden')) {
			contentWrapper.slideDown('slow').removeClass('hc-hidden');
		} else {
			contentWrapper.slideUp().addClass('hc-hidden');
		}
	});
	
	// Testimonial fader
	$('#testimonial-wrapper').loopedFader({
		fadeInSpeed: 1500,
		fadeOutSpeed: 1500,
		waitTime: 4000,
		slide: '.testimonial'
	});
    
	// Gallery tabs
	if ($.fn.tabs) {
		$tabs = $('#galleryTabs').tabs();
	}
	
	// Colorbox on gallery
	if ($.fn.colorbox) {
		$('a[rel^="gallery"]').colorbox({
			transition: 'fade'
		});
	}
	
	// Clear the contact form elements on click
	$('.form-element').focus(function() {
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
		}
	});
	
	// Bind the ajax contact form
	$('#contact-form').live('submit', function(event) {
		// Prevent the browser submitting the form normally
		event.preventDefault();
		// Bind the form submit to use the ajax form plugin
		$(this).ajaxSubmit({
			url: 'contact-form.php',
			dataType: 'json',
			success: function(response) {
				// Check if the form submission was successful
				if (response.type == 'success') {
					// Fade out the form
					$('#contact-form-container').fadeOut('slow', function() {
						// Then fade in the success message
						$('#contact-form-message').hide().html('<p>' + response.data + '</p>').fadeIn('slow');
					});
				} else if (response.type == 'error') {
					// Remove any previous errors from the DOM
					$('.form-errors').remove();
					// Go through each element containing errors
					$.each(response.data, function(index, element) {
						// Save a reference to this element
						$element = $('#' + index, '#contact-form-container');
						// If the returned element exists
						if ($element.size()) {
							$element.val(element.value);
							if (element.errors != undefined && element.errors.length > 0) {
								// Create a blank error list
								var $errorList = $('<ul class="form-errors"></ul>');
								// Go through each error for this field
								$.each(element.errors, function(i, e) {
									// Append the error to the list as a list item
									$errorList.append('<li>' + e + '</li>');
								});
								// Add the error list after the element
								$element.after($errorList);
							}
						}
					});
					// Fade all errors in
					$('.form-errors').fadeIn(1600);					
				}				
			}
		});
	});	
});


//Image preloader
var images = new Array(
	'images/more-info1.png'
);
var imageObjs = new Array();
for (var i in images) {
	imageObjs[i] = new Image();
	imageObjs[i].src = images[i];
}

