// JavaScript Document

function openPanel(obj) { // Need to close all the panels first.
	$(".nav-panel").slideUp("fast");
	if ($("#panel-" + obj).is(":hidden")) {
		$("#panel-" + obj).slideDown("slow");
	}// else {
	//	$("#panel-" + obj).slideUp("fast");
	//}
}
function openSubPanel(obj) { // Reset anchors
	$('section#panel-what .titles a').removeClass('active');
	$('section#panel-what #nav-' + obj).addClass('active'); // Reset everything;
	$('section#panel-what .slide').css('display', 'none');
	$('section#panel-what #' + obj).css('display', 'block'); // Set the margin out
	$('section#panel-what #' + obj + " .inner").css('margin-left', '-960px');
	var $marginLefty = $('section#panel-what #' + obj + " .inner");
	$marginLefty.animate({
		marginLeft: 0
	}, 500);
}

var upImg = "http://www.georgebarnsdale.co.uk/wp-content/themes/pop/images/arrow_down.png";
var downImg = "http://www.georgebarnsdale.co.uk/wp-content/themes/pop/images/arrow_up.png";

function slideType(id) {
	
			if($("#slideType").parent('li').children('ul').hasClass('opened')) {
			$("#slideType").parent('li').children('ul').slideUp().removeClass('opened');
			$("#slideType").parent('li').find('img').attr('src', upImg);				

		} else {
			$("#slideType").parent('li').children('ul').slideDown().addClass('opened');
			$("#slideType").parent('li').find('img').attr('src', downImg);	

	//	$('ul.opened').slideUp().removeClass('opened'); /// New line
		
		}
}
		
function sideMenuAccordian() {
//	$('li:has(ul)').children('a').click(function() {
	$('.arrow').click(function() {	
			
			
		if($(this).parent('li').children('ul').hasClass('opened')) {
			$(this).parent('li').children('ul').slideUp().removeClass('opened');
			
			$(this).find('img').attr('src', upImg);			

		} else {
			$(this).parent('li').children('ul').slideDown().addClass('opened');

			$(this).find('img').attr('src', downImg);	
		
		}
		
		

		return false;
	}); /* the following two lines will ensure that the UL opens to the section that you had open on the navigation when you left the page, if you wish the navigation to simply revert back to all the categories being closed when you leave a page then remove the two lines of code below */
	
	
}
var loader = 'http://www.georgebarnsdale.co.uk/wp-content/themes/pop/images/loading.gif';
$(document).ready(function() {
		$('#slides').slides({
				effect: 'fade',
				crossfade:true,
				preload: true,
				preloadImage: loader,
				play: 5000,
				pause: 5000,
				hoverPause: true,
				pagination: false
			});
	
//		$('.accord').children('li').children('a').addClass('up');

$('li:has(ul.children)').children('a').before('<a href="#" class="arrow"><img src="http://www.georgebarnsdale.co.uk/wp-content/themes/pop/images/arrow_down.png" height="32" width="32"></a>');

$('li:has(ul.accord-menu)').children('a').before('<a href="#" class="arrow"><img src="http://www.georgebarnsdale.co.uk/wp-content/themes/pop/images/arrow_down.png" height="32" width="32"></a>');


//$('li:has(ul)').children('a').addClass('up');

$('a.on').parent('li').children('ul').show().parent('li').children('a.arrow img').attr('src', downImg);
	$('a.on').parent('li').parent('ul').show();



	$('a.on').parent('li').parent('ul').parent('li').children('a.arrow').children('img').attr('src', downImg);
	$('li.current_page_item').parent('ul').parent('li').children('a.arrow').children('img').attr('src', downImg);	
//	$('a.up').parent('li').children('a.arrow').children('img').attr('src', downImg);




	});



