// JavaScript Document



jQuery(document).ready(function(){

	

	//Add attributes

	

	jQuery('#navigation li a').addClass('main_buttons');

	jQuery('#navigation li a a').removeClass('main_buttons');

	

	jQuery('.commentlist li:first-child, .children li:first-child').addClass('first');

	jQuery('.commentlist li:last-child, .children li:last-child').addClass('last');

	

	if ( jQuery('ol.commentlist li').find('ul.children') ) {

		jQuery(this).addClass('asdf');

	}

	

	jQuery('ol.commentlist li:not(:has("ul.children"))').addClass('last')

	

	jQuery('#navigation').superfish({

		delay:       800,

		animation:   { opacity: 'show', height:'show' },

		speed:       300,

		autoArrows:  true,

		anchorClass : 'sf-with-ul',

		arrowClass  : 'sf-sub-indicator',

		dropShadows: false

	}); 

	

	jQuery('#featured_desc').jcarousel({
		scroll: 1,
		auto: 5,
		wrap: 'both',
		animation: 1500,
		initCallback: feature_carousel_initCallback,
		buttonNextHTML: null,
		buttonPrevHTML: null,
		easing: 'easeInOutExpo'
	});
	
	jQuery('#featured_images').jcarousel({
		scroll: 1,
		auto: 5,
		wrap: 'both',
		animation: 1500,
		initCallback: feature_carousel_initCallback,
		itemVisibleInCallback: {onBeforeAnimation: images_itemVisibleInCallback},
		buttonNextHTML: null,
		buttonPrevHTML: null,
		easing: 'easeInOutExpo'
	});

	





	// jQuery('#navigation li a.main_buttons').corner('5px');

	

	//Add Design Related

	

	jQuery('.widget_calendar #calendar_wrap').unwrap();

	jQuery('.widget_calendar').wrapInner('<div class="calendar_wrapper"></div>');

	

	jQuery('.widget_text .textwidget').unwrap();

	jQuery('.widget_text').wrapInner('<div class="widget_wrapper_text"></div>');

	

	jQuery('.info_section ul li:first-child').addClass('first');

	jQuery('.info_section ul li:last-child').addClass('last');

	

	jQuery('#single_page .basic_style_1 a, #post_list .basic_style_1 a').find('img').addClass('image_with_desc_wrap');

	

	jQuery('#footer_menu li:not(li:last-child)').append('|')

	

	//Pretty Photo (lightbox effect)

	jQuery('#single_page .basic_style_1 a[href$=jpg], #single_page .basic_style_1 a[href$=gif], #single_page .basic_style_1 a[href$=png], #single_page .basic_style_1 a[href$=bmp]').addClass('pretty_photo');

	jQuery('.pretty_photo').prettyPhoto();

	

	//Form

	

	var loader = jQuery('<div id="loader"><img src="http://flre.ca/wordpress/wp-content/themes/frontline/images/ajax-loader.gif" alt="loading..." /> <span>Sending Message...</span></div>')

		.appendTo('#form_result')

		.hide();

	jQuery().ajaxStart(function() {

		jQuery('#contact_form').hide(500);

		jQuery('#quick_contact').hide(500);

		loader.show(500);

	}).ajaxStop(function() {

		loader.hide(500);

	}).ajaxError(function(a, b, e) {

		throw e;

	});

	

	$("#contact_form").validate({

			

		rules: {

			input_name: 'required',

			input_email: {

				required: true,

				email: true

			},

			input_subject: 'required',

			textarea_message: 'required'

		},

		messages: {

			input_name: 'Name is required',

			input_email: {

				required: 'Email is required',

				email: 'Invalid email format'

			},

			input_subject: 'Please specify a subject',

			textarea_message: 'Message is empty'

		},

		errorElement: 'span',

		errorClass: 'error_message',

		errorPlacement: function(error, element) {

			error.appendTo(element.parent('span').prev('label'));

		},

		submitHandler: function(form) {

			jQuery(form).ajaxSubmit({

				target : '#form_result'

			});

		}

			

	});

	

	$("#quick_contact").validate({

			

		rules: {

			input_name: 'required',

			input_email: {

				required: true,

				email: true

			},

			input_subject: 'required',

			textarea_message: 'required'

		},

		messages: {

			input_name: 'Name is required',

			input_email: {

				required: 'Email is required',

				email: 'Invalid email format'

			},

			textarea_message: 'Message is empty'

		},

		errorElement: 'span',

		errorClass: 'error_message',

		errorPlacement: function(error, element) {

			error.appendTo(element.parent('p').prev('p'));

		},

		submitHandler: function(form) {

			jQuery(form).ajaxSubmit({

				target : '#form_result'

			});

		}

			

	});

	

	/*** Cufon ***/

	/** ----------------------------------------------------- **/

	

	Cufon.replace(

		
		'#featured_desc h2,' +

		'#featured_desc h3,' +

		'#contact_page #contact_form label,' +

		'.comment-author,' +

		'.font_main,' +

		'.wp-pagenavi'

					  

	,{ fontFamily: 'Sansation', hover: true });

	

	Cufon.replace(

		

		'.basic_style_1 h1, .basic_style_1 h2, .basic_style_1 h3, .basic_style_1 h4, .basic_style_1 h5, .basic_style_1 h6'

					  

	,{ fontFamily: 'Sansation', hover: true });

	

	//Initialize Zebra Table

	

	zebra_table();

	

});



//Functions



function feature_carousel_initCallback($carousel) {

	

	jQuery('#featured_buttons li').bind('click', function() {

		$carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));

		$carousel.startAuto(0);

		jQuery('#featured_buttons li.clicked').removeClass('clicked');

		jQuery(this).addClass('clicked');

		return false;

	});



};



function images_itemVisibleInCallback(carousel, item, idx, state) {

	jQuery('#featured_buttons li.clicked').removeClass('clicked');

	jQuery('#featured_buttons li:contains("' + idx + '")').addClass('clicked');

}; 



jQuery(function(){ //smoothscroll

	jQuery('.smooth_scroll').click(function() {

		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 

			&& location.hostname == this.hostname) {

				var $target = $(this.hash);

				$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');

			if ($target.length) {

				var targetOffset = $target.offset().top;

				$('html,body').animate({scrollTop: targetOffset}, 1000);

				return false;

			}

		}

	});

});



function zebra_table(){ //zebra table



	jQuery('tbody tr:nth-child(odd)').addClass('odd');

	

}







/* Odd/Even functions for listings */

$(document).ready(function(){

$("#post_list li.listings:even").addClass("even");

$("#post_list li.listings:odd").addClass("odd");

});





/* Load Twitter Feed */

    $(document).ready(function(){

        $(".tweet").tweet({

            username: "frontlineRE",

            join_text: "auto",

            avatar_size: 1,

            count: 1,

            loading_text: "loading tweets..."

        });

    });

    

    
