jQuery(document).ready(function($) {

function formatText(index, panel) {
		  return index + "";
	    }
    
        $(function () {
        
            $('.anythingSlider').anythingSlider({
                easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
                autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
                delay: 10000,                    // How long between slide transitions in AutoPlay mode
                startStopped: false,            // If autoPlay is on, this can force it to start stopped
                animationTime: 1000,             // How long the slide transition takes
                hashTags: false,                 // Should links change the hashtag in the URL?
                buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
        		pauseOnHover: false,             // If true, and autoPlay is enabled, the show will pause on hover
        		startText: "Go",             // Start text
		        stopText: "Stop",               // Stop text
		        navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
            });
            
            $("#slide-jump").click(function(){
                $('.anythingSlider').anythingSlider(6);
            });
            
        });

//TABS
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

//Make first word in City Country occurences bold
	$(".city-nav ul li a").each(function(){
		var me = $(this);
		me.html( me.text().replace(/(^\w+)/,'<strong>$1</strong>') );
	});
	$("body.page-template-page-city-php .post h2").each(function(){
		var me = $(this);
		me.html( me.text().replace(/(^\w+)/,'<strong>$1</strong>') );
	});
	
//Highlight appropriate city for city taxonomy posts
	$('body.city-axum li.page-item-20').addClass('current_page_item');
	$('body.city-brest li.page-item-22').addClass('current_page_item');
	$('body.city-chennai li.page-item-24').addClass('current_page_item');
	$('body.city-cuernavaca li.page-item-26').addClass('current_page_item');
	$('body.city-karmiel li.page-item-28').addClass('current_page_item');
	$('body.city-kunming li.page-item-30').addClass('current_page_item');
	$('body.city-nairobi li.page-item-32').addClass('current_page_item');
	$('body.city-potenza li.page-item-34').addClass('current_page_item');
	$('body.city-takayama li.page-item-36').addClass('current_page_item');
	$('body.city-ulaanbaatar li.page-item-38').addClass('current_page_item');
	$('body.single-post li.page-item-8').addClass('current_page_item');
	$('body.single-trip li.page-item-8').addClass('current_page_item');
	
//Animated City Menu
		//add class to UL to prevent default css hover functions
	$('ul.cities').removeClass('cities').addClass('java-city');

	//var cityitem = $('ul.java-city li').not('ul.java-city li.current_page_item');

	//create .bar in each list item
	$('ul.java-city li').append('<div class="bar"></div>');
			
	//animate .bar when hovering over $citylink
	$('ul.java-city li').not('ul.java-city li.current_page_item').hover(
		function(){
		$(this).find('.bar').stop(true, false).animate({width:150},1000,'easeOutExpo');
		$(this).find('a').stop(true, false).animate({color:'#FFF'},500,'easeOutExpo');
		},function(){
		$(this).find('.bar').stop(true, false).animate({width:4},400,'easeOutExpo');
		$(this).find('a').stop(true, false).animate({color:'#404040'},200,'easeOutExpo');
		}
	);
	
//FancyBox for Flickr galleries
	$("a.flickr-gallery").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	500, 
		'speedOut'		:	300, 
		'overlayShow'	:	true
	});

//email input text
$("#email-box").focus(function() {
        if ($(this).val() == "email address") {
            $(this).val("");
        }
    });

//Accordian
	$('.post h4 + p').addClass('accordian').hide();
	$('.post h4').addClass('accordian').click(function(){$(this).toggleClass('selected');$(this).find('+ p').slideToggle();});

	
//add classes for link icons

	$("a").filter(function() {return this.hostname && this.hostname !== location.hostname;}).addClass('external');
	$(".post").not(".main-city").find("a").addClass("link-icon");

});
