$(function() {
	/*
	$('#Featured_Projects .item .thumb').each(function(index) {
		var action = $(this).find('a');
		var detail = $(this).find('.detail');
		
		$(this).find('a').mouseenter(function() {
			alert('enter');
		}).mouseleave(function() {
			alert('leave');
		});
	});
	*/
});

var HeaderImage = {
	images : null,
	pages : null,
	container : null,
	totalPage : null,
	totalWidth : null,
	imgWidth : 970,
	currentIndex : 0,
	
	init : function() {
        $(function() {
			HeaderImage._init();
		});
	},
	
	_init : function () {
		HeaderImage.images = $('#displayImage .mainpic img');
		HeaderImage.pages = $('#displayImage .pages li');
		HeaderImage.container = $('#displayImage .mainpic');
		
		HeaderImage.totalPage = HeaderImage.pages.length;
		HeaderImage.totalWidth = HeaderImage.imgWidth * HeaderImage.pages.length;
		
		HeaderImage.container.css({width: HeaderImage.totalWidth});
		
		HeaderImage.pages.each(function(index) {
			$(this).click(function() {
				HeaderImage.container.animate(
					{"marginLeft": -1 * HeaderImage.imgWidth * index},
					{duration: 1000, queue: false}
				);
				
				HeaderImage.pages.removeClass('active');
				$(this).addClass('active');
				
				HeaderImage.onPagingClick();
				
				return false;
			})
		});
		
		$("#displayImage").everyTime(5000,HeaderImage.autoPlay);
	},
	
	onPagingClick : function() {
		$("#displayImage").stopTime();
	},
	
	autoPlay : function() {
		HeaderImage.container.animate(
					{"marginLeft": -1 * HeaderImage.imgWidth * HeaderImage.currentIndex},
					{duration: 1000, queue: false}
				);
		
		HeaderImage.pages.removeClass('active');
		HeaderImage.pages.eq(HeaderImage.currentIndex).addClass('active');
		
		HeaderImage.currentIndex++;
		
		if(HeaderImage.currentIndex >= HeaderImage.totalPage)
			HeaderImage.currentIndex = 0;
	}
};

HeaderImage.init();
