
$(document).ready(function() {

/* 
 *
 * header
 *
 */


$('div.headerbox .links a').mouseenter(function() {
		$('div.headerbox .banner').addClass($(this).parent().attr('class'));
	}).mouseleave(function() {
		$('div.headerbox .banner').removeClass($(this).parent().attr('class'));
	});

$('div.jumps select').change(function() {
		if ($(this).val() != "-") {
			window.location = "/?c=" + $(this).val();
		}
	});


/* 
 *
 * jumpnav
 *
 */




$('.jumpnav .menu .comics')
	.mouseenter(function() {
		var widthBuffer = 10; // pixels on each side that contain the first/last item
		jumpnav = new Object;
		jumpnav = {
			offset: $(this).offset(),
			height: $(this).height(),
			width: $(this).width(),
			widthBuffer: widthBuffer,
			numsets: cdata['setdata'].length,
			setHeight: ($(this).height() / cdata['setdata'].length),
			set: -1,
			tag: -1
		};
		$('.jumpnav .menu').addClass("comics-on");
	})
	
	.mouseleave(function() {
		$('.jumpnav .menu').removeClass("comics-on");
		delete jumpnav;
	})
	
	.mousemove(function(e) {
		var thisX = e.pageX - jumpnav.offset.left;
		var thisY = e.pageY - jumpnav.offset.top;
		var newSet = Math.floor(thisY / jumpnav.setHeight);
		if (jumpnav.set != newSet) {
			jumpnav.set = newSet;
			jumpnav.tag = -1;
			$('.jumpnav .comics .set').html(cdata['settext'][jumpnav.set]);
		}

		var numTags = cdata['setdata'][jumpnav.set].length;
		var tagBoxWidth = (jumpnav.width - (jumpnav.widthBuffer * 2)) / numTags;
		
		if (thisX <= jumpnav.widthBuffer) {
			newTag = 0;
		} else if (thisX >= (jumpnav.width - jumpnav.widthBuffer)) {
			newTag = cdata['setdata'][jumpnav.set].length - 1; // last item in set
		} else {
			newTag = Math.floor((thisX - jumpnav.widthBuffer) / tagBoxWidth );
		}
		
		if (jumpnav.tag != newTag) {
			jumpnav.tag = newTag;
			$('.jumpnav .comics .tag').html(cdata['setdata'][jumpnav.set][jumpnav.tag]);
		}
		
	})
	
	.click(function() {
		if (jumpnav && jumpnav.tag != -1) {
			window.location.href = "/?jmp=c&c="+cdata['setdata'][jumpnav.set][jumpnav.tag].replace(/ /g, "_");
			delete jumpnav;
		}
	})	
		
	;
	

$('.jumpnav .menu .arcs')
	.mouseenter(function() {
		var widthBuffer = 10; // pixels on each side that contain the first/last item
		jumpnav = new Object;
		jumpnav = {
			offset: $(this).offset(),
			height: $(this).height(),
			width: $(this).width(),
			widthBuffer: widthBuffer,
			numArcs: cdata['arcdata'].length,
			arc: -1
		};
		$('.jumpnav .menu').addClass("arcs-on");
	})
	
	.mouseleave(function() {
		$('.jumpnav .menu').removeClass("arcs-on");
		delete jumpnav;
	})
	
	.mousemove(function(e) {
		var thisX = e.pageX - jumpnav.offset.left;
		var arcBoxWidth = (jumpnav.width - (jumpnav.widthBuffer * 2)) / jumpnav.numArcs;
		
		if (thisX <= jumpnav.widthBuffer) {
			newArc = 0;
		} else if (thisX >= (jumpnav.width - jumpnav.widthBuffer)) {
			newArc = cdata['arcdata'].length - 1; // last arc
		} else {
			newArc = Math.floor((thisX - jumpnav.widthBuffer) / arcBoxWidth );
		}
		
		if (jumpnav.arc != newArc) {
			jumpnav.arc = newArc;
			$('.jumpnav .arcs .arc').html(cdata['arcdata'][jumpnav.arc][0]);
		}
		
	})
	
	.click(function() {
		if (jumpnav && jumpnav.arc != -1) {
			window.location.href = "/?jmp=a&c="+cdata['arcdata'][jumpnav.arc][1];
			delete jumpnav;
		}
	})	
	
	;
	
$('.jumpnav .menu .close').mouseenter(function() {
		$('.jumpnav .menu').addClass("nothing-on");
	}).mouseleave(function() {
		$('.jumpnav .menu').removeClass("nothing-on");
	});
$('.jumpnav .toggle').click(function() {
	$('.comic-block .jumpnav .menu').toggle();
	$('.comic-block .jumpnav .menu-shadow').toggle();
	$('.jumpnav .menu').removeClass("nothing-on");
	});


$('.jumpnav .toggle').show();
   


});

