// JavaScript Document

jQuery(document).ready(function(){
								
	 jQuery('#submenu li a').after('<h6></h6>');
	 
	 jQuery('#submenu li ul li a').after('<h6></h6>');
	 
	 jQuery('#submenu li ul li ul li a').after('<h6></h6>');
								
	 jQuery('#submenu li').has('ul').addClass('with_accord');
	 
	 jQuery('.with_accord a:first-child').next().remove();
	 
	 jQuery('.with_accord a:first-child').after('<h4></h4>');
	 
	 jQuery('.with_accord ul li').find('h4').remove();
	 
	 jQuery('.with_accord ul .with_accord a:first-child').next().remove();
	 
	 jQuery('.with_accord ul .with_accord a:first-child').after('<h5></h5>');
	 
	 jQuery('.with_accord ul .with_accord ul li').find('h5').remove();
	 
	 jQuery('#submenu .current_page_ancestor > h4, #submenu .current_page_ancestor > h5').addClass('arrow_down');
	 
	 jQuery('#submenu .current_page_item > h4, #submenu .current_page_item > h5').addClass('arrow_down');
	 
	 jQuery('#submenu .current_page_item').has('ul').find('> h5').addClass('arrow_down');
	
	 jQuery('#submenu').accordion({
	 	header: 'h4',
	 	navigation: true,
		navigationFilter: function() { jQuery('.with_accord_title').click( function() { return false; } ); },
	 	clearStyle: true,
	 	autoheight: false,
		collapsible: true,
		active: true
	 });
	 
	 jQuery('#submenu ul').accordion({
		header: 'h5',
		navigation: true,
		navigationFilter: function() { jQuery('.with_accord_title2').click( function() { return false; } ); },
		clearStyle: true,
		autoheight: false,
		collapsible: true,
		active: true
	 });
	 
	jQuery('#submenu h4').click(function() {
		jQuery(this).next().toggle();
		jQuery(this).toggleClass('arrow_down');
		return false;
	}).next().hide();
	
	jQuery('#submenu h5').click(function() {
		jQuery(this).next().toggle();
		jQuery(this).toggleClass('arrow_down');
		return false;
	}).next().hide();

	 
	 /*jQuery('#submenu ul').accordion({
	 	header: '.with_accord_title2',
	 	event: 'mouseover',
	 	navigation: true,
	 	clearStyle: true,
	 	autoheight: false,
	 	collapsible: true
	 });*/
	
	 //jQuery('#submenu ul li:not(:first)').each().prepend('<div class="not_expandable">&nbsp;</div>');
	//jQuery("#submenu").treeview();
	


	jQuery('#submenu ul .current_page_item').parent().parent().parent().css({ 'display' : 'block' });
	
	jQuery('#submenu ul ul .current_page_item').parent().css({ 'display' : 'block' });
	
	jQuery('#submenu ul .current_page_item').parent().css({ 'display' : 'block' });
	
	jQuery('#menu > li:last').css({'border-right' : 'none'});
	
	jQuery('#submenu li:last-child').addClass('no_border');
	
	jQuery('#submenu .current_page_item > ul').css({ 'display' : 'block' });
										  
	/*** Navigation ***/
	/** ----------------------------------------------------- **/
	jQuery('#menu').superfish({
		delay:       500,
		animation:   { opacity: 'show', height:'show' },
		speed:       500,
		autoArrows:  true,
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		easing: 'easeOutQuart'
	}); 
	
    jQuery('#feature_photo div').cycle({
		fx:     'fade',
		speed:  'slow'
	});
	
	//Form
	
	var loader = jQuery('<div id="loader"><span>Sending Message...</span></div>')
		.appendTo('#form_result')
		.hide();
	jQuery().ajaxStart(function() {
		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({
				beforeSubmit : function () {
					jQuery('#contact_form').hide(500);
				},
				target : '#form_result'
			});
		}
			
	});
	
	//footer add class
	
	jQuery('#footer ul li.menu-item a').addClass('with_cufon');
	
	jQuery('#footer ul li ul li.menu-item a').removeClass('with_cufon');
	
	//prettyphoto (lightbox effect)
	
	jQuery('a[rel^="prettyPhoto"]').prettyPhoto({theme:'facebook'});
	
	
	//font scale
	
	jQuery('#up').fontscale("h1,h2,h3,h4,p,li","up",{unit:"percent",increment:15});
	jQuery('#down').fontscale("h1,h2,h3,h4,p,li","down",{unit:"percent",increment:15});
	jQuery('#reset').fontscale("h1,h2,h3,h4,p,li","reset");								  
});

/*** Functions ***/
/** ----------------------------------------------------- **/

jQuery(function(){ //smooth scroll
					 
	jQuery('.smooth_scroll a').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($object){  //apply an alternate class on a row of a table

	jQuery( $object + ' tbody tr:nth-child(odd)').addClass('odd');
	
	jQuery( $object + ' tbody tr').hover(
		function () {
		jQuery(this).addClass('trover');
	},
		function () {
		jQuery(this).removeClass('trover');
	})
  
}


