/* +----------------------------------------------------+ */
/* | Main JavaScript used on this site                  | */
/* +----------------------------------------------------+ */

Cufon.replace('nav a', { fontFamily: 'Belwe Std' });
Cufon.now();

/**
 * onLoad events 
 */
$(document).ready(function() {
	text_field_observer();
	new_window_handler();
	video_helper();
});

/**
 * Kill parent framesets, except Wordpress preview frame 
 */
if (top.location != self.location) {
	if (self.location.indexOf('preview=1') == -1) {
		top.location.replace(self.location.href);
	}
}

/**
 * Clear certain input fields on focus
 */
function text_field_observer()
{
	$('#sidebar .default_text').focus(function() {
		if ($(this).val() == $(this).attr('value')) {
			$(this).val('');
			$(this).removeClass('default_text');
		}
	});
}

/**
 * Open certain links in new windows
 */
function new_window_handler()
{
	$("a[rel='external']").click(function(event) { 
		window.open(this.href); 
		event.preventDefault(); 
	});	
}

/**
 * Display latest Tweets
 */
function get_twitter_feed(number)
{
	$('#twitter_feed').tweet({
		username: 'soniahunt', join_text: '', avatar_size: 50, count: number, 
		loading_text: '<img src="/content/themes/soniahunt/images/loading.gif" alt="" class="loading" />'
	});
}

/**
 * Functionality needed on front page
 */
function front_page_helper()
{
	// Replace footer icons
	$('footer a img').each(function() {
		$(this).attr('src', $(this).attr('src').replace('.png', '-main.png'));
	});
	// Cycle background image
	$('#fp_background').cycle({ 
		timeout: 5000, speed: 1000, delay: 2000 
	});
}

/**
* Functionality needed on single post pages
 */
function single_helper()
{
	comment_form_helper();
}

/**
 * Run functions needed on video pages
 */
function video_helper()
{
	$('.scroll-pane').jScrollPane();
	$('.scroll-pane-arrows').jScrollPane({
		showArrows: true,
		horizontalGutter: 10
	});
}


function comment_form_helper()
{
	// Turn off HTML5 validation. URL field is allowed to not validate, as it's not required. 
	$('#commentform').attr('novalidate', true);
}



