$(document).ready(function() {
				   
	var langId = $.cookie('langId');
	var styleId = $.cookie('style');
	
	if ( styleId != undefined ) {		
		changeStyle( styleId );
	}else {
		changeStyle('blue');
	}
	
	changeLang( langId );
	
	
	$('.box-video-playlist ul li').hover(
		function() {
			$(this).addClass('current2').css( 'cursor', 'pointer' );									  
		}, function() {
			$(this).removeClass('current2');	
		}
	);

	$('#mp3').click(
		  	function(){
				$(this).addClass('current');
				$('#img').removeClass('current');
				$('#web').removeClass('current');
				//document.boxsearch.action=base_url + "mp3/search/#play_song/1/0/";
		});
});

function closePopup() {
	$('#box-lyric-popup').fadeOut('slow');
	
};

function showPopup( id ) {	 
	var el = '#id-' + id;
	var lyric = $(el).html();
	var id2 = $(el) .attr("rel");
	var url = 'http://123.30.6.9:3760/GetItem.aspx?id=' + id2 + '&callback=?';
	$.getJSON(url,function(data){
	  if(data.ly){
	    $('#lyric-view').html( lyric  + Base64.decode(data.ly ));
	  }
	});
	$('#box-lyric-popup').fadeIn('slow');
};

function showLyric( id ) {	 
	var el = '#id-' + id;
	var lyric = $(el).html();	
	$('#lyric-view').html( lyric);	
	$('#box-lyric-popup').fadeIn('slow');
};

function openViewLyric( idBox ) {
	
	var cssName = $('a#a-' + idBox ).attr('class');
	var myText = $('#lyric_' + idBox );
	var myTextShow = $('#lyric_click_' + idBox );
	
	if ( cssName == 'title-up' ) {
		$( 'a#a-' + idBox ).removeClass().addClass( 'title');
		myText.css( {
			'height' : '70px',
			'display' : 'block' 
		});
		myTextShow.css('display' , 'none');
	}
	
	if ( cssName == 'title' ) {
		$( 'a#a-' + idBox ).removeClass().addClass( 'title-up');
		myText.css( 'display', 'none');
		myTextShow.css ({
			'display' : 'block',
			'height'  : 'auto'
		});
	}
};


// Thay doi style
function changeStyle( styleId ) {	
	var styleOld = $.cookie('style');
	
	$('a#' + styleOld ).css( 'border', '1px solid #FFF' );	
	
	// Set Cookie
	$.cookie( 'style', null); 
	$.cookie( 'style', styleId, { expires: 30, path: '/'}); 
	
	// Current
	$('a#' + styleId ).css( 'border', '1px solid #666' );
	changeCssFile( styleId );	
	
	// Thay doi logo
	$('#logo').attr({
		src: base_url + 'public/img/' + styleId + '.png',
		//src: base_url + 'public/logo/logo_halloween.jpg',
        title: 'NaisCorp.com',
		alt: 'NaisCorp.com',
		height: '128',
		width: '272'
		//height: '188',
		//width: '300'
	});
	
};

function changeCssFile( styleId ) {
	var css = document.getElementById ('css');
	var pathCss = base_url + 'public/css/';	
	css.href = pathCss + styleId + '.css';	
};

// Thay doi kieu go
function changeLang( LangId ) {
	
	if ( LangId == null ) {
		LangId = 'en';
	}
	
	if ( LangId == 'vi' ) {		
		$('#english').css( 'display', 'none');							 
		$('#vietnamese').css( 'display', 'block');
		setMethod(1); 
	}else {
		$('#vietnamese').css( 'display', 'none');							 
		$('#english').css( 'display', 'block');		
		setMethod(-1); 
	}
	
	$.cookie( 'langId', null);
	$.cookie( 'langId', LangId, { expires: 30,path: '/'} );
};

function showBox( id_box ) {
	
	if ( id_box == 1 ) {		
		$('#hidden-send').toggle('slow');
	}	
		
	if ( id_box == 2 ) {	
		$('#hidden-comment').toggle('slow');
	}			
};


function replacequery(str) {	
	str = ltrim(str);	
	var str2 = str.indexOf('.');
	if ( str2 == 0 ) { 
		str = str.replace('.', '');
	}
	str = str.replace(/ /g,'-');
	str = str.replace(/\%20/g,'-');
	str = str.replace(/\?/g,'');
	str = str.replace("\|",'');
	str = str.replace(/\//g,'');
	str = str.replace(/\\/g,'');
	return str
};

function ltrim(str){ 	
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
};
function rtrim_t(str) {
	if(str!=null){
		for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
			return str.substring(0,j+1);
	}else return "";
};
function trim(str) {
	return ltrim(rtrim_t(str));
};
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
};
/**
Ham thuc hien viecj replace query
**/
function ProcessQuery(strings){
	var str = "";
	 str = strings.replace(/-/g,' ');
	 str = str.replace(/'/g,'');
	 str = str.replace(/"/g,'');
	 return str;
};

function replacequery_search(str) {	
	//alert(str);
	str = trim(str);
	str 	= encodeURIComponent(str);
	//alert(str);
	str = ltrim(str);	
	var str2 = str.indexOf('.');
	if ( str2 == 0 ) { 
		str = str.replace('.', '');
	}
	//str = str.replace(/\+/g,'%2B');
	str = str.replace(/ /g,'+');
	str = str.replace(/\%20/g,'+');
	//str = str.replace(/\?/g,'%3F');
	//str = str.replace("\|",'%7C');
	//str = str.replace(/\//g,'%2F');
	str = str.replace(/\\/g,'%5C');
	return str
};
function replacequery_test(str) {	

	//str = str.replace(/\+/g,'%2B');
	str = str.replace(/\+/g,' ');
	return str
};

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
};
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
};
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
};
