﻿/* 
	Website: www.thangdc.com
	Phiên Bản: 1.1.0;
	Ngày: 23-02-2011;
	Tác giả: Đinh Công Thắng
	Hỗ trợ: thang@thangdc.com
	
	Cập Nhật: 27-02-2011
	Phiên Bản: 1.1.1
	Thay Đổi: Thêm Chức Năng Tạo Playlist bài hát ngẫu nhiên, kèm tiêu đề, hình ảnh, mô tả.
	
	Cập Nhật: 01-02-2011
	Phiên Bản: 1.1.1
	Thay Đổi: Thêm Chức Năng Tạo Bài Đăng Ngẫu Nhiêu Kèm Thumnail cho Blogger
*/

var ThangDC = new Object();
ThangDC.Domain = '';
ThangDC.Label = '';
ThangDC.MaxResult = '';
ThangDC.Container = '';

ThangDC.Tab = new Array('Tin Game', 'Máy Tính Bảng','Máy Tính Xách Tay','Điện Thoại Di Động');

ThangDC.Run = function(domain, label, maxresult, div){
	this.Domain = domain;
	this.Label = label.replace(/ /g,'%20');
	this.MaxResult = maxresult;
	ThangDC.GetJsonData(this.Domain, this.Label, this.MaxResult, div);	
};

ThangDC.AddScript = function(id, src){
	var DivID = document.getElementById(id);         
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = src;
	DivID.appendChild(script);
	try {
		DivID.appendChild(script);
	}
	catch (ex) {  }
}
ThangDC.GetJsonData = function(domain, label, maxresult, div){
	var JSONUrl = domain + '/feeds/posts/default/-/' + label + '?max-results=' + maxresult + '&alt=json-in-script&callback=?';
	 $.getJSON(JSONUrl, function(data) {
		$('#' + div).html(ThangDC.JsonData(data) + "<br/><div style=\"text-align:right;\"><a href=\""+ domain +"/search/label/"+ label +"\">Xem Tấc Cả</a></div>");
		ThangDC.TabEvent();
	 });
}

ThangDC.GetJsonTopNews = function(domain, label, maxresult, div){
	var JSONUrl = domain + '/feeds/posts/default/-/' + label + '?max-results=' + maxresult + '&alt=json-in-script&callback=?';
	$.getJSON(JSONUrl, function(data) {
		
			$('#' + div).html(ThangDC.JsonTopNewsData(data));
			ThangDC.HotNews('featured');
		
	 });
}
var total = 10;
var item = 5;
ThangDC.ShowRandomPost = function(domain, width, div, total, item){
	var JSONUrl = domain + '/feeds/posts/default?max-results=999999&alt=json-in-script&callback=?';
	$.getJSON(JSONUrl, function(data) {
		$('#' + div).html(ThangDC.RandomPost(data, width, total, item));
	 });
}

ThangDC.ShowNewPost = function(domain, width, div, item){
	var JSONUrl = domain + '/feeds/posts/default?max-results='+ item +'&alt=json-in-script&callback=?';
	$.getJSON(JSONUrl, function(data) {
		$('#' + div).html(ThangDC.GetNewPost(data, width));
	 });
}

ThangDC.JsonTopNewsData = function(json){
    var Post = '';
    var tab = '';
    var content = '';
	if(json.feed.entry != null){
		for (i = 0; i < json.feed.entry.length; i++) {
			var title = json.feed.entry[i].title.$t;
			var link = json.feed.entry[i].link[4].href;
			var description = json.feed.entry[i].content.$t;
			var img = $('img', description).attr('src');

			var temp = json.feed.entry[i].published.$t.substring(0, 19) + json.feed.entry[i].published.$t.substring(23, 29);

			timestamp = encodeURIComponent(temp);
			
			tab += '<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-' + (i + 1) + '"><a href="#fragment-' + (i + 1) + '"><img src="' + img + '" alt="" /><span>' + title + '</span></a></li>';
			content += '<div id="fragment-' + (i + 1) + '" class="ui-tabs-panel" style=""><div class="info" ><h2><a href="' + link + '" >' + title + '</a></h2><p>' + description + '</p></div></div>';
		}
		Post = '<ul class="ui-tabs-nav">'+ tab +'</ul><div class="contentNews">'+ content +'</div>';
	}
	return Post;
}

ThangDC.GetNewPost = function(json, width){
	var Post = '';
	for (i = 0; i < json.feed.entry.length; ++i) { 
		var title = json.feed.entry[i].title.$t;
		var link = "";
		var picture = "";
		
		var link = json.feed.entry[i].link[4].href;
		var description = json.feed.entry[i].content.$t;
		var img = $('img', description).attr('src');
		
		if(img != ""){	picture = '<img src="'+ img +'" style="border: 1px solid #CCC;float: left;margin-right: 5px;padding: 1px;width: 54px; height: 50px;" alt="'+ title +'"/>';	}
		
		for (var j = 0; j < json.feed.entry[i].link.length; ++j) {             
			if (json.feed.entry[i].link[j].rel == 'alternate') {                 
				link = json.feed.entry[i].link[j].href;
				break;             
			}
		}
		Post += "<li style=\"border-bottom: 1px solid #E1E1E1;float: left;padding: 7px 2px; width: "+ (width-4) +"px; background: none;list-style: none;\"><a href=\""+ link +"\" style=\"color:black;float: left;font: normal normal normal 12px/18px Tahoma;text-align: left;text-decoration:none;\">" + picture + title +"</a></li>"; 
	}
	return "<ul style=\"margin: 0 auto; padding:0;width:"+ width +"px;border: 1px solid #E1E1E1; border-bottom: 0;\">"+Post+"<br style=\"clear:both;\"/></ul>";
}
ThangDC.RandomPost = function(json, width, total, it){
	var maxEntries = total;
	var numPosts = json.feed.openSearch$totalResults.$t;
	var indexPosts = new Array();
	for (var i = 0; i < numPosts; ++i) {
		indexPosts[i] = i;     
	}     
	indexPosts.sort(function() {
		return 0.5 - Math.random()
	});     
	
	if (maxEntries > numPosts) {         
		maxEntries = numPosts;     
	}     
	
	var Post = '';
	var count = 0;
	var item = json.feed.entry;
	for (i = 0; i < maxEntries; ++i) {    
		var index = indexPosts[i];
		if(item[index] != null){
			var link = "";
			var picture = "";
			
			var title = item[index].title.$t;  
			var content = item[index].content.$t;
			var description = item[index].content.$t;
			var img = $('img', description).attr('src');
			
			if(img != ""){	picture = '<img src="'+ img +'" style="border: 1px solid #CCC;float: left;margin-right: 5px;padding: 1px;width: 54px; height: 50px;" alt="'+ title +'"/>';	}
			
			for (var j = 0; j < item[index].link.length; ++j) {             
				if (item[index].link[j].rel == 'alternate') {                 
					link = item[index].link[j].href;
					break;             
				}
			}
			
			if(count < it){ Post += "<li style=\"border-bottom: 1px solid #E1E1E1;float: left;padding: 7px 2px; width: "+ (width-4) +"px; background: none;list-style: none;\"><a href=\""+ link +"\" style=\"color:black;float: left;font: normal normal normal 12px/18px Tahoma;text-align: left;text-decoration:none;\">" + picture + title +"</a></li>"; }
			else{ break;	}
			
			count++;
		}
	}     
	return "<ul style=\"margin: 0 auto; padding:0;width:"+ width +"px;border: 1px solid #E1E1E1; border-bottom: 0;\">"+Post+"</ul><br style=\"clear:both;\"/>";
} 

ThangDC.JsonData = function(json){
	var Post = '';
	if(json.feed.entry != null){
		for (i = 0; i < json.feed.entry.length; i++) {
			var title = json.feed.entry[i].title.$t;
			var link = json.feed.entry[i].link[4].href;
			var description = json.feed.entry[i].content.$t;
			var img = $('img', description).attr('src');

			var temp = json.feed.entry[i].published.$t.substring(0, 19) + json.feed.entry[i].published.$t.substring(23, 29);

			timestamp = encodeURIComponent(temp);
			Post += '<div class="title"><a href="'+ link +'">'+ title +'</a></div>' + description + '<div style="clear: both"></div>';
		}
	}
	return Post;
}
ThangDC.JsonDataPaging = function(json){
	var Post = '';
	if(json.feed.entry != null){
		for (i = 0; i < json.feed.entry.length; i++) {
			var title = json.feed.entry[i].title.$t;
			var link = json.feed.entry[i].link[4].href;
			var description = json.feed.entry[i].content.$t;
			var img = $('img', description).attr('src');
			if(img != ""){	picture = '<img src="'+ img +'" alt="'+ title +'"/>';	}
			Post += '<li><a href="' + link + '">"' + picture + title + '</a></li>';
		}
	}
	return '<ul class=\"pgnews\">' + Post + '</ul><br style=\"clear:both;\"/>';
}

ThangDC.stripViet = function(str) {
	str= str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a");  
	str= str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e");  
	str= str.replace(/ì|í|ị|ỉ|ĩ/g,"i");  
	str= str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o");  
	str= str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u");  
	str= str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y");  
	str= str.replace(/đ/g,"d");  
	
	str= str.replace(/À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ/g,"A");  
	str= str.replace(/È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ/g,"E");  
	str= str.replace(/Ì|Í|Ị|Ỉ|Ĩ/g,"I");  
	str= str.replace(/Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ/g,"O");  
	str= str.replace(/Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ/g,"U");  
	str= str.replace(/Ỳ|Ý|Ỵ|Ỷ|Ỹ/g,"Y");  
	str= str.replace(/Đ/g,"D");  
	
	return str;
};

ThangDC.Trim = function(str){
	str = str.replace(/ /g,'');
	return str;
}

ThangDC.CreateTab = function(param){
	var result = '';
	var content = '';
	var active = '';
	result += '<ul class="menu">';
	for(i=0; i<ThangDC.Tab.length; i++){
		var stripcontent = ThangDC.stripViet(ThangDC.Tab[i]);
		var trimcontent = ThangDC.Trim(stripcontent);
		
		if(i==0){
			active = 'class="active"';			
		}
		else{
			active = '';			
		}
			
		result += '<li id="'+ trimcontent +'" '+ active +'>'+ ThangDC.Tab[i] +'</li>';
		
		content += '<div class="content '+ trimcontent +'">\
						<div id="tb'+ trimcontent +'"></div>\
					</div>';
	}
	result += '</ul>';
	result += '<span class="clear"></span>';
	result += content;
	
	ThangDC.LoadCSS();
	
	$('#' + param).html(result);
	
	ThangDC.LoadTabCss();
}

ThangDC.LoadTabCss = function(){
	for(i=0; i< ThangDC.Tab.length; i++){
		var stripcontent = ThangDC.stripViet(ThangDC.Tab[i]);
		var trimcontent = ThangDC.Trim(stripcontent);
		var classcss = '.' + trimcontent;
		
		if(i==0){
			$(''+classcss).show();
		}
		else{
			$(''+classcss).hide();
		}
	}
}

ThangDC.TabEvent = function(){
	$(".menu > li").click(function(e){		
		for(i = 0; i < ThangDC.Tab.length; i++)
		{
			var stripcontent = ThangDC.stripViet(ThangDC.Tab[i]);
			var trimcontent = ThangDC.Trim(stripcontent);
			if(e.target.id == trimcontent){
				$("#" + trimcontent).addClass("active");
				$("div." + trimcontent).fadeIn();
			}
			else
			{
				$("#" + trimcontent).removeClass("active");
				$("div." + trimcontent).css("display", "none");
			}
		}
	});
}

ThangDC.LoadCSS = function(){
	var sheet = document.createElement('style')
	var css = '';
	css += '* { margin: 0;padding: 0;}';
	css += '.clear{ clear: both; height: 0; visibility: hidden; display: block;}';
	css += 'a{ text-decoration: none;}';

	css += '#container{ width: 600px; margin: 5px;}';
	css += '#container ul{ list-style: none; list-style-position: outside;}';
	css += '#container ul.menu li{ float: left; margin-right: 5px; margin-bottom: -1px;}';
	css += '#container ul.menu li{ font-weight: 700; display: block; padding: 5px 10px 5px 10px; background: #efefef; margin-bottom: -1px; border: 1px solid #d0ccc9; border-width: 1px 1px 1px 1px; position: relative; color: #898989; cursor: pointer;}';
	css += '#container ul.menu li.active{ background: #fff; top: 1px; border-bottom: 0;color: #5f95ef;}';

	css += '.content{ margin: 0pt auto; background: #efefef; background: #fff; border: 1px solid #d0ccc9; text-align: left; padding: 10px; padding-bottom: 20px; font: 12px/18px Arial,Verdana}';
	css += '.content img { padding: 5px 5px 5px 0;}';
	css += '.content .title { color: #000BFF; font: bold 22px Arial,Helvetica,Sans-serif; text-decoration: none; text-shadow: 0 1px 0 #FFFFFF, 0 2px 4px #AAAAAA;}';
	css += '.content h1{ line-height: 1em; vertical-align: middle; height: 48px; padding: 10px 10px 10px 52px;font-size: 32px;}';
	
	sheet.innerHTML = css;
	
	document.body.appendChild(sheet);
}
ThangDC.LoadScrollNewsCss = function(div){
	var sheet = document.createElement('style');
	sheet.type = 'text/css';
	var css = '';
	css += '#' + div + '{width:345px; padding-right:250px; position:relative; border:5px solid #ccc; height:310px; background:#fff; margin-bottom: 5px;}';
	css += '#' + div + ' ul.ui-tabs-nav{ position:absolute; top:0; left:300px; list-style:none; padding:0; margin:0; width:295px; }';
	css += '#' + div + ' ul.ui-tabs-nav li{ padding:1px 0; padding-left:13px; font-size:12px; color:#666;}';
	css += '#' + div + ' ul.ui-tabs-nav li img{ float:left; margin:2px 5px; background:#fff; padding:2px; border:1px solid #eee;width: 50px;height: 50px;}';
	css += '#' + div + ' ul.ui-tabs-nav li span{ font-size:11px; font-family:Verdana; line-height:18px; }';
	css += '#' + div + ' li.ui-tabs-nav-item a{ display:block; height:60px; color:#333;  background:#fff; line-height:20px;text-decoration: none;}';
	css += '#' + div + ' li.ui-tabs-nav-item a:hover{ background:#f2f2f2; }';
	css += '#' + div + ' li.ui-tabs-selected{ background:url("Images/selected-item.gif") top left no-repeat; }';
	css += '#' + div + ' ul.ui-tabs-nav li.ui-tabs-selected a{ background:#ccc; }';
	css += '#' + div + ' .ui-tabs-panel{ width:300px; height:310px; background:#999; position:relative;}';
	css += '#' + div + ' .ui-tabs-panel .info{ position:absolute; left:0; height:310px; background: url("Images/transparent-bg.png"); }';
	css += '#' + div + ' .ui-tabs-panel .info img{ padding: 0 5px;}';
	css += '#' + div + ' .info h2{ font-size:18px; font-family:Georgia, serif; color:#fff; padding:5px; margin:0;overflow:hidden; }';
	css += '#' + div + ' .info > a {padding-left: 5px; }';
	
	css += '#' + div + ' .info p{ margin:0 5px; font-family:Verdana; font-size:11px; line-height:15px; color:#f0f0f0;}';
	css += '#' + div + ' .info a{ text-decoration:none; color:#fff; text-shadow: 0 1px 0 #FF00FF, 0 2px 4px #3C3C3C;}';
	css += '#' + div + ' .info a:hover{ text-decoration:underline; }';
	css += '#' + div + ' .ui-tabs-hide{ display:none; }';
	sheet.innerHTML = css;
	
	document.body.appendChild(sheet);
}
ThangDC.LoadScrollTinhYeu24hCss = function(div){
	var sheet = document.createElement('style');
	sheet.type = 'text/css';
	var css = '';
	css += '#' + div + '{width:408px; padding-right:250px; position:relative; border:1px solid #F6D97D; height:310px; background:#FEF4D1; margin-bottom: 5px;}';
	css += '#' + div + ' ul.ui-tabs-nav{ position:absolute; top:0; left:343px; list-style:none; padding:0; margin:0; width:315px; }';
	css += '#' + div + ' ul.ui-tabs-nav li{ padding:1px 0; font-size:12px; color:#666;}';
	css += '#' + div + ' ul.ui-tabs-nav li img{ float:left; margin:2px 5px; background:#fff; padding:2px; border:1px solid #eee;width: 50px;height: 50px;}';
	css += '#' + div + ' ul.ui-tabs-nav li span{ font-size:11px; font-family:Verdana; line-height:18px; }';
	css += '#' + div + ' li.ui-tabs-nav-item a{ display:block; height:60px; color:#333;  background:#fff; line-height:20px;text-decoration: none;}';
	css += '#' + div + ' li.ui-tabs-nav-item a:hover{ background:#FF0066; color: #fff;}';
	css += '#' + div + ' li.ui-tabs-selected{ background: #ff6734; }';
	css += '#' + div + ' ul.ui-tabs-nav li.ui-tabs-selected a{ background:#ff6734; color: #fff;}';
	css += '#' + div + ' .ui-tabs-panel{ width:300px; background:#FEF4D1; position:relative;}';
	css += '#' + div + ' .ui-tabs-panel .info{ position:absolute; left:0; height:310px;}';
	css += '#' + div + ' .ui-tabs-panel .info img{ padding: 0 5px;}';
	css += '#' + div + ' .info h2{ font-size:18px; font-family:Georgia, serif; color:#fff; padding:5px; margin:0;overflow:hidden; }';
	css += '#' + div + ' .info > a {padding-left: 5px; }';
	
	css += '#' + div + ' .info p{ margin:0 5px; font-family:Verdana; font-size:11px; line-height:15px; color:#000;}';
	css += '#' + div + ' .info a{ text-decoration:none; color:#FF0066; text-shadow: 0 1px 0 #ccc, 0 1px 1px #3C3C3C;}';
	css += '#' + div + ' .info a:hover{ text-decoration:none; }';
	css += '#' + div + ' .ui-tabs-hide{ display:none; }';
	css += '#' + div + ' .contentNews{ margin: 15px; }';
	
	css += '#pagingData { width: 657px; border: 1px solid #A2CCDB; background: url("https://lh5.googleusercontent.com/_jIZu46BgWOo/TXDh6zulBBI/AAAAAAAABFc/ZDQkpV5PUa4/postbg.png") repeat-x scroll 0 0 #FFFFFF}';
	css += 'ul.pgnews{margin: 2px auto; padding:0; border: 1px solid #E1E1E1; border-bottom: 0;}';
	css += 'ul.pgnews li {border-bottom: 1px solid #E1E1E1;float: left;padding: 7px 2px; width: 323px; background: none;list-style: none;}';
	css += 'ul.pgnews li:hover { background: #FF6734; color: #fff;}';
	css += 'ul.pgnews li a {color:black;float: left;font: normal normal normal 12px/18px Tahoma;text-align: left;text-decoration:none;}';
	css += 'ul.pgnews li a:hover {color: #fff;} ';
	css += 'ul.pgnews li a img {border: 1px solid #CCC;float: left;margin-right: 5px;padding: 1px;width: 54px; height: 50px;}';
	
	sheet.innerHTML = css;
	
	document.body.appendChild(sheet);
}

ThangDC.HotNews = function(div){
	$('#' + div + ' > ul').tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 5000, true); 
}


ThangDC.Cookie = new Object();
ThangDC.Cookie.Get = function(name){
	var i, x, y, ARRcookies = document.cookie.split(";");
	for (i = 0; i < ARRcookies.length; i++)
	{
		x = ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y = ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x = x.replace(/^\s+|\s+$/g,"");
		if ( x == name )
		{
			return unescape(y);
		}
	}
}

ThangDC.Cookie.Set = function(name, value, expried){
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expried);
	var c_value = escape(value) + ((expried == null) ? "" : "; expires="+ exdate.toUTCString());
	document.cookie = name + "=" + c_value;
}

ThangDC.Width = '250';
ThangDC.Height = '300';

//ThangDC.PlayList: (0, Title), (1, Link), (2, Description), (3, Image), (4, Link Embed)

ThangDC.PlayList = new Array();
ThangDC.AutoPlay = true;

ThangDC.CheckAutoPlay = function(pl, fx){
	var cookie = ThangDC.Cookie;
	var auto = cookie.Get('autoPlay');
	if(auto != null && auto != ""){
		ThangDC.Auto = auto;
	}
	else{
		cookie.Set('autoPlay', ThangDC.Auto, 1);
	}
	
	ThangDC.FixedBar.ShowAutoPlay(auto, fx, pl);
}

ThangDC.ChangeAutoPlay = function(pl, fx){
	$("input[name='IsAuto']").change(function(){
		var auto = $(this).val();
		ThangDC.FixedBar.ShowAutoPlay(auto, fx, pl);
	});
}

ThangDC.Player = function(title, url, description, picture, embedlink){
	var	auto1 = ''; var auto2 = '';
	if(ThangDC.AutoPlay) { auto1 = '<param value="&amp;autostart=true" name="flashvars"/>'; auto2 = ' flashvars="&amp;autostart=true';}
	return '\
	<div style="width: 250px; margin: 2px auto;">\
		<h4 style="margin:0; padding:0;">' + title + '</h4>\
		<div class="image">\
			<img src="'+ picture +'" alt="'+ title +'" width="100px" height="100px"/>\
		</div>\
		<p class="description" style="margin: 0; padding: 0; text-align: justify; padding-right: 5px;">'+ description +'</p>\
		<div style="margin: 5px 0;">\
			<object height="'+ ThangDC.Height +'" width="'+ ThangDC.Width +'">\
				<param value="'+ embedlink +'" name="movie"/>\
				<param value="high" name="quality"/>\
				<param value="transparent" name="wmode"/>'+ auto1 +'\
				<embed height="'+ ThangDC.Height +'" width="'+ ThangDC.Width +'"'+ auto2 +'" type="application/x-shockwave-flash" wmode="transparent" quality="high" src="'+ embedlink +'"></embed>\
			</object>\
		</div>\
	</div>';
}
ThangDC.RandomPlayList = function(pl){	
	var i = Math.floor(Math.random() * ThangDC.PlayList.length);	
	var title = ThangDC.PlayList[i][0];
	var url = ThangDC.PlayList[i][1];
	var description = ThangDC.PlayList[i][2];
	var picture = ThangDC.PlayList[i][3];
	var link = ThangDC.PlayList[i][4]; 	
	$(pl).html(ThangDC.Player(title, url, description, picture, link));
}

ThangDC.FixedBar = new Object();
ThangDC.FixedBar.ShowAutoPlay = function(isauto, fx, pl){		
	var cookie = ThangDC.Cookie;
	var btRadio = '';
	if(isauto == 'true') { 
		btRadio = '<label><input type="radio" name="IsAuto" value="true" checked="checked" /> Bật</label> <label><input type="radio" value="false" name="IsAuto"/> Tắt</label>';
		cookie.Set('autoPlay', 'true', 1);
		ThangDC.AutoPlay = true;
	}
	else{ 
		btRadio = '<label><input type="radio" name="IsAuto" value="true"/> Bật</label> <label><input type="radio" value="false" name="IsAuto" checked="checked" /> Tắt</label>';
		cookie.Set('autoPlay', 'false', 1);
		ThangDC.AutoPlay = false;
	}
	$(fx).html('Tự động Nghe Nhạc: ' + btRadio);
	ThangDC.ChangeAutoPlay(pl, fx);
	ThangDC.RandomPlayList(pl);
}

ThangDC.Themes = new Object();
ThangDC.Themes.Data = '';
ThangDC.Themes.ThemesIndex = 'Themes 1';

ThangDC.Themes.Select = function(obj){
	var result = '';	
	var cookie = ThangDC.Cookie;
	var index = cookie.Get('ThemesIndex');
	if(ThangDC.Themes.SelectIndex != null || ThangDC.Themes.SelectIndex != ""){
		ThangDC.Themes.ThemesIndex = index;
	}
	else{
		cookie.Set('ThemesIndex', ThangDC.Themes.ThemesIndex, 1);
	}
	for(var index in obj){
		if(index == ThangDC.Themes.ThemesIndex){
			result += '<option value="'+ index +'" selected="true">'+ index +'</option>';
		}
		else{
			result += '<option value="'+ index +'">'+ index +'</option>';
		}
	}
	ThangDC.Themes.Data = '<select name="selectThemes">'+ result +'</select>';
	$('#page').attr('style',obj[ThangDC.Themes.ThemesIndex]);
}
ThangDC.Themes.Change = function(obj){
	var cookie = ThangDC.Cookie;
	$("select[name='selectThemes']").change(function(){
		var themes = $(this).val();
		for(var index in obj){
			if(themes == index){
				ThangDC.Themes.ThemesIndex = index;
				cookie.Set('ThemesIndex', ThangDC.Themes.ThemesIndex, 1);
				$('#page').attr('style',obj[ThangDC.Themes.ThemesIndex]);
			}
		}
	});
}

ThangDC.ShowDateTime = function(param){
	var dt = new Date();
	var strMonth = new Array("01","02","03","04","05","06","07","08","09","10","11","12"); 
	var strDay = new Array("Chủ nhật", "Thứ hai", "Thứ ba", "Thứ tư", "Thứ năm", "Thứ sáu", "Thứ bảy"); 
	var date = strDay[dt.getDay()] + ", ";
	var years = dt.getYear();
	var days=dt.getDate();
	if (years<1900) years += 1900;
	if (days<10)
		date += "0" + dt.getDate() + "/" + strMonth[dt.getMonth()] + "/" + years;
	else
		date += "" + dt.getDate() + "/" + strMonth[dt.getMonth()] + "/" + years;
		
	var phut=dt.getMinutes();
	var giay=dt.getSeconds();
	if(phut<10)
	{          
		phut="0"+phut;
	}
	if(giay<10)
	{          
		giay="0"+giay;
	}
	if(document.getElementById(""+ param +"")!=null)
	{
		document.getElementById(""+ param +"").innerHTML=date+", "+dt.getHours()+":"+phut+":"+giay+" GMT+7";
	}    
} 


ThangDC.ChangePage = function(domain, index, item, divData){
	if(index > 1)		
		index = index * parseInt(item) - 4;
	else index = index;
	
	var JSONUrl = domain + '/feeds/posts/default/?start-index='+ index +'&max-results='+ item +'&alt=json-in-script&callback=?';
	$.getJSON(JSONUrl, function(data) {	
		$('#' + divData).html(ThangDC.JsonDataPaging(data));
	});
}

ThangDC.ShowPaging = function(domain, items, divPaging, divData){
	var pc = 100;
	var randomindex = Math.floor(Math.random() * pc);
	ThangDC.ChangePage(domain, randomindex, items, divData);
	var JSONUrl = domain + '/feeds/posts/summary/?alt=json-in-script&max-results=1&callback=?';
	$.getJSON(JSONUrl, function(json) {	
		var total = json.feed.openSearch$totalResults.$t;
		var pagecount = Math.ceil(total / items) - 1;
		$("." + divPaging).paginate({
			count 		: pagecount,
			start 		: randomindex,
			display     : 10,
			border					: true,
			border_color			: '#7BAF36',
			text_color  			: '#fff',
			background_color    	: '#9ED358',	
			border_hover_color		: '#ccc',
			text_hover_color  		: '#000',
			background_hover_color	: '#fff', 
			images					: false,
			mouse					: 'press',
			onChange				: function(page){
				ThangDC.ChangePage(domain, page, items,  divData);
			}
		});
	});
	
}

ThangDC.LoadPagingCSS = function(){
	var sheet = document.createElement('style');
	sheet.type = 'text/css';
	var css = '';
	css += '.jPaginate{ height:34px; position:relative; color:#a5a5a5; font-size:small; width:100%;}';
	css += '.jPaginate a{ line-height:18px; height:18px; cursor:pointer; padding:2px 5px; margin:2px; float:left;}';
	css += '.jPag-control-back{ position:absolute; left:0px;}';
	css += '.jPag-control-front{ position:absolute; top:0px;}';
	css += '.jPaginate span{cursor:pointer;}';
	css += 'ul.jPag-pages{float:left; list-style-type:none; margin:0px 0px 0px 0px; padding:0px; }';
	css += 'ul.jPag-pages li{ display:inline; float:left; padding:0px; margin:0px;}';
	css += 'ul.jPag-pages li a{ float:left; padding:2px 5px;}';
	css += 'span.jPag-current{ cursor:default; font-weight:normal; line-height:18px; height:18px; padding:2px 5px; margin:2px; float:left;}';
	
	css += '#pagingData { width: 657px; border: 1px solid #A2CCDB; background: url("https://lh5.googleusercontent.com/_jIZu46BgWOo/TXDh6zulBBI/AAAAAAAABFc/ZDQkpV5PUa4/postbg.png") repeat-x scroll 0 0 #FFFFFF}';
	css += 'ul.pgnews{margin: 2px auto; padding:0; border: 1px solid #E1E1E1; border-bottom: 0;}';
	css += 'ul.pgnews li {border-bottom: 1px solid #E1E1E1;float: left;padding: 7px 2px; width: 323px; background: none;list-style: none;}';
	css += 'ul.pgnews li:hover { background: #FF6734; color: #fff;}';
	css += 'ul.pgnews li a {color:black;float: left;font: normal normal normal 12px/18px Tahoma;text-align: left;text-decoration:none;}';
	css += 'ul.pgnews li a:hover {color: #fff;} ';
	css += 'ul.pgnews li a img {border: 1px solid #CCC;float: left;margin-right: 5px;padding: 1px;width: 54px; height: 50px;}';
	
	sheet.innerHTML = css;
	
	document.body.appendChild(sheet);
}

ThangDC.TVOnline = new Object();

ThangDC.TVOnline.Width = 350;
ThangDC.TVOnline.Height = 300;

ThangDC.TVOnline.Chanel = new Array();
ThangDC.TVOnline.Chanel['Tắt'] = '';
ThangDC.TVOnline.Chanel['THVL1'] = 'rtmp://123.30.108.77/live/THVL1';
ThangDC.TVOnline.Chanel['THVL2'] = 'rtmp://123.30.108.77/live/THVL2';
ThangDC.TVOnline.Chanel['THLA'] = 'mms://la34.com.vn/LA34 streaming                                                         - GDAGDASGDASGUEWIUR87326865874HDGFJB SJHDFU48384324938763HASFGD3287468732648RASFGASFDASF';
ThangDC.TVOnline.Chanel['THTG'] = 'mms://118.69.201.97/rtv';
ThangDC.TVOnline.Chanel['THĐT'] = 'mms://115.84.182.65/DongThap';
ThangDC.TVOnline.Chanel['ĐN1'] = 'rtmp://123.30.107.3:1935/live/dn1';
ThangDC.TVOnline.Chanel['ĐN2'] = 'rtmp://123.30.107.3:1935/live/dn2';
ThangDC.TVOnline.Chanel['BRT'] = 'rtmp://117.103.225.2/live';
ThangDC.TVOnline.Chanel['HauGiang'] = 'mms://118.69.155.1/thhg';
ThangDC.TVOnline.Chanel['BinhThuan'] = 'mms://123.30.108.114/BTVTruyenhinh';

ThangDC.TVOnline.ListChanel = function(div, pl){
	var result = '';
	for(var index in ThangDC.TVOnline.Chanel){
		result += '<option value="'+ index +'">'+ index +'</option>';
	}
	$(div).html('Xem TV Trực Tuyến: ' + '<select name="ListChanel">'+ result +'</select>');
	ThangDC.TVOnline.ChangeChanel(pl);
}

ThangDC.TVOnline.ChangeChanel = function(pl){
	var player = '';
	$("select[name='ListChanel']").change(function(){
		var index = $(this).val();
		var linkchanel = ThangDC.TVOnline.Chanel[index];
		if(index != 'Tắt'){
			if(linkchanel.indexOf('rtmp') != -1){
				if(index.indexOf('ĐN') != -1) {
					player = '<iframe frameborder="0" height="'+ ThangDC.TVOnline.Height +'" scrolling="no" src="http://thvl.vn/_player.swf?streamer=' + linkchanel + '&file=livestream&autostart=true" width="'+ ThangDC.TVOnline.Width +'"></iframe>';
				}
				else{
					player = '<iframe frameborder="0" height="'+ ThangDC.TVOnline.Height +'" scrolling="no" src="http://thvl.vn/_player.swf?streamer=' + linkchanel + '&file='+ index +'&autostart=true" width="'+ ThangDC.TVOnline.Width +'"></iframe>';
				}
				$(pl).html(player);
			}
			else if(linkchanel.indexOf('mms') != -1){
				player = '<embed type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" id="" name="" src="'+ linkchanel +'" autostart="1" clicktoplay="0" displaysize="4" autosize="-1" enablecontextmenu="1" volume="100" enablefullscreencontrols="1" enabletracker="1" mute="0" playcount="1" showcontrols="0" showaudiocontrols="1" showdisplay="0" showgotobar="0" showpositioncontrols="0" showstatusbar="1" showtracker="1" height="'+ ThangDC.TVOnline.Height +'" width="'+ ThangDC.TVOnline.Width +'">';
				$(pl).html(player);
			}
		}
		else{
			$(pl).html('');
		}
	});
}

ThangDC.LoadCategories = function(domain, name, div){
	var JSONUrl = domain + '/feeds/posts/default/-/' + name + '?max-results=6&alt=json-in-script&callback=?';
	$.getJSON(JSONUrl, function(data) {
		$('#' + div).html(ThangDC.JsonCategories(data, domain, name) + "<br/>");
	});
}

ThangDC.JsonCategories = function(json, domain, name){
	var Post = '';
	var related = '';
	if(json.feed.entry != null){
		for (i = 1; i < json.feed.entry.length; i++) {
			related += '<li><a href="'+ json.feed.entry[i].link[4].href +'">'+ json.feed.entry[i].title.$t +'</a></li>';
		}
		var title = json.feed.entry[0].title.$t;
		var link = json.feed.entry[0].link[4].href;
		var description = json.feed.entry[0].content.$t;
		var img = ($('img', description).attr('src').indexOf('blogger.googleusercontent.com') != -1 ? '' : $('img', description).attr('src'));
		var picture = (img != '' ? '<a href="'+ link +'"><img src="'+ img +'" alt="" width="100px" height="100px" align="left" border="0"/></a>' : '');	
		var desc = '';
		if(description.indexOf('span') != -1) {
			desc = $('span', description).html();
		}
		else{
			desc = $('p', description).html();
		}
		var summary = (desc.length <= 100 ? desc : desc.substr(0,100) + '...');
		Post = '<div class="categories"><div class="title"><a href="' + domain +'/search/label/' + name +'">'+ name +'</a></div><div class="content"><div class="maincontent">'+ picture +'<a href="'+ link +'" class="sub">'+ title + "</a><p>" + summary +'</p></div><div class="related"><ul>'+ related +'</ul></div><br class="clear"/></div></div>';
	}
	return Post;
}
