Cufon.replace('#navigation ul li a, a.read-more-btn',{fontFamily:'MyriadPro Regular', hover: true});

jQuery(document).ready(function($) {
	
	var speed = 650;
	
	$(".quicklinks ul li a").each(function(index) {
	  
		$el = $(this);
		var width = $el.find("span").width();
		$el.data('width',width);
	
	});
	
	$(".center .cont").after('<span class="nextcon" /><span class="prevcon" />');
	
	$(".nextcon").live('click', function(event) {
		var theIndex = $(".center .cont div").index( $(".center .cont div.cur") ) + 1;
		var num = $(".center .cont div").length;
		
		if($(".center .cont div").is(":animated")){
			
		} else {
			if(theIndex == num){
				$(".center .cont .cur").fadeOut(speed).removeClass("cur");
				$(".center .cont div").eq(0).delay(speed).fadeIn(speed).addClass("cur");
			} else {
				$(".center .cont .cur").fadeOut(speed).removeClass("cur").next().delay(speed).fadeIn(speed).addClass("cur");
			}
		}
		
		return false;
	});
	
	$(".prevcon").live('click', function(event) {
		var theIndex = $(".center .cont div").index( $(".center .cont div.cur") ) + 1;
		var num = $(".center .cont div").length;
		
		if($(".center .cont div").is(":animated")){
			
		} else {
			if(theIndex == 1){
				$(".center .cont .cur").fadeOut(speed).removeClass("cur");
				$(".center .cont div").eq(num - 1).delay(speed).fadeIn(speed).addClass("cur");
			} else {
				$(".center .cont .cur").fadeOut(speed).removeClass("cur").prev().delay(speed).fadeIn(speed).addClass("cur");
			}
		}
		
		return false;
	});
	
	function slidingInfo(type, other){
		
		if(type == 'over'){
			desc.animate({ 'bottom': '0px' }, { queue: false, duration: speed });
			title.animate({ 'top': '0px' }, { queue: false, duration: speed });
			
		} else if(type == 'out'){
			
			
		}
		
	}
	
	//set featured title title
	$("#jplayer_playlist ul li").html($(".large .title h2").html());
	
	if($("#player").length != 0){
	
	$("#player").jPlayer({
		ready: function () {
			this.element.jPlayer("setFile", $(".large").attr("mp3"));
		},
		swfPath: 'http://iwalkedaudiotours.com/iw/wp-content/themes/iwalked/style/js/',
		nativeSupport: true,
		oggSupport: false
		//errorAlerts: true,
		//warningAlerts: true
	});
	
	}
	
	$(".large .play").live('click', function(event) {
		
		$el = $(this);
		if($el.hasClass("playing")){
			$("#player").jPlayer("pause");
		} else {
			$("#player").jPlayer("play");			
		}
		
		return false;
	});
	
	// large area functions
	
	var desc = $(".large .desc"),
		title = $(".large .title");
		
	var amount = 8;
	
	title.css({
	
	'top': '-35px'
		
	});
	
	desc.css({
	
	'bottom': '-135px'
		
	});
	
	desc.show();
	title.show();
	
	$(".large").hover(function() {
		
		slidingInfo('over');
		
	}, function() {
		
		slidingInfo('out');
		
	});
	
	
	/////////////////////////////////////
	
	$(".wp-post-image").each(function(index) {
		$(this).attr("title","");
		$(this).attr("alt","");
	});
	
	$(".wp-tag-cloud li a").attr("title","");
	var swapCount = 0;
	function swapSmall(item){
		
		$cur = $(".center");
		$el = item;
		
		var elimg = $el.find("img").attr("src"),
			eltitle01 = $el.find(".title h2").html(),
			eltitle02 = $el.find(".title h3").html(),
			elitunes = $el.find("a.itunes").attr("href"),
			elgmaps = $el.find("a.gmap").attr("href"),
			eldesc = $el.find(".desc .cont").html(),
			elpurchase = $el.find("div.purchaseinfo").html();
			elmp3 = $el.attr("mp3");
						
		var curimg = $cur.find("img").attr("src"),
			curtitle01 = $cur.find(".title h2").html(),
			curtitle02 = $cur.find(".title h3").html(),
			curitunes = $cur.find("a.itunes").attr("href"),
			curgmaps = $cur.find("a.gmap").attr("href"),
			curdesc = $cur.find(".desc .cont").html(),
			curpurchase = $cur.find("div.purchaseinfo").html();
			curmp3 = $cur.parent().attr("mp3");
			
		
		
		$(".large .center").fadeOut(function(){
			
			//swap images
			$cur.find("img").attr("src",elimg);
			
			$el.find("img").attr("src",curimg);
			
			//swap titles
			$cur.find(".title h2").html(eltitle01);
			$cur.find(".title h3").html(eltitle02);
			
			$el.find(".title h2").html(curtitle01);
			$el.find(".title h3").html(curtitle02);
			
			//swap links
			$cur.find("a.itunes").attr('href',elitunes);
			$el.find("a.itunes").attr('href',curitunes);
			
			$cur.find("a.gmap").attr('href',elgmaps);
			$el.find("a.gmap").attr('href',curgmaps);
			
			//swap description
			$cur.find(".desc .cont").html(eldesc);
			
			$el.find(".desc .cont").html(curdesc);
			$(".center .cont").hide();
			//swap purchase link
			$cur.find("div.purchaseinfo").html(elpurchase);
			$el.find("div.purchaseinfo").html(curpurchase);
			
			
			if($(".center .cont div").length != 0){
				
			} else {
				$(".center .cont h2, .center .cont p").slice(0,2).wrapAll("<div />");
				$(".center .cont h2, .center .cont p").slice(2,4).wrapAll("<div />");
				$(".center .cont h2, .center .cont p").slice(4,6).wrapAll("<div />");
				$(".center .cont h2, .center .cont p").slice(6,8).wrapAll("<div />");
			}
			
			$(".center .cont div").hide();
			$(".center .cont").show();
			$(".center .cont div").eq(0).addClass("cur").fadeIn(speed);
			
		}).fadeIn();
		//descfade();
		var songname = $el.find(".title h2").html();
		
		$("#player").jPlayer("stop");
		$("#player").jPlayer( "setFile", elmp3).jPlayer("play");
		$("#jplayer_playlist ul li").html(songname);
		
		$cur.parent().attr("mp3",elmp3);
		$el.attr("mp3",curmp3);
		
	}
	
	$(".center .cont h2, .center .cont p").slice(0,2).wrapAll("<div />");
	$(".center .cont h2, .center .cont p").slice(2,4).wrapAll("<div />");
	$(".center .cont h2, .center .cont p").slice(4,6).wrapAll("<div />");
	$(".center .cont h2, .center .cont p").slice(6,8).wrapAll("<div />");
	$(".center .cont div").hide();
	$(".center .cont").show();
	$(".center .cont div").eq(0).addClass("cur").fadeIn(speed);
	
	
	$(".small").live('click', function(event) {
		swapSmall($(this));
		return false;
	});
	
	$(".tours-small ul li").live('click', function(event) {
		swapSmall($(this));
	});
	
	/////////////////////////////////////
	
	$("a.prev-track").live('click', function(event) {
		
		if($(".small").length != 0){
			$(".small.left").click();
		} else {
			swapSmall($(".tours-small ul li:eq(0)"));
		}
		
		
		return false;
	});
	
	$("a.next-track").live('click', function(event) {
		
		if($(".small").length != 0){
			$(".small.right").click();
		} else {
			swapSmall($(".tours-small ul li:eq(1)"));
		}
		
		return false;
	});
	
	if($(".tours-small").length != 0){
		var speed = 650;
		var total = $(".tours-small ul li").length;
		
		if(total <= 4){
			$(".tours-small .prev").hide();
			$(".tours-small .next").hide();
		}
		
		
		$(".tours-small .prev").click(function() {
			
			var imageHeight = $(".tours-small ul li").eq(0).height() + 7;
			var curScroll = parseInt($(".tours-small ul").css("marginTop").replace("px",""));
			
			var totalItems = $(".tours-small ul li").length;
			
			if($(".tours-small ul").is(":animated")){
				
			} else {
			
				if(curScroll == 0){
				
				
				
				} else {
			
					$(".tours-small ul").animate({

					'marginTop': curScroll + imageHeight

					}, { queue: false, duration: speed });
				
				}
			
			}
			
			return false;
		});
		
		$(".tours-small .next").click(function() {
			
			var imageHeight = $(".tours-small ul li").eq(0).height() + 7;
			var curScroll = parseInt($(".tours-small ul").css("marginTop").replace("px",""));
			
			var totalItems = $(".tours-small ul li").length;
			
			if($(".tours-small ul").is(":animated")){
				
			} else {
			
				if(curScroll == (-imageHeight * totalItems) + (imageHeight * 4)){
				
				
				
				} else {
			
					$(".tours-small ul").animate({

					'marginTop': curScroll - imageHeight

					}, { queue: false, duration: speed });
				
				}
			
			}
						
			return false;
		});
		
	}
	
	if($(".quotes").length != 0){
		
		$(".quotes ul li").hide();
		$(".quotes ul li").eq(0).show().addClass("visible");
		
		function loopQuotes(){
			
			var wait = 7000;
			var speed = 1000;
			var index = $(".quotes ul li").index($(".quotes ul li.visible")) + 1;
			var total = $(".quotes ul li").length;
			
			if(total == index){
				
				setTimeout(function() {
					
					$(".quotes ul li.visible").fadeOut(speed).removeClass("visible");
					$(".quotes ul li:first").fadeIn(speed).addClass("visible");
					
				}, wait);
				
			} else {
			
				setTimeout(function() {

					$(".quotes ul li.visible").fadeOut(speed).removeClass("visible").next().fadeIn(speed).addClass("visible");
					loopQuotes();

				}, wait);
				
			}
			
		}
		
		loopQuotes();
		
	}
	
	if($("#thewrap").length != 0){
		
		$(".copy").jScrollPane({
			
			reinitialiseOnImageLoad: true
			
		});
		
	}
	
	$(".quicklinks ul li a").tipsy({
		live: true,
		gravity: 's',
		fade: true
	});
	
	$(".desc a").tipsy({
		live: true,
		gravity: 's',
		fade: true
	});
	
	if($(".page-id-44").length != 0){
		
		$(".copy > ul > li > ul").slideUp();
		
		$(".copy ul li h3").live('click', function(event) {
			
			if($(this).parent().find("ul").is(":visible")){
				
			} else {
				$(".copy > ul > li > ul").slideUp();
			}
			
			$(this).parent().find("ul").slideDown();
			
			return false;
		});
		
	}
		
});

