if(document.location.hash.length>0&&window.location.hash.substring(1,2)=="/") window.location=document.location.hash.substring(1);
var recentsTemplate='<li><a href="{1}" title="{0}">{0}</a></li>';
var ttcb_click;
var ttcb_w;
var ttcb_h;
function launchTagEditor1(param,w,h)
{
	if(!param) param = "pop-news-filter";
	$.fn.colorbox(
	{
		width: w + "px",
		height: h + "px",
		inline:true,
		href:"#" + param,
		open:true,
		opacity:0.5
	})
}
$(document).ready(function()
{
	var i_video = 0;
	$("#filter-customize a").click(function()
	{
		launchTagEditor($(this).attr('rel'));
		return false;
	});
	
	$("#footer-nav-right a").click(function()
	{
		ttcb_click	=	$(this).attr('rel_id');
		ttcb_w	=	$(this).attr('rel_w');
		ttcb_h	=	$(this).attr('rel_h');
		launchTagEditor1(ttcb_click,ttcb_w,ttcb_h);
		return false;
	});
	
	$("#link_rss").click(function()
	{
		ttcb_click	=	$(this).attr('rel_id');
		ttcb_w	=	$(this).attr('rel_w');
		ttcb_h	=	$(this).attr('rel_h');
		launchTagEditor1(ttcb_click,ttcb_w,ttcb_h);
		$("#rss").load(url_website + 'rss/ajax');
		return false;
	});
	

	
	$("#affiliates a").click(function()
	{
		ttcb_click	=	$(this).attr('rel_id');
		ttcb_w	=	$(this).attr('rel_w');
		ttcb_h	=	$(this).attr('rel_h');
		$("#" + $(this).attr('rel_id')).load(url_website + 'ajax/' + $(this).attr('rel_id'),function(){
					launchTagEditor1(ttcb_click,ttcb_w,ttcb_h);
			 });
		
		
		
		return false;
	});
	
	$("#latest-type li").click(function()
	{
		$(this).hasClass("active") || changeRecents($("#latest-type li").index(this));
		return false;
	});
	
	$("#latest-refresh").click(function()
	{
		refreshRecents()
	});
	
	$("#poll-nav span").click(function()
	{
		//$(this).hasClass("active")||changePoll($("#poll-nav span").index(this));
		//return false
		if($(this).index() == 0)
		{
			if(!$('.block_video').eq(i_video-1).length)
			{
				$(this).addClass("active");
				return false;
			}
			else
			{
				if(i_video-1 < 0){ 
					$(this).addClass("active");
					return false; 
				}
				else
				{
					$("#poll-nav").find('span').eq(1).removeClass("active");
					i_video--;	
				}
			}	
		}
		else
		{
			i_video++;
			if(!$('.block_video').eq(i_video+1).length)
			{
				$(this).addClass("active");
			}
			if($('.block_video').length -1  < i_video)
			{
				i_video = $('.block_video').length - 1;
				return false;
			}
			$("#poll-nav").find('span').eq(0).removeClass("active");
		}
		
		
		if(i_video==0)
		{
			$("#poll-nav").find('span').eq(0).addClass("active");
		}

		$('.poll-novote').html( $('.block_video').eq(i_video).find('textarea').eq(0).val() );
		$('.poll-results').html( $('.block_video').eq(i_video).find('textarea').eq(1).val() );
	});
	
	$("#pollSubmit").click(function()
	{
		votePoll();
		return false
	});
	$('.poll-novote').html( $('.block_video').eq(0).find('textarea').eq(0).val() );
	$('.poll-results').html( $('.block_video').eq(0).find('textarea').eq(1).val() );
	
});
function changePoll(b)
{
	$("#poll-bits li.active").removeClass("active");
	$("#poll-nav span.active").removeClass("active");
	$("#poll-nav span:eq("+b+")").addClass("active");
	$("#poll-bits > li:eq("+b+")").addClass("active")
}
function toggleFilter()
{
	$("#filter-panel").slideToggle(200);
	$("#filter-toggle").toggleClass("active");
	$("#filter").toggleClass("active")
}

function changeRecents(b)
{
	$("#latest-community-bits li.active").removeClass("active");
	$("#latest-type li.active").removeClass("active");
	$("#latest-type li:eq("+b+")").addClass("active");
	$("#latest-community-bits > li:eq("+b+")").addClass("active")
}

function refreshRecents()
{
	alert('Chức năng này hiện thời đang được xây dựng');
}




function launchTagEditor(param)
{
	if(!param) param = "pop-news-filter";
	$.fn.colorbox(
	{
		width:"400px",
		inline:true,
		href:"#" + param,
		open:true,
		opacity:0.5
	})
}


if(window.addEventListener)
{
	var kkeys=[],konami="38,38,40,40,37,39,37,39,66,65";
	window.addEventListener("keydown",function(b)
	{
		kkeys.push(b.keyCode);
		if(kkeys.toString().indexOf(konami)>=0)
		{
			kkeys=[];
			alert('a');
		}
	},true)
}

function konamiTriggered()
{
	switchStyleSheet("classic")
};
	
	
	
	
	
