// JavaScript Document
var isIE		= (navigator.userAgent.toLowerCase().indexOf("msie") == -1 ? false : true);
var isIE6	= (navigator.userAgent.toLowerCase().indexOf("msie 6") == -1 ? false : true);
var isIE7	= (navigator.userAgent.toLowerCase().indexOf("msie 7") == -1 ? false : true);
var isChrome= (navigator.userAgent.toLowerCase().indexOf("chrome") == -1 ? false : true);
// Show sản phẩm theo độ phân giải màn hình
function changeDataMatchResolution(sel){	
	if(sel == "") sel = ".list_sp:not(.fixed), .list_review:not(.fixed), .list_category:not(.fixed)";
	$(sel).each(function(index){		
		width		= (typeof($(this).attr("dataWidth")) != "undefined" ? $(this).attr("dataWidth") : (isIE ? 157 : 158));
		col		= (typeof($(this).attr("dataCol")) != "undefined" ? $(this).attr("dataCol") : 8);		
		numCol	= parseInt($(this).width() / width);
		if(numCol < 3) numCol = 3;
		if(numCol > col) numCol = col;
		colWidth	= 100 / numCol;
		if(isIE6 || isIE7) colWidth = colWidth - 0.1;		
		$(this).find(".fl").width(colWidth + "%");
		n = $(this).attr("dataLine") * numCol;		
		$(this).find(".fl:lt(" + n + ")").removeClass("hidden");
		if(n > 0) $(this).find(".fl:gt(" + (n-1) + ")").addClass("hidden");		
		// Trường hợp page_div nằm bên trong
		$(this).find(".page_div a, .page_div_top a").each(function(index2){
			$(this).attr("href", function(index3, attr){
				return changePageSize(attr, n);
			});
		});		
		// Trường hợp page_div nằm bên ngoài
		if($(this).hasClass("view_thumbnail_table") == true){
			$(this).parent().find(".page_div a, .page_div_top a").each(function(index2){
				$(this).attr("href", function(index3, attr){
					return changePageSize(attr, n);
				});
			});
		}		
	});	
}
// Resize window về đúng độ phân giải màn hình (Full Screen)
function resizeWindow(){	
	minWidth	= 994;
	bodyWidth= ($("#header").width() < minWidth ? minWidth : $("#header").width());
	if($("#container_body").width() == 1000) bodyWidth = 1000;
	
	$("#container_body, .header_bar").width(bodyWidth);
	search_keyword_width	 = bodyWidth - $(".header_search .search_help").outerWidth(true) -
													$(".header_search .search_in").outerWidth(true) -
													$(".header_search .search_text .left").outerWidth(true) - $(".header_search .search_text .right").outerWidth(true) - 2 -
													$(".header_search .search_area").outerWidth(true) -
													$(".header_search .statistic").outerWidth(true) -
													$(".header_search .register_estore").outerWidth(true);
	changeDataMatchResolution("");	
	$(".data_option:first").width($(".data_option_fixed:first").width() - 10);	
}
function initLoad(){	
	if(!isIE6){
		resizeWindow();
		$(window).resize(function(){
			resizeWindow();
		});
	}	
	initLoadMain();	
	if($("#container_body").width() >= 1120) $(".center_banner table td div").css("width", "auto");	
}
