﻿var count = 0;
function Advt_SetImageWidth(obj, src, width, height) {
    if(!width && !height) {

        if (count < 1) {
            obj.style.display = "none";
            setTimeout(function() { Advt_SetImageWidthTime(obj, src); }, 100);
        }
    }
    else
    {
	    obj.style.display = "block";
	    if (width)
	        obj.style.width = parseInt(width) + "px";
	    
        if(height)
            obj.style.height = parseInt(height) + "px";
    }
}

function Advt_SetImageWidthTime(obj, src) {   
    var width;
	var objParent = obj.parentNode;
	//Find Parent on offsetWidth > 0 To Body
	while(objParent && objParent != document.body)
	{
	    if(objParent.offsetWidth)
	        break;
	    objParent = objParent.parentNode;
	}
	//If offsetWidth > 0
	if (objParent && objParent.offsetWidth) {
	    //Set Width Between 32 to 500
	    if (objParent.offsetWidth < 500 && objParent.offsetWidth > 32) 
	        width = objParent.offsetWidth;
	    else if (objParent.offsetWidth < 32) 
	        width = 100; //Default Value
	    else 
	        width = 200;	    
	}
	else 
	    width = 200 //Default Value	
	obj.width = width;
	obj.style.width = width;
	if (src.indexOf('width') == -1)
	    obj.src = src + "&width=" + width;
	obj.style.display = "block";
	count += 1;
}

