document.domain = "zing.vn";
ZM_WidgetBlog 			= new Object();
ZM_WidgetBlog.domain 	= 'http://wb.me.zing.vn/';
ZM_WidgetBlog.static 	= 'http://stc.wb.me.zdn.vn/';
var iframeLoaded=false;

ZM_WidgetBlog.hasScript=function(src){
	var scripts=document.getElementsByTagName('script');   
	for(i=0; i<scripts.length;i++){
		var script=scripts.item(i);
		if(script.src==src) {
			return true;
		}
	}
	return false;
}

ZM_WidgetBlog.include 	= function(file) {
   	if(ZM_WidgetBlog.hasScript(ZM_WidgetBlog.static  + file))
   		return;
   	var script  	= document.createElement('script');     
   	script.src  	= ZM_WidgetBlog.static  + file;  
   	script.type 	=  'text/javascript';  
   	script.defer 	= true;
	document.getElementsByTagName('head').item(0).appendChild(script);   
}

ZM_WidgetBlog.include('js/jquery.pack.js');
ZM_WidgetBlog.include('js/zmjsonp.js');


ZM_WidgetBlog.Init = function() {	
	var object = ZM_WidgetBlog.getObject();
	if (typeof object != 'undefined' && object != null && object.length > 0) {
        var url = ZM_WidgetBlog.BuildUrl(object[0]);        
		$.getJSON(url+"&jsoncallback=?",
        function(data){
			$("#ZM_BOX_BLOG").append(data.rs);
			iframeLoaded=true;
        });
    }
}

ZM_WidgetBlog.getAttribute = function(node,name){
    var result = null;
    if(node != null)
        result = node.getAttribute(name);
    if(result == null)
        result = "";
    return result;
}

ZM_WidgetBlog.setAttribute = function(node,name,value){
    if(node != null){
        node.setAttribute(name, value);
    }
}

ZM_WidgetBlog.getObject = function(){
    var obj = null;
    var node = window.document;
    obj = ZM_WidgetBlog.getElementsByClassName(node, "div", "ZM_BOX_BLOG");
    return obj;        
}

ZM_WidgetBlog.getElementsByClassName = function(node, tag, searchClass) {
	var classElements = [];
	node = node || document;
	tag = tag || '*';
	var tagElements = node.getElementsByTagName(tag);
	var regex = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
	for (var i=0, j=0; i < tagElements.length; i++) {
		if (regex.test(tagElements[i].className)) {
			classElements[j] = tagElements[i];
			j++;
		}
	}
	return classElements;
}

ZM_WidgetBlog.BuildUrl 	= function(object, page) {
	
    var url 		= ZM_WidgetBlog.domain + "index.php?wb=BOX_BLOG";
	var Connections = ZM_WidgetBlog.getAttribute(object,'connections');
	var Width 		= ZM_WidgetBlog.getAttribute(object,'width');
	var Height 		= ZM_WidgetBlog.getAttribute(object,'height');
	var ProfileId	= ZM_WidgetBlog.getAttribute(object,'profile_id');
	var Domain 		= ZM_WidgetBlog.domain;
    
	url += '&connections=' + Connections;
	url += '&width=' + Width;
	url += '&height=' + Height;
	url += '&profile_id=' + ProfileId;
	url += '&domain=' + ZM_WidgetBlog.domain;
	return url;
}

window.setTimeout('ZM_WidgetBlog.Init()', 1000);
