///////////////////////////////////////////////////////////
///	jQuery Google Analytics Plugin
///////////////////////////////////////////////////////////

//	Uncomment for debugging into Firebug Console
//	$.fn.track.defaults.debug = true;

//	Load Google Analytics script & track page views
	$.trackPage(gaKey,{callback:impressionTracking});
	
	$(document).ready(function(){
		$('.AdvertsWidget a').track({
			category :	'advert',
			action	 :	'click',
			label	 :	function(element) { return element.attr('rel') },
			value	 :	null,
    		skip_internal : false
		});
	});
	
	function impressionTracking() {
		$('.AdvertsWidget .advert').each(function(){
			$.trackEvent(
				'advert',
				'impression',
				$(this).attr('title'),
				null
			);
		});
	}

///////////////////////////////////////////////////////////
///	Add Custom jQuery Functions
///////////////////////////////////////////////////////////

jQuery.fn.slideFadeToggle  = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
};

///////////////////////////////////////////////////////////
///	Deprecated Browsers Rejection
///////////////////////////////////////////////////////////

$(document).ready(function() {
	$.reject({
		imagePath: '/themes/zendankwan/images/browsers/'
	});	
});

///////////////////////////////////////////////////////////
///	Open MailChimp Subscription Links in New Window
///////////////////////////////////////////////////////////
$(document).ready(function(){
	$('a[href^="http://eepurl.com"]').attr('target','_blank');
});

///////////////////////////////////////////////////////////
///	Tree Navigation
///////////////////////////////////////////////////////////

$(document).ready(function() {
	$('.tree-navigation').treeview({
		animated: "normal",
		collapsed: true,
		control: "#tree-controls",
		// cookieId: "treeview-zdk",
		// persist: "cookie"  
		// persist: "location"
		persist: "location" 
	}).fadeIn();
});

///////////////////////////////////////////////////////////
///	Feature Box Description Slide Up/Down
///////////////////////////////////////////////////////////

$(document).ready(function() {
	
	// Feature Box Description Slide Toggle
	$('.feature-item').hover(
		function(){ $(this).find('p').slideDown(); },
		function(){ $(this).find('p').slideUp(); }
	);
	
	// Feature Box Cycle
	$('.type-home .features').cycle({ 
		fx:     'fade', 
		speed:   900, 
		timeout: 5000,
		pause:   1 
	});
});

///////////////////////////////////////////////////////////
///	FAQs Question/Answer Slide
///////////////////////////////////////////////////////////

$(document).ready(function() {
		
	$(".question").click(function(){
		$(this).next().slideToggle();
		$(this).toggleClass('question-show');
	}); 

});

///////////////////////////////////////////////////////////
///	Contact Page Google Map
///////////////////////////////////////////////////////////

$(document).ready(function() {
	
	if ($('.section-contact #googlemap').length) {
		var mapLatLng = new google.maps.LatLng(mapLat, mapLng);
		var mapOptions = {
			zoom: 14,
			center: mapLatLng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var map = new google.maps.Map(document.getElementById('googlemap'), mapOptions);
	    var marker = new google.maps.Marker({
	        position: mapLatLng, 
	        map: map,
	        title:"Zen Dan Kwan School of Martial Arts"
	    });
	} 

});

///////////////////////////////////////////////////////////
///	Form Elements Focus Behaviour
///////////////////////////////////////////////////////////

$(document).ready(function() {
	
	// Give Form Elements class of 'idle-field'
	$('input, select, textarea').addClass("idle-field");
	
	// Change class 'idle-field' to 'focus-field' when Form Element gets focus
	$('input[type=text], select, textarea').focus(function() {
		$(this).removeClass("idle-field").addClass("focus-field");
	});
	
	// Reset class to 'idle-field' once Form Element loses focus
	$('input[type=text], select, textarea').blur(function() {
		$(this).removeClass("focus-field").addClass("idle-field");
	});
	
	// Set Label as Default Value
	$('#home-subscribe-form input').each(function(){
		$(this).val($(this).siblings('label').html());
	});
	$('#home-subscribe-form input').focus(function() {
		if (this.value == $(this).siblings('label').html()){
			this.value = '';
		}
		if(this.value != $(this).siblings('label').html()){
			this.select();
		}
	});
	$('#home-subscribe-form input').blur(function() {
		if ( $.trim(this.value) == ''){
			this.value = ($(this).siblings('label').html() ? $(this).siblings('label').html() : '');
		}
	});
});

