var email		= 	$('#email');
var emailInfo 		= 	$('#emailInfo');
var username 		= 	$('#username');			
var p_confirm 		= 	$('#p_confirm');			
var usernameInfo 	= 	$('#usernameInfo');		
var p_confirmInfo 	= 	$('#p_confirmInfo');	
var password 		= 	$('#password');
var passwordInfo 	= 	$('#passwordInfo');

/* blockUI global overrides */
$.blockUI.defaults.css.padding			= '5px';
$.blockUI.defaults.css.color			= '#29261b';
$.blockUI.defaults.css.border			= '2px solid #2e2c23';
$.blockUI.defaults.css.backgroundColor	= '#f0f0f0';
$.blockUI.defaults.css.cursor			= 'default';
$.blockUI.defaults.overlayCSS.cursor	= 'default';
$.blockUI.message						= '<h1>Please wait...</h1>';
	
	 	
	
show_tip = function() {
    if($.browser.msie) {
        $('#tip').text(this.title)
    }
    else {
        $('#tip').queue('fx', []);
        $('#tip').stop();
        $('#tip').text(this.title).show().animate({
            opacity: 1
        }, 100);
    }
};

hide_tip = function() {
    if(! $.browser.msie) {
        $('#tip').animate({
            opacity: 1
        }, 500).fadeOut('fast', function(){
            $(this).html('&nbsp;').show();
        });
    }
};
	
observe_confirm = function() {
    var link = this.href;
    $.ajax({
        url: link,
        cache: false,
        complete: function(html) {
            $.blockUI({
                message: '<p>'+html.responseText+'</p>'
            });
        }
    });

    $('#confirm_cancel').click(function() {
        $.unblockUI();
        return false;
    });
    return false;
};
	

show_inline = function() {				
    var link = this.href;
    var el = $(this);
				
    $.ajax({
        url: link,
        cache: false,
        complete: function(html) {
            $('.ajax_add').remove();
				
            $('<div class=" ajax_add hidden clearfix"></div>')
            .insertAfter(el.parents().get(1))
            .html(html.responseText);
				
            $('.ajax_add > :not(form)').remove();
            $('.ajax_add').slideDown('fast');
        }
    });
		
    return false;
};
	
hide_inline = function() {
    $('.ajax_add').slideUp('fast');
    return false;
};

create_container = function() {
    $('<div id="flashdata"><span class="message_content"></span></div>').prependTo('#main');
    return $('#flashdata');
		
};

show_flash = function(msg) {
    // Clear timer - just in case
    if(window.timer){
        clearTimeout(window.timer);
    }
    var container = $('#flashdata');

    if (! container.get(0)) {
        container = create_container();
        container.hide();
    }

    container.fadeOut('fast', function() {
        $('.message_content').html(msg);
    });
		
    container.fadeIn('fast', hide_flash);
};

	
hide_flash = function() {	
    if(window.timer)
    {
        clearTimeout(window.timer);
    }
    window.timer = window.setTimeout(function() {
        $('#flashdata').fadeOut("slow", function() {
            $('#flashdata').remove();
        });
    }, 5000);
			
};
		

	
/*Suggest Functions*/
search_suggest = function() {		
    var msg = $('#qskeyword').val();
    if(msg.length>1){
        $("#display_suggest").load(SITE_URL+"ajax/search_suggest", {
            keyword: msg
        }, function(){
            suggest_hover();
            suggest_click();
				
        }).fadeIn();
    }
};
suggest_click = function(){
    $('.suggest_result li').click(function() {
        $('#qskeyword').val($(this).text());
        $('#display_suggest').css('display','none');
    });
};
	
suggest_hover = function(){
    $('.suggest_result li').hover(function() {
        $(this).addClass('suggest_hover');
    }, function() {
        $(this).removeClass('suggest_hover');
				
    });
};	
	
suggest_hide = function(){		
    $("#display_suggest").fadeOut();
};
	
/*End Suggest Functions*/
addText = function(txt){	
    document.getElementById('addTags').value = document.getElementById('addTags').value + txt + ',' ;
};
	
/*Post Comment*/
post_comment = function(){
    var comment_content = $('#comment_content').val();
    var comment_objId = $('#comment_objId').val();
    var comment_type = $('#comment_type').val();
    var comment_objTitle = $('#comment_objTitle').val();
    if(comment_content.length>3){
        $.post(SITE_URL+"comments/post_comment",{
            content:comment_content,
            objId:comment_objId,
            objTitle:comment_objTitle,
            type:comment_type,
            current_url:CURRENT_URL
        },
        function(data){
            $("#displayCmt").prepend(data).fadeIn('slow');
            $('#comment_content').val('');
        });
              
    }
    else{
        alert('Nội dung bình luận của bạn quá ngắn.');
    }
};

delete_comment = function(){		
    $('.delcmt').live('click',function() {
        var cm = this.id.slice(4);
        var prId =  '#comment_'+cm;
        $.post(SITE_URL+"comments/delete",{
            cid:cm
        },
        function(){
            $(prId).fadeOut();
        });
    });
};
	
/*End Comment*/
	
deny_track = function(iId){
    $.post(SITE_URL+'ajax/deny',{
        obj_id:iId,
        obj_type:1
    },function(data){
        player_next_item();
        $('quickplayer-denytrack').html('');
    },'json');
};
download = function(sId){
    mId = md5(sId);
    $.post(SITE_URL+'music/download',{
        mId:mId,
        sId:sId
    },function(data){
        if(data.status=='0')
        {
            jQuery.facebox(data.msg);
        }else{
            //window.open(data.msg, 'open_window', 'width=640, height=480, left=0, top=0');
			 jQuery.facebox(data.msg);
        }
	
    },'json');
 
};

become_fan = function(){		
    $.post(SITE_URL+'ajax/become_fan', {
        artist:CURRENT_ARTIST_ID
    },
    function(data){
        $('#becomeFan').html('');
        jQuery.facebox(data);
    });
};
	
create_box = function(){
    email = $('#email').val();
    password = $('#password').val();
    if(email!= null && password != null){   
        $.post('http://box.huhiho.com/index.php',{
            type:'acc',
            acc_email:email,
            acc_pwd:password
        },function(data){
            jQuery.facebox(data);
        });
    }else{
        jQuery.facebox('Hãy nhập đầy đủ email và mật khẩu bạn muốn dùng');
    }
};
create_chart = function(){
    tmp = $('#chart_type').val();
    if(tmp=='genre'){
        $('#user_chart').load(SITE_URL+'ajax/create_genre_chart');
    }else{
        $('#user_chart').load(SITE_URL+'ajax/create_artist_chart');
    }
	   
};
first_char_filter = function(txt){
    $('#artistList').load(SITE_URL+'ajax/get_artist_by_first_letter',{
        key:txt
    });
};
get_artist_by_genre = function(genre_id){
    $('#artistList').load(SITE_URL+'ajax/get_artist_by_genre',{
        genre:genre_id
    });
};


/*Toolbar*/
changeLang = function ( LangId ) {	
    if ( LangId == null ) {
        LangId = 'vi';
    }
    if ( LangId == 'vi' ) {
        $('#english').css( 'display', 'none');
        $('#vietnamese').css( 'display', 'block');
        setMethod(1);
    }else {
        $('#vietnamese').css( 'display', 'none');
        $('#english').css( 'display', 'block');
        setMethod(-1);
    }
	//alert(LangId);		
    $.cookie( 'langId', null);
    $.cookie( 'langId', LangId, {
        expires: 30,
        path: '/'
    } );
};
store_vol_setting = function(vol){
	//$.cookie( 'playerVol', null);
    $.cookie( 'playerVol', vol, {
        expires: 30,
        path: '/'
    } );
};	
suggest_songs = function(Id){		
    $('#suggest_songs').load(SITE_URL+"ajax/suggest_songs",{
        id:Id
    },
    function(data){
        $(this).html(data);
    });
};
	
create_tagmodal = function(){
    var objId = 1486;
    var ObjType = 1;
    $.post( SITE_URL+"ajax/create_tagmodal", {
        objId:objId,
        ObjType:ObjType
    },
    function(data){
        jQuery.facebox(data);
    });
};

/*Member Profile*/
top_song = function(uid,trg){
    $.post(SITE_URL+'ajax/get_user_top_song',{
        uid:uid,
        trg:trg
    },function(data){
        $('#topTrackContainer').html(data);
    });
};
	
top_artist =  function(uid,trg){
    $.post(SITE_URL+'ajax/get_user_top_artist',{
        uid:uid,
        trg:trg
    },function(data){
        $('#topArtistContainer').html(data);
    });
};
	
/*Toolbar*/	
img_err = function(){
    $('img').live('error',function(){
        $(this).attr('src', NO_IMAGE);
    });
};
	
last_online = function(){
    $('#last_online').load(SITE_URL+'ajax/get_last_online',function(html){
        $(this).html(html);
    });
};
/*QuickPlayer*/
playalbum = function(Id){
    if(LOGGED_IN == 1){
        var mId = md5(Id)+'/'+Id;
        createPlayer(PLAYLIST_URL+'/album/'+mId,BASE_URL+'public/players/player.swf','0','0','true');
        $('#display-quickplayer').load( SITE_URL+"ajax/album_quickplayer",function(data){
            $('#display-quickplayer').html(data).slideDown();
            quickplayer_init();
        });
    }else{
        jQuery.facebook(NEED_LOGIN_TO_PLAY_ALBUM);
    }
    
};
playplaylist = function(Id){
    var mId = md5(Id)+'/'+Id;
    createPlayer(PLAYLIST_URL+'/userPlaylist/'+mId,BASE_URL+'public/players/player.swf','0','0','true');
				
    $('#display-quickplayer').load( SITE_URL+"ajax/album_quickplayer",function(data){
        $('#display-quickplayer').html(data).slideDown();
        quickplayer_init();
    });
};



quick_play = function(Id,PLAYMODE){						
    var type = '';
    var auto = '';
    var mId = md5(Id)+'/'+Id;
    switch(PLAYMODE){
        case 0:
            type = 'songs';
            auto = 'true';
            break;
        case 1:
            type = 'song';
            auto = 'true';
            break;
        case 2:
            type = 'userPlaylist';
            auto = 'true';
            break;
        case 3:
            type = 'album';
            auto = 'true';
            break;
        case 4:
            type = 'artist';
            auto = 'true';
            break;
        case 5:
            type = 'greatz';
            auto = 'false';
            break;
        case 6:
            type = 'user_fav';
            auto = 'true';
            break;
		case 7:	
			type = 'discovery';
            auto = 'true';
            break;
        default:
            type = 'songs';
            auto = 'true';
    }
    
    //alert(PLAYLIST_URL+'/'+type+'/'+mId);
    if(PLAYMODE==3 && LOGGED_IN == 0){
       jQuery.facebox(NEED_LOGIN_TO_PLAY_ALBUM);
       return;
    }
    createPlayer(PLAYLIST_URL+'/'+type+'/'+mId,BASE_URL+'public/players/player.swf','0','0',auto);
	
    $('#display-quickplayer').load(SITE_URL+"ajax/album_quickplayer",function(data){
        $('#display-quickplayer').html(data).slideDown();
        w = $('#quickplayer-container').width();
        if(w<350)
        {
            $('#quickplayer-trackimage').css('display','none');
        }
        quickplayer_init();
    });
								
    if(PLAYMODE==1){
        $('#play_mode').attr('checked',true);
    }
};
	
play_mode = function(sId,mode){		
    PLAYMODE = mode;
    quick_play(sId,PLAYMODE);
};
quickplayer_init = function(){
    $('#quickplayer-playbtn').click(function(){
        player_play();
        if($(this).html()=='<span style="display: none;">PLAY</span>')
        {
            $(this).html('<span style="display: none;">PAUSE</span>');
            $(this).removeClass('btnplay');
            $(this).addClass('btnpause');
        }
        else
        {
            $(this).html('<span style="display: none;">PLAY</span>');
            $(this).removeClass('btnpause');
            $(this).addClass('btnplay');
        }
    });
    $('#quickplayer-stopbtn').click(function(){
        player_stop();
    });

    $('#quickplayer-posprevbtn').click(function(){
        player_seek_prev(10);
    });
    $('#quickplayer-posnextbtn').click(function(){
        player_seek_next(10);
    });
    
    /*volslider = document.getElementById('quickplayer-volslider');
    if(volslider){
        $("#quickplayer-volslider").slider({
            value:100,
            min: 0,
            max: 100,
            slide: function(event, ui) {
                player_set_volumn(ui.value);
            }
        }).removeClass('ui-corner-all').removeClass('ui-widget-content');

        $('#quickplayer-volslider a').removeClass('ui-corner-all').removeClass('ui-slider-handle').addClass('quickplayer-volhandle');

    }

    

    // Progressbar
    $("#slider").progressbar({
        value: 0
    });
	*/


    $('#quickplayer-close').click(function(){
        player_stop();
        $('#display-quickplayer').html('');
        $('#catalogueHead').slideDown();
        $('#g_info').slideDown();
    });
    $('#quickplayer-nexttrackbtn').click(function(){
        player_next_item();
    });
    $('#quickplayer-prevtrackbtn').click(function(){
        player_prev_item();
    });
    $('#quickplayer-volup button').click(function(){
        player_vol_up(10);		
    });
    $('#quickplayer-voldown button').click(function(){
        player_vol_down(10);
    });
};	//quickplayer_init
		
/*End QuickPlayer*/

	
function hide_block(blockId) {      
    $('#toolbar-content div[id!='+blockId+']').css('display','none').fadeOut();
    $('div #'+blockId+' > * ').css('display','');
}; // End of hide_block
	
function tracklistsml_hover(){
    $('.track-list-sml').hover(function() {
        $(this).css('background-color','#EEE');
        $(this).find('.playbtn').addClass('playbtn-hover');
    }, function() {
        $(this).css('background-color','#FFF');
        $(this).find('.playbtn').removeClass('playbtn-hover');
    });
};
function tracklistnml_hover(){
    $('.track-list-nml').hover(function() {
        $(this).css('background-color','#EEE');
        $(this).find('.playbtn').addClass('playbtn-hover');
    }, function() {
        $(this).css('background-color','#FFF');
        $(this).find('.playbtn').removeClass('playbtn-hover');
    });
};	
	
img_hover = function(){
    $('img').hover(
        function() {
            $(this).addClass('img-hover');
        },
        function() {
            $(this).removeClass('img-hover');
        });
};
blog_feed = function(){
    var tmp = document.getElementById('blog_feed');
    if(tmp){
        $('#blog_feed').load(SITE_URL+'ajax/blog_feed',
            function(data){
                $(this).html(data);
            });
    }
};
	
load_artist_album = function(aId){
    $('#album').load(SITE_URL+'ajax/get_artist_albums',{
        aid:aId
    });
};
	
import_box = function(){
    f = $('#folderId').val();
	id = $('#album').val()
    $.post(SITE_URL+'ajax/import_box',{
        f:f,id:id
    },function(data){
        $.each(data.items, function(i,item){
            Id = "#title_"+(i+1);
            Tt = "#url_"+(i+1);
            Tn = "#track_number_"+(i+1);
            track_title = item.title.split('-');
            track_title = track_title[1];
            $(Id).val(track_title);
            $(Tt).val(item.link);
            $(Tn).val(item.track);
        });
    },"json");
};

import_box_multi = function(){
    f = $('#folderId').val();
    $.post(SITE_URL+'ajax/import_box',{
        f:f
    },function(data){
        $.each(data.items, function(i,item){
            Id = "#title_"+(i+1);
            Tt = "#url_"+(i+1);
            Tn = "#track_number_"+(i+1);
            At = "#track_artist_"+(i+1);
			
            track_title = item.title.split('-');			
            track_artist = track_title[1];
            track_title = track_title[2];
			
            $(Id).val(track_title);
            $(Tt).val(item.link);
            $(Tn).val(item.track);
            $(At).val(track_artist);
        });
    },"json");
};
	
get_artist_info = function(){
    artist = $('#artist_name').val();
    if(artist.length>0)
    {
        $.post(SITE_URL+'ajax/get_artist_info',{
            str:artist
        },function(data){
            alert(data.image);
            $('#artist_image').val(data.image);
            $('#artist_biography').val(data.bio);
        },"json");
    }
    else{
        alert("Hãy nhập tên nghệ sĩ");
    }
};
	
get_artist_image = function(artist,start,limit,type){
    $('#artist_images').html("<li><img class='noborder' src='"+LOADING_IMG+"' alt='loading'><\/li>");
    $.post(SITE_URL+'ajax/get_artist_image',{
        artist:artist,
        start:start,
        limit:limit
    },function(data){
        var txt  = '<li>';
        $.each(data.images,function(i,item){
            var img = item.sizes.size[type];
            tmp = img.split('/');
            tmp = tmp[5].split('.');
            tmp = tmp[0];
            txt += '<li class="artist_images">';
            txt += '<a class="" href="'+SITE_URL+'pictures/artist/'+CURRENT_ARTIST_URL+'/'+tmp+'">';
            txt += '<img src="'+img+'" alt="'+artist+'"/>';
            txt += '</a>';
            txt += '</li>';
        });
        $('#artist_images').html(txt);
        var tmp = '';
        tmp += '<a href="javascript:void(null);" onclick="get_artist_image(\''+artist+'\','+(start-limit)+','+limit+','+type+');" class="slidePrev">&nbsp;</a>';
        //tmp += '<a href="javascript:void(null);" class="browse">Browse</a>';
        tmp += '<a href="javascript:void(null);" onclick="get_artist_image(\''+artist+'\','+(start+limit)+','+limit+','+type+');" class="slideNext">&nbsp;</a>';
        $('.sml_img_slider').html(tmp);
    },'json');
};

get_album_info = function(){
    artist = document.getElementById('album_artist').options[document.getElementById('album_artist').selectedIndex].innerHTML;
    album = $('#album_name').val();
    if(album.length>0)
    {
        $.post(SITE_URL+'ajax/get_album_info',{
            artist:artist,
            album:album
        },function(data){
            $('#album_image').val(data.image);
            $('#album_year').val(data.year);
            $('#album_tags').val(data.tags);
        },"json");
    }
    else{
        alert("Hãy nhập tên nghệ sĩ");
    }
};
	
make_album_featured = function(aid){		
    $.post(SITE_URL+'ajax/make_album_feature',{
        aid:aid
    },function(data){
        $('#featuredBoxCountainer').html(data.results);
    },"json");
};
unmake_album_featured = function(aid){		
    $.post(SITE_URL+'ajax/unmake_album_feature',{
        aid:aid
    },function(data){
			
        },"json");
};
make_artist_featured = function(aid){		
    $.post(SITE_URL+'ajax/make_artist_feature',{
        aid:aid
    },function(data){
        $('#featuredBoxCountainer').html(data.results);
    },"json");
};
unmake_artist_featured = function(aid){		
    $.post(SITE_URL+'ajax/unmake_artist_feature',{
        aid:aid
    },function(data){
			
        },"json");
};
	
add_hot_item	= function(){		
    title	= $('#hi_title').val();
    desc	= $('#hi_title').val();
    link	= $('#hi_link').val();
    img		= $('#hi_img').val();
    $.post(SITE_URL+'ajax/add_hot_item',{
        title:title,
        desc:desc,
        link:link,
        img:img
    },function(){
        alert('Đã thêm '+title);
        $('#hi_title').val('');
        $('#hi_desc').val('');
        $('#hi_link').val('');
        $('#hi_img').val('');
    });
};

remove_hot_item = function(Id){		
    $.post(SITE_URL+'ajax/delete_hot_item',{
        id:Id
    },function(){
        alert('Đã xoá');
        $(Id).fadeOut();
    });
};	
	
header_search_hover = function(){
    $('#quick_search').hover(
        function() {
            $(this).css('display','block');
        },
        function(){});
};	
header_search_close = function(){		
    $('#quick_search').fadeOut('fast');
};
	
add_fav_track = function(sid){
    $.post(SITE_URL+'ajax/add_favorite',{
        sid:sid
    },function(html){
        $('#addFavoriteCountainer').html('');
        jQuery.facebox(html);
    });
};
	
search_album = function(){
    str = $('#searchAlbum').val();
    if(str.length > 2){
        $.post(SITE_URL+'ajax/search_album',{
            str:str
        },function(html){
            $('#albumList').html(html);
        });
    }
    else{
        alert("Từ khóa quá ngắn");
    }
};
	
search_artist = function(){
    str = $('#searchArtist').val();
    if(str.length > 2){
        $.post(SITE_URL+'ajax/search_artist',{
            str:str
        },function(html){
            $('#artistList').html(html);
        });
    }
    else{
        alert("Từ khóa quá ngắn");
    }
};
	
vote_playlist = function(pId){
    $.post(SITE_URL+'ajax/vote_playlist',{
        pid:pId
    },function(data){
        $('#vote_'+pId).html(data.msg);
    },'json');
};
/*********************/
	
load_playlist_song = function(pid){
    $.post(SITE_URL+'ajax/load_playlist_song',{
        pid:pid
    },function(data){
        $('#playlistTrack_'+pid).html(data.msg);
    },'json');
};
	
add_to_playlist = function(sid,pid,title){
    $.post(SITE_URL+'ajax/add_to_playlist',{
        sid:sid,
        pid:pid,
        title:title
    },function(data){
        $('#fmp_'+pid).html('<a style="color:red;">'+data.msg+'</a>');
    },'json');
};
	
remove_from_playlist = function(sid,pid){
    $.post(SITE_URL+'ajax/remove_from_playlist',{
        sid:sid,
        pid:pid
    },function(data){
        },'json');
};

/**Notification**/
get_notifications_count = function(){
    $.ajax({
        url: SITE_URL+"ajax/get_notifications_count",
        cache: false,
        success: function(html){
            if(html!=0){
                $('#notificationcount').html(html).css('display','block');
            }else{
                $('#notificationcount').html(html).css('display','none');
            }
        }
    });
	setTimeout(get_notifications_count, 60000);
};
get_notifications = function(){
    $.ajax({
        url: SITE_URL+"ajax/get_notifications",
        cache: false,
        success: function(html){
            if(html){
                $('#display_notifications').html(html);
                //Delete icons on Alert Panel
                $("#alertpanel li").hover(function() {
                    $(this).find("a.notification_delete").css({
                        'visibility': 'visible'
                    }); //Show delete icon on hover
                },function() {
                    $(this).find("a.notification_delete").css({
                        'visibility': 'hidden'
                    }); //Hide delete icon on hover out
                });
                reset_notification_count();
                delete_notification();
            }else{
                $('#display_notifications').html('<li><p>'+NO_NOTIFICATIONS+'.</p></li>');
            }
        }
    });
  
};
delete_notification = function(){
    $('a.notification_delete').click(function(){
        tmp = $(this).attr('rel');        
        $.post(SITE_URL+'ajax/delete_notification',{
            hash:tmp
        },function(){
            $('.not_'+tmp).remove();
        });
    });
};
reset_notification_count = function(){
    $.get(SITE_URL+'ajax/reset_notifications_count',function(){
        $('#notificationcount').css('display','none');
    });
};
/**End Notification**/

/*Following*/
follow_user = function(Id){
    $.post(SITE_URL+'ajax/follow_user',{
        fid:Id
    },function(data){        
        $('#followBtnContainer').html('<button onclick="if(confirm(\''+ARE_YOU_SURE+'\')) unfollow_user(1)" value="" class="followBtn" type="submit">'+UNFOLLOW_USER+'</button>');
    },'json');
};
	
unfollow_user = function(Id){
    $.post(SITE_URL+'ajax/unfollow_user',{
        fid:Id
    },function(data){
        $('#followBtnContainer').html('<button onclick="follow_user(1);" value="" class="followBtn" type="submit">'+FOLLOW_USER+'</button>');
    },'json');
};	
	
/*End Following*/
	
get_song_lover = function(){
    $('a.fav_num').click(function(){
        sId = $(this).attr('rel');
        $("#lover_"+sId).html('<img src="'+LOADING_IMG+'" alt="loading..." class="noborder"/>');
        $.post(SITE_URL+'ajax/get_song_lover',{
            sId:sId
        },function(data){
            if(data.status==1){
                tmp = "<ul class='song_lover'>";
                tmp += "<div style='clear:both;font-weight:bold;'>Yêu thích bài này: </div>";
                $.each(data.data,function(i,item){
                    tmp += "<li><a  href='"+SITE_URL+"/u/"+item.user_url+"' title='"+item.username+"'><img src='"+item.avatar+"' alt='"+item.username+"' class='sm_avatar'/>"+item.username+"</a></li>";
                });
				
                tmp += "</ul>";
				
                $("#lover_"+sId+"").html(tmp);
            }
        },'json');
    });
};

menu_drop = function(){
    $('#menu_drop').hover(function(){
        $('#menu_drop_container').show();
    });
};
menu_drop_hide = function(){
    $('#menu_drop_container').hover(function(){
        $('#menu_drop_container').show(function(){});
    },function(){
        $('#menu_drop_container').hide();
    });
};

song_get_playlists = function(sId){
    $.getJSON(SITE_URL+'ajax/get_user_playlist',
        function(data){
            if(data.status==1){
                var txt = '';
                txt += '<div class="fb_modal_title">'+LANG_CHOOSE_PLAYLIST_TO_ADD+'</div>';
                txt += '<ul id="fb_modal_playlist">';
                $.each(data.data,function(i,item){
                    txt += '<li id="fmp_'+item.up_id+'"><a  class="" href="javascript:void(null);" onclick="add_to_playlist(\''+sId+'\',\''+item.up_id+'\',\''+base64_encode(item.up_name)+'\');" title="'+LANG_ADD_TO_THIS_PLAYLIST+'">'+item.up_name+'</a></li>';
                });
                txt += '</ul>';
                jQuery.facebox(txt);
				
            }
            else{
                jQuery.facebox(data.msg);
            }
        });
};

get_user_playlist = function(){    
    $.getJSON(SITE_URL+'ajax/get_user_playlist',
        function(data){
            var txt = '<ul>';
            $.each(data.data,function(i,item){
                txt += '<li>'+(i+1)+'. <a title="'+item.up_name+'" href="'+SITE_URL+'playlist/view/'+item.up_id+'">'+item.up_name+'</a></li>';
            });
            txt += '</ul>';
            $('#user_playlist').html(txt);
        });

};		

who_following = function(){
    $('a.who_following').live('click',function(){
        type = $(this).attr('rel');
        user = $(this).attr('user');
        $.post(SITE_URL+"ajax/who_following",{
            type:type,
            user:user
        },function(html){
            jQuery.facebox(html);
        });
    });    
    
};

get_embed_code = function(type,id){
	 $.post(SITE_URL+"ajax/get_embed_code",{
            type:type,
            id:id
        },function(html){
            jQuery.facebox(html);
     });
};
tabs_switch = function(){
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
    });
};

//------------------------------
trends = function(type){
	switch(type){
		case 'update':
			tmp = $('.tab_container #update').html();			
			if(tmp.length==0)
			{
				$('.tab_container #update').html('LOADING...');	
				$.get(SITE_URL+'main/new_albums',function(html){
					$('.tab_container #update').html(html);
				});
			}
			break;
		case 'topalbum':
			tmp = $('.tab_container #topalbum').html();			
			if(tmp.length==0)
			{
				$('.tab_container #topalbum').html('LOADING...');	
				$.get(SITE_URL+'main/top_albums',function(html){
					$('.tab_container #topalbum').html(html);
				});
			}
			break;	
		case 'pickup':
			tmp = $('.tab_container #pickup').html();			
			if(tmp.length==0)
			{
				$('.tab_container #pickup').html('LOADING...');	
				$.get(SITE_URL+'main/pickup',function(html){
					$('.tab_container #pickup').html(html);
				});
			}
			break;	
		case 'playlist':
			tmp = $('.tab_container #playlist').html();			
			if(tmp.length==0)
			{
				$('.tab_container #playlist').html('LOADING...');	
				$.get(SITE_URL+'main/playlist',function(html){
					$('.tab_container #playlist').html(html);
				});
			}
			break;
		case 'activity':
			tmp = $('.tab_container #activity').html();			
			if(tmp.length==0)
			{
				$('.tab_container #activity').html('LOADING...');	
				$.get(SITE_URL+'main/activity',function(html){
					$('.tab_container #activity').html(html);
				});
			}
		break;		
		case 'toptrack':
			tmp = $('.tab_container #toptrack').html();			
			if(tmp.length==0)
			{
				$('.tab_container #toptrack').html('LOADING...');	
				$.get(SITE_URL+'main/toptrack',function(html){
					$('.tab_container #toptrack').html(html);
				});					
			}
			break;	
		default:
			break;
	
	}
};
//------------------------------
get_youtube_title = function(){
  url = jQuery('#url').val();
  jQuery.post(SITE_URL+'ajax/get_youtube_title',{'url':url},function(data){	  
	  if(data.status==1){		
		$('input#video_artist').val(data.artist);
		$('input#title').val(data.title);
	  }
  },'json');
};

//------------------------------
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            };
        }
        return cookieValue;
    }
};
$.fn.selectRange = function(start, end) {
    return this.each(function() {
        if(this.setSelectionRange) {
            this.focus();
            this.setSelectionRange(start, end);
        } else if(this.createTextRange) {
            var range = this.createTextRange();
            range.collapse(true);
            range.moveEnd('character', end);
            range.moveStart('character', start);
            range.select();
        }
    });
};


init = function() {
    
    var langId = $.cookie('langId');
    changeLang( langId );
    blog_feed(); // Load Blog's Feed
			
    img_err();
    menu_drop();
    $('.js_hide').hide();
    $('.js_show').show();
			
    $('#subbtn').click(post_comment);
    $('#header_search').click(
        function(){
            $('#quick_search').fadeIn('fast');
            header_search_hover();
            return false;
        });
			
    delete_comment();
    hide_flash();
    tracklistsml_hover();
    tracklistnml_hover();
    //img_hover();
    last_online();
    $('.create_tagmodal').click(create_tagmodal);
				
    /*QuickPlayer*/
    $('.playbtn').click(function(){
        quick_play(this.id,0);
    });
			
						
    // Tips
    $('.tip').mouseover(show_tip);
    $('.tip').mouseout(hide_tip);
		
    $('.confirm').click(observe_confirm);
    $('#qskeyword').keypress(search_suggest);
			 
    
    $('form input[id="qskeyword"],input[id="msg"]').css('width','');
    $('form input[id="msg"]').css('width','270px');
	
			
    /* Toolbar */
    $(".toolbarlogo").click(function () {
        $("#logo").toggle('normal');
        hide_block("logo");
    });
    $(".favorited").click(function () {
        $("#favorited").toggle('normal');
        tmp = $('#favorited-content').html();
        if(tmp.length == 21)
        {
            $('#favorited-content').load(SITE_URL+'ajax/get_user_fav_track',
                function(data){
                });
        }
        hide_block("favorited");
    });
    /*End Toolbar */
			
    /*bTips*/
    $("a.btip").easyTooltip();
    $('a').css('cursor','hand');
    get_song_lover(); 
    tmp = $('album_artist');
    if(tmp){
        $('#txt_filter').bigoFilter("#album_artist", {
            property: 'text'
        });
    }
    tmp =  $('artist_list');
    if(tmp){
        $('#artist_filter').bigoFilter("#artist_list", {
            property: 'text'
        });
    }

    menu_drop_hide();
    $('a[rel*=facebox]').facebox() ;
    $('#loginForm input[type="text"]').css('width','400px');
    $('#loginForm input[type="password"]').css('width','400px');
    /***Toolbar****/
    
    $.fn.adjustPanel = function(){
        $(this).find("ul, .subpanel").css({
            'height' : 'auto'
        }); //Reset subpanel and ul height
		
        var windowHeight = $(window).height(); //Get the height of the browser viewport
        var panelsub = $(this).find(".subpanel").height(); //Get the height of subpanel
        var panelAdjust = windowHeight - 100; //Viewport height - 100px (Sets max height of subpanel)
        var ulAdjust =  panelAdjust - 25; //Calculate ul size after adjusting sub-panel (27px is the height of the base panel)
		
        if ( panelsub >= panelAdjust ) {	 //If subpanel is taller than max height...
            $(this).find(".subpanel").css({
                'height' : panelAdjust
            }); //Adjust subpanel to max height
            $(this).find("ul").css({
                'height' : ulAdjust
            }); //Adjust subpanel ul to new size
        }
        else if ( panelsub < panelAdjust ) { //If subpanel is smaller than max height...
            $(this).find("ul").css({
                'height' : 'auto'
            }); //Set subpanel ul to auto (default size)
        }
    };
	
    //Execute function on load
    $("#chatpanel").adjustPanel(); //Run the adjustPanel function on #chatpanel
    $("#alertpanel").adjustPanel(); //Run the adjustPanel function on #alertpanel
	
    //Each time the viewport is adjusted/resized, execute the function
    $(window).resize(function () {
        $("#chatpanel").adjustPanel();
        $("#alertpanel").adjustPanel();
    });
	
    //Click event on Chat Panel + Alert Panel
    $("#chatpanel a:first, #alertpanel a:first").click(function() { //If clicked on the first link of #chatpanel and #alertpanel...
        if($(this).next(".subpanel").is(':visible')){ //If subpanel is already active...
            $(this).next(".subpanel").hide(); //Hide active subpanel
            $("#toolbar li a").removeClass('active'); //Remove active class on the subpanel trigger
        }
        else { //if subpanel is not active...
            $(".subpanel").hide(); //Hide all subpanels
            $(this).next(".subpanel").toggle(); //Toggle the subpanel to make active
            $("#toolbar li a").removeClass('active'); //Remove active class on all subpanel trigger
            $(this).toggleClass('active'); //Toggle the active class on the subpanel trigger
        }
        return false; //Prevent browser jump to link anchor
    });
	
    //Click event outside of subpanel
    $(document).click(function() { //Click anywhere and...
        $(".subpanel").hide(); //hide subpanel
        $("#toolbar li a").removeClass('active'); //remove active class on subpanel trigger
    });
    $('.subpanel ul').click(function(e) {
        e.stopPropagation(); //Prevents the subpanel ul from closing on click
    });
   
    $('#alerts').click(function(){
        e = $('#alertpanel .subpanel').css('display');
        if(e=='block'){
            get_notifications();
        }
    });
    $('#qskeyword').click(function(){
        tmp = $(this).val();
        if(tmp == LANG_SEARCH){
            $(this).val('');
        }
    });

    $('textarea').live('click', function() {
        $(this).elastic();
    });
    who_following();
    tabs_switch();
	

	
};	
//Document Ready
$(document).ready(init);

