/*** jQuery function calls for Kobo.co.uk ***/

var auroraMenuSpeed = 400;

$(document).ready(function() {
	
	//Open external links and PDFs in new browser tab/window
	$('a.external').click(function(){
		window.open(this.href);
		return false;
	});

	//Image gallery - Fancybox
	$("a.group").fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	600,
        'changeSpeed'   :   340,
        'titlePosition' :   'over',
		'overlayShow':	true
    });
	
	//Accordian navigation menu for Products pages
	$.cookie('testcookie' , 'expanded')
	var auroramenucount = 0;
	$('.auroramenu').each(function(){
		var auroramenuitemcount = 0;
		$(this).children('li').children('ul').each(function(){
			if($.cookie('arMenu_' + auroramenucount + '_arItem_' + auroramenuitemcount) == 1){
				$(this).siblings('a').attr('onClick' , 'auroraMenuItem(\'' + auroramenucount + '\' , \'' + auroramenuitemcount + '\' , \'0\'); return false;');
				$(this).parent().children('.aurorahide').css("display","inline");
				$(this).parent().children('.aurorashow').css("display","none");
			} else {
				$(this).css("display","none");
				$(this).siblings('a').attr('onClick' , 'auroraMenuItem(\'' + auroramenucount + '\' , \'' + auroramenuitemcount + '\' , \'1\'); return false;');
				$(this).parent().children('.aurorahide').css("display","none");
				$(this).parent().children('.aurorashow').css("display","inline");
			}
			auroramenuitemcount ++;
		});
		auroramenucount ++;
	});

});



//Defines function 'auroraMenuItem'
function auroraMenuItem(menu , item , show){
    $.cookie('arMenu_' + menu + '_arItem_' + item , show);
	var auroramenucount = 0;
	$('.auroramenu').each(function(){
		if(menu == auroramenucount){	
			var auroramenuitemcount = 0;
			$(this).children('li').children('ul').each(function(){
				if(item == auroramenuitemcount){
					if(show == 1){
						$(this).slideDown(auroraMenuSpeed);
						$(this).siblings('a').attr('onClick' , 'auroraMenuItem(\'' + menu + '\' , \'' + item + '\' , \'0\'); return false;');
						$(this).parent().children('.aurorahide').css("display","inline");
						$(this).parent().children('.aurorashow').css("display","none");
					} else {
						$(this).slideUp(auroraMenuSpeed);
						$(this).siblings('a').attr('onClick' , 'auroraMenuItem(\'' + menu + '\' , \'' + item + '\' , \'1\'); return false;');
						$(this).parent().children('.aurorahide').css("display","none");
						$(this).parent().children('.aurorashow').css("display","inline");
					}
				}
				auroramenuitemcount ++;
			});
		}
		auroramenucount ++;
	});
}