// JavaScript Document
$(document).ready(function () {
	start_ani();
	slideshow_home();
	fix_font_size();
	$(window).scroll(fix_menu_pos);
});

var count = 0;
var timer2;
var direction = 0;
var timer3;

function start_ani()
{
	clearTimeout(timer3);
	timer2 = setInterval(animation, 100);
}

function animation()
{
	var $current = $('#topmenu #logo_hotpot_top img.current');
	if(direction == 0)
	{
		$next = $current.next();
	}
	else
	{
		$next = $current.prev();
	}
	
	$next.addClass('current');
    $current.removeClass('current');
	
	$current.css("visibility","hidden");
	$next.css("visibility","visible");
	
	if($next.hasClass('end'))
		direction = 1;
	else if($next.hasClass('start'))
	{
		direction = 0;
		count++;
	}
	if(count == 1)
	{
		count = 0;
		clearInterval(timer2);
		timer3 = setTimeout(start_ani, 3000);
	}
}

// Su dung thu vien fadeSlideShow (de hien thi slide o IE)
var t;
function slideshow_home()
{
	clearTimeout(t);
	$slide = $('#slide_home');
	if($slide.length == 0)
		return;
	
	var mygallery2 = new fadeSlideShow({
	wrapperid: "slide_home", //ID of blank DIV on page to house Slideshow
	dimensions: [700, 450], //width/height of gallery in pixels. Should reflect dimensions of largest image
	imagearray: imgarr,
	displaymode: {type:'auto', pause:3500, cycles:0, wraparound:false, randomize:false},
	persist: false, //remember last viewed slide and recall within same session?
	fadeduration: 1000, //transition duration (milliseconds)
	descreveal: "none",
	togglerid: ""
})
}
function fix_menu_pos()
{
	var header_h = $('#header').height() + $('#header').margin().bottom;
	var footer_h = $('#footer').height() + $('#footer').padding().top + $('#footer').padding().bottom;
	if($(window).scrollTop() >= header_h && $(window).height() > $('#sidebar').height() + footer_h)
		$('#sidebar').addClass('fixed');
	else
		$('#sidebar').removeClass('fixed');
}
function fix_font_size(){
	var names = $('.menu .foods .food .name.small');
	for (var i = 0; i < names.length; i++)
	{
		if($(names[i]).width() > 85)
		{
			$(names[i]).css('font-size', '80%');
			$(names[i]).css('line-height', '160%');
		}
	}
	var names = $('.menu .foods .food .name.small2');
	for (var i = 0; i < names.length; i++)
	{
		if($(names[i]).width() > 230)
		{
			$(names[i]).css('font-size', '90%');
			$(names[i]).css('line-height', '140%');
		}
	}
}
