/* Author: 

*/

var $DYFooterFirstItem;
var $DYFooterOpenItem;
var DYFooterOpenWidth = 0;

$(function() {
	var w = 0;
	$('.DYFooterBoxContainer').each(function(index){
		w = $('.DYFooterBoxContainer:eq(' + index + ') .DYFooterTitle').width();
		$(this).width(w);
		$(this).attr('closeWidth', w);
	});
	
	$('.DYFooterBox').each(function(index){
		w = $('.DYFooterBoxContainer:eq(' + index + ') .DYFooterTitle').width();
		w += $('.DYFooterBoxContainer:eq(' + index + ') .DYFooterDirection').width() + 20;
		$(this).width(w);
		if (DYFooterOpenWidth < w) DYFooterOpenWidth = w;
	});
	
	$('.DYFooterBoxContainer').mouseenter(function() {
		if ($DYFooterOpenItem.index() != $(this).index()) {
			openItem($(this));
		}
	});
	
	$('.DYFooterBoxContainer').click(function() {
		if ($DYFooterOpenItem.index() != $(this).index()) {
			openItem($(this));
		}
	});
	
	$('#DYFooterContainer').mouseleave(function() {
		if ($DYFooterOpenItem.index() != 2) {
			openItem($DYFooterFirstItem);
		}
	});
	
	$DYFooterFirstItem = $('.DYFooterBoxContainer:eq(2)');
	openItem($DYFooterFirstItem);
});

function openItem($item) {
	if ($DYFooterOpenItem != undefined) closeItem($DYFooterOpenItem);
	$item.stop().animate({
		width:DYFooterOpenWidth}
	, 300);
	
	$title = $item.find('.DYFooterTitle');
	$title.css('background-color', '#5b9700');
	$title.css('color', '#FFF');
	$DYFooterOpenItem = $item;
}

function closeItem($item) {
	$item.stop().animate({
		width:$item.attr('closeWidth')}
	, 300);
	$title = $item.find('.DYFooterTitle');
	$title.css('background-color', '#d9d9d9');
	$title.css('color', '#666');
}























