/*
jQuery for Touch Financial
Developed by Ricco Sobers
http://www.riccosobers.com

*/

$(document).ready(function() {
	
var open = false;
$("#featuredPostTitle").animate({opacity: 0.90}, 'fast');

/* =NAVIGATION ACCORDION FOR SIDEBAR
    -------------------------------------------------------------------------- */
	$('.sidebar-list>li>ul>.page_item>a').click(function() {
		if (!$(this).hasClass('gotolink')) {
			if ( $(this).next().is(':visible')){
				$(this).removeClass('btn-active').next().stop(false, true).slideUp('normal', function() {$(this).slideDown('fast').prev().addClass('btn-active');});
			}
			else if ( $(this).next().not(':visible')) {
				if ( $('.page_item .children').is(':visible')){
					$('.page_item .children').stop(false, true).slideUp('normal');
				}
					$('.sidebar-list li li a').removeClass('btn-active');
				$(this).next().stop(false, true).slideDown('normal');
				$(this).addClass('btn-active');
			}
			return false;
		}else{
				location.href = $(this).attr('href');
		}
	}).next().hide();
	$('.sidebar-list>li>ul>li').each( function() {
		if ($(this).hasClass('current_page_ancestor')) {
				$(this).children('.children').slideDown('slow').prev().addClass('btn-active'); 
				open = true;
		}
		else if ($(this).hasClass('keepguidesclose')) {
			open = true;
		}
	});
	if (!open) {
		$('.sidebar-list>li>ul>li>.children:first').slideDown('slow').prev('.page_item>a').addClass('btn-active');
	}

/* =KNOWLEDGE CENTRE
    -------------------------------------------------------------------------- */	
	$('.updateFeature').live('mouseover', function() {
		id = $(this).attr('id');
		i = 170;
		if (id == "postnum_1") { i = 100; } else if (id == "postnum_3"){ i = 190; } 
		pos =  i * id.replace('postnum_','');
		$("#arrow").stop(false, true).animate({ left: pos + "px" }, 'fast');
		title = $(this).attr('title');
		author = $(this).attr('rel');
		href =  $(this).attr('href');
		image =  $(this).find('.bigIMG').attr('rel');
		
		$("#featuredPostTitle").find('a').stop(false, true).fadeOut('fast', function(){ 
			$(this).html(title).attr('href', href); 
		}).stop(false, true).fadeIn('fast');
			$("#featureauthor").stop(false, true).html(author);
				$(".postpermalink").stop(false, true).attr('href', href)
					$("#featuredIMG").stop(false, true).fadeOut('fast', function(){ 
						$(this).attr('src', image); 
					}).stop(false, true).fadeIn('fast');
		return false;
	});
	
	$('.btn_toggle_searchbox').click(function() {
	  $('#searchbox').slideToggle('fast'); //Toggle the Search box
	  $(this).attr("src", "http://www.touchfinancial.co.uk/wp-content/themes/touchfinancial/images/icon_search_white.png");
	  return false;
	});
	
	$(".btn_toggle_searchbox").hover(function(){
		$(this).find('img').attr("src", "http://www.touchfinancial.co.uk/wp-content/themes/touchfinancial/images/icon_search_white.png");
	}, function(){
		$(this).find('img').attr("src", "http://www.touchfinancial.co.uk/wp-content/themes/touchfinancial/images/icon_search.png");
	});
	
	$('.btn_toggle_services').click(function() {
		$id = $(this).attr("id");
		$(this).html('More +');
		if ( $('#'+$id+'-block').hasClass("showb") ) {
			$('#'+$id+'-block')
				.removeClass("showb").slideUp('slow');
		}else{
			$(this).html('Less -');
			$('#'+$id+'-block')
				.addClass("showb").slideDown('slow');
		}
		location.href = "#"+$id;
		return false;
	});
});
