mycarousel_initCallback = function(carousel) {
	carousel.clip.hover(function() {
			carousel.stopAuto();
	}, function() {
			carousel.startAuto();
	});

}

initContactForm = function()
{
	$("#contact").validate({
		rules: {
			name: "required",
			email: {
				required: true,
				email: true
			},
			subject: "required",
			message: "required"
		},
		messages: {
			name: "Bạn chưa nhập tên",
			email: "Địa chỉ email không hợp lệ",
			subject: "Bạn chưa nhập tiêu đề",
			message: "Bạn chưa nhập nội dung"
		},

		submitHandler: function(form) {
			$("button", form).attr("disabled", "disabled");
			$(form).ajaxSubmit({
				success: function(res) {
					var className;
					var html;
					
					if (res == 'OK')
					{
						alert('Đã gởi đi thư liên hệ của bạn');
						$("#contact").clearForm();
					}
					else
					{
						alert('Có lỗi. Vui lòng thử lại sau');
					}
					$("#contact").remove();
				}
			});
		}
	});
}


//$(function(){
	var init = {
		home : true,
		gioi_thieu : false,
		san_pham : false,
		lien_he : false
	};
	
	swfobject.embedSWF("/images/mediaplayer.swf", "video", "382", "290", "9.0.0", "/images/expressInstall.swf", {
		file : '/images/video.flv',
		image : '/images/thumb.jpg',
		width : 382,
		height : 290
	}, {
		wmode : 'opaque',
		allowfullscreen : 'true',
		allowscriptaccess : 'always'
	});
	
	
	
	
	swfobject.embedSWF("/images/banner.swf", "logo", "1151", "105", "9.0.0", "/images/expressInstall.swf", {}, {wmode : 'transparent'});
	
	
	swfobject.embedSWF("/images/cup.swf", "flash-cup", "368", "410", "9.0.0", "/images/expressInstall.swf", {}, {wmode : 'transparent', quality:'medium'});
	
	// swfobject.embedSWF("/images/cup-small.swf", "slideshow", "382", "120", "9.0.0", "/images/expressInstall.swf", {}, {wmode : 'transparent'});
	
	$("#content").scrollTo("#home");
	
	$("#menu a").click(function(e){
		e.preventDefault();
		
		$("#menu a").css("background-position","0px 0px");
		$(this).css("background-position","0px -50px");
		
		var id = $(this).attr("href").replace(/\/\#\/([\w\W]*)\/the\-gioi\-phang\.html/, "#$1");
		
		if (id == '#gioi-thieu')
		{
			if (!init.gioi_thieu)
			{
				init.gioi_thieu = true;
				$('#gioi-thieu .content').jScrollPane();
			}
		}
		else if (id == '#san-pham')
		{
			if (!init.san_pham)
			{
				init.san_pham = true;
				
				$("#tabs a").blend();
		
				$("#tabs").idTabs(function(id,list,set){ 
					$("a",set).removeClass("selected").filter("[href='"+id+"']",set).addClass("selected"); 
					for(i in list)
					{
						$(list[i]).hide();
					}
					$(id).fadeIn(1000);
					return false;
				});
			}
		}
		else if (id == '#lien-he')
		{
			if (!init.lien_he)
			{
				init.lien_he = true;
				
				initContactForm();
			}
		}
		
		$("#content").stop().scrollTo(id, 'slow', {easing:'easeInOutExpo'});
	}).blend();
	
	
	
	
	/*
	$("#slideshow").slideshow({
		pauseSeconds	:	6,
		fadeSpeed		:	2,
		width			:	382,
		height			:	120,
		caption			:	false,
		auto			:	false
	});
	*/

	$('#carousel').css("display","block").jcarousel({
		scroll:1,
		auto:10,
		wrap: 'last',
		initCallback: mycarousel_initCallback

	});

	
	$("#carousel a[rel=brochure]").fancybox({
		overlayOpacity:0.5,
		overlayColor:'#301303',
		wrap:'both',
		speedIn:1200,
		changeSpeed:1000,
		changeFade:'slow'
	}).hover(function(){ $(this).click(); }, function() {});
	
	
	
//});

