// This is the default Blueprint javascript lib for this site.
$(window).load(function(){
	//$("#comicPage").css('width', $("#comicPage ul li img").width());	
	//$("#comicPage").css('height', $("#comicPage ul li img").height());	
});

$(document).ready(function() {	
	$("#showDes").click(function() {
		$("#description").slideToggle();
		return false;
	});
	$("#featuredCycle").cycle({ 
	    fx:    'scrollHorz', 
	    delay: -2000,
	    next: '#next',
	    prev: '#prev'
	});

	$("#comicPage").cycle({
		fx: 'fade',
		timeout: 0,
		next: ".page_next",
		prev: ".page_prev",
		containerResize: 1
	});
	
	var count = 1;
	$("#comicPage li").each(function(index) {
		count = index;
	});

	count = count + 1;
	
	var currpage = 1;

	$(".comicPageNav span").html("Page " + currpage + " of " + count);
	
	
	$("a.page_next").click(function() {
		currpage = (currpage == count) ? 1 : currpage + 1;
		$(".comicPageNav span").html("Page " + currpage + " of " + count);
		return false;
	});
	
	$("a.page_prev").click(function() {
		currpage = (currpage == 1) ? count : currpage - 1;
		$(".comicPageNav span").html("Page " + currpage + " of " + count);
		return false;
	});
	

	$(".sub-node ul").each(function() {
		var menu_count = 0;
		$(this).children().each(function() {
			menu_count += 1;
		});
		if(menu_count < 7) {
			$(this).css("height", "auto");
		}
	});

	$(".sub-node").hide();
	$(".favorite-inside").hide();

	$('.first-node button').click(function() {
		var drop = $(this).parent().parent().find(".sub-node").css("z-index");
		var button = $(this).parent().css("z-index");
		button = (button == "3") ? "1" : "3";
		drop = (drop == "2") ? "0" : "2";
		$(this).parent().css("z-index", button);
		$(this).parent().parent().find(".sub-node").css("z-index", drop);
		$(this).parent().parent().find(".sub-node").slideToggle('fast', function() {
			/*var button = $(this).parent().find(".dropButton").css("z-index");
			var drop = $(this).css("z-index");
			button = (button == "3") ? "1" : "3";
			drop = (drop == "2") ? "0" : "2";
			$(this).parent().find(".dropButton").css("z-index", button);
			$(this).css("z-index", drop);*/
		});
		$('.first-node').toggleClass('expanded', "fast");
	});
	
	var debug = false;

	if(!debug) {
		$("#formStepTwo").hide();
		$("#formStepThree").hide();
		
		var step_one_height = $("#formStepOne").height();
		var step_two_height = $("#formStepTwo").height();
		var step_three_height = $("#formStepThree").height();
		
		var pageContent = $("#pageContent");

		pageContent.height(step_one_height);

		$("#stepOne span").css("color", "#ffffff");

		$("#gotoTwo").click(function() {
			$("#formStepOne").fadeOut();
			$("#stepOne span").css("color", "#616161");
			$("#stepTwo span").css("color", "#ffffff");
			pageContent.animate({
				height: step_two_height,
				}, 500, function() {
					$("#formStepTwo").fadeIn();
			});
			return false;
		});
		$("#gotoTwo2").click(function() {
			$("#formStepTwo").fadeOut();
			$("#stepOne span").css("color", "#ffffff");
			$("#stepTwo span").css("color", "#616161");
			pageContent.animate({
				height: step_two_height,
				}, 500, function() {
					$("#formStepOne").fadeIn();
			});
			return false;
		});
		$("#gotoThree").click(function() {
			$("#formStepTwo").fadeOut();
			$("#stepTwo span").css("color", "#616161");
			$("#stepThree span").css("color", "#ffffff");
			pageContent.animate({
				height: step_three_height
				}, 500, function() {
					$("#formStepThree").fadeIn();
			});
			return false;
		});
		$("#gotoThree2").click(function() {
			$("#formStepThree").fadeOut();
			$("#stepTwo span").css("color", "#ffffff");
			$("#stepThree span").css("color", "#616161");
			pageContent.animate({
				height: step_three_height
				}, 500, function() {
					$("#formStepTwo").fadeIn();
			});
			return false;
		});
	}

});

function prepare_email_message()
{
	$('#message').val(
		'Creator: ' + $('#from_name').val() + '\n'
		+ 'Role: ' + $('#role').val() + '\n'
		+ 'Email address: ' + $('#from_email').val() + '\n\n'
		+ 'Comic title: ' + $('#comic_title').val() + '\n'
		+ 'Synopsis: ' + $('#synopsis').val() + '\n'
		+ 'Chapter/Episode number: ' + $('#chapter_episode').val() + '\n'
		+ 'Series title: ' + $('#series_title').val() + '\n'
		+ 'Genre: ' + $('#select_genre').val() + '\n'
		+ 'File URL: ' + $('#file_location').val() + '\n'																												
	);
}
