﻿var theWidth;
var theHeight;
var currentContent = 0;

$(window).resize(function () {
    sizeContent();
});

$(window).ready(function () {
    sizeContent();
});

function sizeContent() {
    theWidth = $(window).width();
	if ($(window).height() < 785) {
		theHeight = 800;
	} else {
    	theHeight = $(window).height();
	}
    sizeContentItems();
    setLeftOnContentItems();
    sizeContentWrapper(theWidth, theHeight);
    moveContent(currentContent, theWidth);
    changeSelected(currentContent);
	//マーク等の位置最調整
	positionTopParts();
	//ヘッダーのサイズ調整
	sizeContentHeader(theWidth);
}

function sizeContentItems() {
    $(".contentItem").css('width', theWidth);
    $(".contentItem").css('height', theHeight);
}

function setLeftOnContentItems() {
    var contentCount = 0;
    $(".contentItem").each(function (i) {
        contentCount += i;
        $(this).css('left', i * theWidth);
    });
}

function sizeContentWrapper(width, height) {
    $("#contentWrapper").css('width', width);
    $("#contentWrapper").css('height', height);
}

function moveContent(i, width) {
    $("#contentWrapper").scrollLeft(i * width);
}

function changeSelected(i) {
    $(".selected").removeClass("selected");
    $("li:eq(" + i + ") a").addClass("selected");
}

function sizeFootWrapper(width, height) {
    $("#triangle").css('width', width);
}

function scrollContentNext() {
    scrollContent(currentContent + 1);
}

function scrollContent(i) {
    i = checkMax(i);
    changeSelected(i)
    scrollFooter(i);
    currentContent = i;
    $("#contentWrapper").animate({ scrollLeft: i * theWidth }, 1000);
}

function checkMax(i) {
    var maxItems = $("li").length;
    if (i >= maxItems) {
        return 0;
    }
    return i;
}

// footerのスクロールに伴う再配置用
function scrollFooter(i) {
    var left = (i * $(window).width() +30);
    $("#footerArea").animate({ left: left }, 1000);
}

// topの各パーツの配置用
function positionTopParts() {
	$("#pbcyMark").css({
		position: "absolute",
		bottom: "150px",
		right: "15px"
	});
	$("#nav2").css({
		position: "absolute",
		top: "400px",
		left: "15px"
	});
}
// ヘッダーのサイズ調整用
function sizeContentHeader(width) {
    $("#header").css('width', width);
}


