﻿var hp_timer = null;
var hp_currentIndex = 0;
var slider = null;
var container = null;
var items = null;
var timeout = 5000;
var slideAnimationLength = 1000;

$(function () {
	//
	if($('div#slider').length == 0)
	{ 
		$('div#container').hide();
	}
	else
	{
		$('div#slider').appendTo($('div#container'));
		//
		// homepage image slider
		var slider = $('div#container');
		if (slider.length == 1) {
			// prepare
			container = slider.find('div#slider');
			items = container.find('div.imageBox');
			var totalW = 0;
			items.css('float', 'left').css('display', 'inline-block').each(function () {
				totalW += $(this).width();
			});
			container.width(totalW);
			// animate
			window.setInterval('ShowNext();', timeout);
		}
	}
	//
	var heightHeader = $('#header').height();
	var heightMain = $('#main').height();
	var heightContents = $('#contents').height();
	var heightPage = heightHeader + heightMain;
	//
	var listener = new Object();
	listener.onresize = function(size)
	{
		//alert('heightHeader:' + heightHeader + ' heightMain:' + heightMain + ' heightPage:' + heightPage + '| size.height:' + size.height );
		if(heightPage < size.height)
		{
			//alert('y ' + (size.height - heightHeader));
			$('#main').height(size.height - heightHeader -30);
		}
		
	};
	//
	resizeManager.addListener(listener);
	resizeManager.onresize();
});

function ShowNext() {
	// fix index
	var newIndex = hp_currentIndex + 1;
	if (newIndex > (items.length - 1)) newIndex = 0;
	hp_currentIndex = newIndex;
	// set visibility
	var offset = 0;
	for (var i = 0; i < newIndex; i++)
		offset += parseInt($(items[i]).width());
	container.animate({ 'margin-left': -offset }, { queue: false, duration: slideAnimationLength, easing: 'swing' });
};

