$(function() {
	// doi ten theo the loai
	var query = location.search.replace(/\?g=|&g=/, '&genreid');
	query = query.replace(/\?t=2|&t=2/, '&singer');
	var text = ['', 'bài hát', 'bài hát', 'Album', 'Video Clip', '', 'Karaoke'];
	var index = $('a.searchtypeActive').attr('tabindex');
	if (!index || index == 'undefined') {
		index = 1;
	}
	$('div.title-Result').html($('div.title-Result').html().replace('bài&nbsp;hát', text[index]));
	$('div.group > h1').html($('div.group > h1').html().replace('bài&nbsp;hát', text[index]));
	if (query.search('genreid') != -1) {
		$('div.group > h1').html($('div.group > h1').html().replace('bài hát', 'bài hát theo thể loại'));
	}
	if (query.search('singer') != -1) {
		$('div.group > h1').html($('div.group > h1').html().replace('bài hát', 'bài hát của ca sĩ'));
	}
	
	// gan css cho tab search
	$('a.searchtype, a.searchtypeActive').each(function(){
		if (query.search('genreid') == -1) {
			$(this).attr('href', '/mp3/search/do.html?t=' + $(this).attr('tabindex') + '&q=' + $('input[name=keyword]').val());
		}
		if ($(this).attr('tabindex') == index) {
			$(this).removeAttr('href');
			$(this).addClass('CurType');
		}
	});
	
	// doi ten nguon neu bai hat lay tu nguon nao do
	$('span.upload_').each(function(){
		$(this).html('Nguồn');
	});
	$('span.uploadby_').each(function(){
		$(this).show();
	});
	
	// gan css cho cac dong cua ket qua tim kiem
	var i = 0;
	$('div.rwResult').each(function(){
		if (i % 2 == 1) {
			$(this).addClass('rwResult bg1');
		}
		i++;
	});
	
	// them border cho paging footer
	var i = 0;
	$('div.Nag').each(function(){
		if (i == 1) {
			$(this).addClass('Nag boderNag');
		}
		i++;
	});
	
	$('.boderalbum img').each(function(){
		//$(this).onerror(function(){alert('aaaaa')});
	});
});

$(document).ready(function() {
	if (location.pathname.search(/\/mp3\/search\/do.html|\/mp3\/search\/do.1.html/i) != -1 && location.search.search(/t=0|t=1|t=2/i) != -1) {
		var url		= '/mp3/searchapi/do.html';
		var keyword	= $('input[name=keyword]').val();
		if ($('#ajaxAlbum').length) {
			$.get(url, {'t': 3, 'q': keyword}, function(data) {
				$('#ajaxAlbum').html(data);
			});
		}
		if ($('#ajaxVideo').length) {
			$.get(url, {'t': 4, 'q': keyword}, function(data) {
				$('#ajaxVideo').html(data);
			});
		}
	}
});

