// JavaScript Document

// Check xem trình duyệt là IE6 hay IE7
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);


function fixImageSize(height,width, maxWidth, maxHeight){
	// Check if the current width is larger than the max
	ratio		= maxWidth / width;   // Get ratio for scaling image
	w			= maxWidth;
	h			= height * ratio;    // Reset height to match scaled image
	// Check if current height is larger than max
	if(h > maxHeight){
		ratio	= maxHeight / height; // Get ratio for scaling image
		w		= width * ratio;    // Reset width to match scaled image
		h		= maxHeight;
	}
	return Array(parseInt(w), parseInt(h));
}





function tooltipProduct(ob){
	if(isIE6 || isIE7) return;
	var obj = ".show_tooltip  pre, .show_2tooltip pre";

	if(typeof(ob) != "undefined") obj = ob;

	j('pre').each(function(index, domEle){

		obTT	= j(domEle).parent().find(".tooltip");
		var img	= j(domEle).parent().find(".tooltip img");
		obTT.tooltip({
			bodyHandler: function(){
				tooltipWidth	= (typeof(obTT.attr("tooltipWidth")) != "undefined" ? obTT.attr("tooltipWidth") : 350);
				//j("#tooltip").css("width", tooltipWidth + "px");
                j("#tooltip").css("width", "auto");
                //alert(tooltipWidth);
				j(domEle).find(".picture, .picture_only").html(function(index, html){
					width			= (typeof(j(this).attr("width"))	!= "undefined" ? j(this).attr("width") : img.width());
					height		= (typeof(j(this).attr("height"))!= "undefined" ? j(this).attr("height") : img.height());
					maxWidth		= (typeof(j(this).attr("maxWidth"))	!= "undefined" ? j(this).attr("maxWidth") : 350);
					maxHeight	= (typeof(j(this).attr("maxHeight"))!= "undefined" ? j(this).attr("maxHeight") : 350);
					arrFixSize	= fixImageSize(height,width, maxWidth, maxHeight);
					return '<img width="' + arrFixSize[0] + '" height="' + arrFixSize[1] + '" src="' + j(this).attr("src") + '" />';
				});
				return j(domEle).html();
			},
			track: true,
			showURL: false,
			extraClass: "tooltip_product"
		});
	});
}


