
//$(function(){
//    $.extend($.fn.jScrollPane.defaults, {
//        showArrows:true,
//        scrollbarWidth:15,
//        arrowSize:16
//    });
//
//    $(window).bind('resize', setContainerHeight);
//    setContainerHeight();
//    correctScroll();
//
//// it seems like you need to call this twice to get consistantly correct results cross browser...
////setContainerHeight();
//});

var isResizing;

// and the body scrollpane
var setContainerHeight = function(){
    ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf("safari") == -1 && ua.indexOf("chrome") == -1){
        return;
    }
    // IE triggers the onResize event internally when you do the stuff in this function
    // so make sure we don't enter an infinite loop and crash the browser
    if (!isResizing) {
        isResizing = true;
        $w = $(window);
        $c = $('#superScroller');
        //$c = $('div:first').parent();
        var p = (parseInt($c.css('paddingLeft')) || 0) + (parseInt($c.css('paddingRight')) || 0);
        $('body>.jScrollPaneContainer').css({
            'height': $w.height() + 'px',
            'width': $w.width() + 'px'
        });
        $c.css({
            'height': ($w.height()-p) + 'px',
            'width': ($w.width() - p) + 'px',
            'overflow':'auto'
        });
        $c.jScrollPane();
        //$('body, html').css('overflow-y:', 'hidden');
        isResizing = false;
    }
}



var superMegoHeight = false;
function correctScroll(){
    setTimeout(correctScroll, 200);
    if (superMegoHeight === false){
        superMegoHeight = $('#superScroller').height();
        return;
    }

    h = $('#superScroller').height();
    if (h != superMegoHeight){
        superMegoHeight = h;
        setContainerHeight();
    }

}



var dragType = null;
var dragId = null;

var Dialog = function(){
  
}

Dialog.prototype.title = '';
Dialog.prototype.content = '';
Dialog.prototype.dialog = null;
Dialog.prototype.buttons = null;
Dialog.prototype.afterClose = null;
Dialog.prototype.open = null;
Dialog.prototype.visible = false;

Dialog.prototype.init = function(){
    this.dialog = $('<div title="' + this.title + '"><div class="contentContainer">' + this.content + '</div><div>');
    this.oldContent = $('.contentContainer', this.dialog).html();
    t = this;
    $(this.dialog).dialog({
        bgiframe: true,
        autoOpen: false,
        resizable: false,
        //draggable: false,
        width: 400,
        modal: true,
        buttons: t.buttons,

        close: function() {
            $('.contentContainer', this.dialog).html('');
            t.dialog.dialog('destroy');
            delete t.dialog;


            if (typeof t.afterClose == 'function'){
                //run callback function after closing of a dialog
                t.afterClose();
            }
            $(':droppable').droppable( 'enable' );
        },

        open: t.open

    });
}

Dialog.prototype.setContent = function(content, title){
    if (typeof content != 'undefined'){
        this.content = content;
    }
    if (typeof title != 'undefined'){
        this.title = title;
    }
};

Dialog.prototype.show = function(){
    this.dialog.dialog('open');
    $(':droppable').droppable( 'disable' );
    //alert('a');
    this.visible = true;
}

Dialog.prototype.close = function(){
    if (this.visible){
        this.dialog.dialog('close');
    }
    this.visible = false;
}

Dialog.prototype.isVisible = function(){
    return this.visible;
}



//Dialog for confirmation (yes/no)
var DialogConfirmation = function(){
 
}

DialogInstance = new Dialog();
DialogConfirmation.prototype = DialogInstance;
DialogConfirmation.prototype.parent = Dialog.prototype;
DialogConfirmation.prototype.onYes = null;
DialogConfirmation.prototype.onNo = null;

DialogConfirmation.prototype.show = function(message, title, onYes, onNo){
    //this.parent.init.call(this);

    this.setContent(message, title);

    if (typeof onYes == 'function'){
        this.onYes = onYes;
    }
    if (typeof onNo == 'function'){
        this.onYes = onNo;
    }

    var t = this;
  
    this.buttons = {
        'Да': function() {
            t.close();
            if (typeof t.onYes == 'function'){
                t.onYes();
            }
        },

        'Нет': function() {
            t.close();
            if (typeof t.onNo == 'function'){
                t.onNo();
            }
        }
    };
  
    this.init();
    this.parent.show.call(this);
  
}



//Dialog for show notification (like with alert)

DialogInstance = new Dialog();
var DialogNotification = function(){

}

DialogNotification.prototype = DialogInstance;
DialogNotification.prototype.parent = Dialog.prototype;

DialogNotification.prototype.show = function(message, title){

    this.setContent(message, title);
  
    t = this;
    this.buttons = {
        'Ок': function() {
            t.close();
        }
    };
    this.init();
    this.parent.show.call(this);
}

DialogInstance = new Dialog();
var DialogAddToPlayList = function(){

}

DialogAddToPlayList.prototype = DialogInstance;
DialogAddToPlayList.prototype.parent = Dialog.prototype;

DialogAddToPlayList.prototype.show = function(title, URL, params){
    ClassLoader.ShowBigLoader();
    t = this;

    $.ajax({
        data: params,
        type: 'get',
        url: URL,

        success: function(data){
            t.setContent(data, title);
            t.init();
            t.parent.show.call(t);
            if ($('.playListsPopUpList ul').height() > 130  ){
                $('.playListsPopUpList ul').height(130);
            }
            $('.playListsPopUpList ul').jScrollPane({
                showArrows:true,
                scrollbarWidth: 15,
                arrowSize: 16
            });
        },
        complete: function(){
            ClassLoader.HideBigLoader();
        },
        error: function(){
            alert('Не вышло получить список плейлистов от сервера', 'Ошибка!');
        }
    
    });
}

var dlgN;
var dlgConfirm;
var dllAddToPlayList;
$(function(){
    //var dialog = new Dialog();
    //dialog.init();
    //dialog.show();

    dlgConfirm = new DialogConfirmation();

    dlgN = new DialogNotification();
    if (clientId){
        dllAddToPlayList = new DialogAddToPlayList();
    }

    window.alert = function(message, title){
        dlgN.show(message, title);
    }
});


var preloadLngBarBackground = function (){
    var img1 = new Image();
    var img2 = new Image();
    var img3 = new Image();
    var img4 = new Image();
    var img5 = new Image();
    var img6 = new Image();
    var img7 = new Image();

    img1.src = 'views/default/images/langs-o.png';
    img2.src = 'views/default/images/langs-t.png';
    img3.src = 'views/default/images/langs-b.png';
    img4.src = 'views/default/images/langs-bg.png';
    img5.src = '/views/default/images/flags/fm.png';
    img6.src = '/views/default/images/flags/kz.png';
    img7.src = '/views/default/images/flags/ru.png';

}
var initRegionsFlags = function(){
    preloadLngBarBackground();
    //----Regions flags
    var regionsDisplayed = false;
    $('#regions > ul > li:first').addClass('first');
    $('#regions > ul > li:last').addClass('last');

    var timeoutId = null;
    // add display function
    var currentRegion = document.getElementById('regions');
    var regionsToShow = document.getElementById('regionlist');
    currentRegion.onmouseover = function(){
        if(timeoutId)
            clearTimeout(timeoutId);
      
        regionsToShow.style.display = 'block';
        timeoutId = null;
    }

    currentRegion.onmouseout = function(){
        timeoutId = setTimeout(function(){
            regionsToShow.style.display = 'none';
        }, 1000);
    }

    //hide flags
    $().click(function(){
        //if (regionsDisplayed){
        $('#regions > ul:visible').hide();
    //}else{
    // regionsDisplayed = true;
    //}
    });

/*
  //toggle flags
  $('#regions .langs').click(function(){
    $('#regions > ul').toggle();
      regionsDisplayed = false;
  });
     */
    
/*
    var showBlock = false;
    //$('#regions .langs').css('background-color', '#fff').css('border', '1px solid black').css('z-index', '2000').css('padding-top', '5px').css('display', 'block');
    $('#regions').css('background', 'red');
	$('#regions').hover(
		function(){
            if(!showBlock){
			    //$('#regions > ul').fadeIn("fast");
			    $('#regions > ul').show();
                showBlock = true;
            }
	    //regionsDisplayed = false;
		},
		function(){
			setTimeout(function(){
				    //$('#regions > ul').fadeOut("fast");
				    $('#regions > ul').hide();
                    showBlock = false;
				}, 500
			);
    //regionsDisplayed = false;
	});
     */
};
/*
var lettersBar = function(){
    //for letters bar
  $('.lettersContainer a img').bind('mouseover', function(){
    var a1 = $(this).parent().prev().css('z-index', 2001);
    var a2 = a1.prev().css('z-index', 2000);
    var b1 = $(this).parent().next().css('z-index', 2001);
    var b2 = b1.next().css('z-index', 2000);

    $('img', $(a1)).height("43px").css('margin-left', '-9px').css('margin-top', '-9px');
    $('img', $(a2)).height("30px").css('margin-left', '-3px').css('margin-top', '-3px');
    $('img', $(b1)).height("43px").css('margin-left', '-9px').css('margin-top', '-9px');
    $('img', $(b2)).height("30px").css('margin-left', '-3px').css('margin-top', '-3px');
    $(this).height("52px").css('margin-left', '-14px').css('margin-top', '-14px');
    $(this).parent().css('z-index', 2002);

  $('.lettersContainer a img').mouseout( function(){
    $(this).height("24px").css('margin-left', '').css('margin-top', '');
    var a1 = $(this).parent().prev().css('z-index', '10');
    var a2 = a1.prev().css('z-index', '10');
    var b1 = $(this).parent().next().css('z-index', '10');
    var b2 = b1.next().css('z-index', '10');

    $('img', $(a1)).height("24px").css('margin-left', '').css('margin-top', '').css('z-index', '10');
    $('img', $(a2)).height("24px").css('margin-left', '').css('margin-top', '').css('z-index', '10');
    $('img', $(b1)).height("24px").css('margin-left', '').css('margin-top', '').css('z-index', '10');
    $('img', $(b2)).height("24px").css('margin-left', '').css('margin-top', '').css('z-index', '10');
    $(this).parent().css('z-index', '10');
  });

  var padding = 3;
  var width = 24;
  var top = 10;

  //letter 24x25 margin:5px
  $('.lettersContainer').each(function(){
    var els = $('a', this);

    var n = els.length;
    var w = (width + padding) * n - padding;
    var left = parseInt(($(this).width() - w)/2);

    $(this).css('position', 'relative').css('text-align', 'left');

    for (var i = 0; i < n; i ++){
      els.eq(i).css('position', 'absolute').css('top', '10px').css('left', left).css('display', 'block').css('z-index', 10);
      els.eq(i).children().height('24px');
      left += (width + padding);
    }
  });  
}
 */

var scrollGenres = function(){
    var elsPerScreen = 2;
    var scrollBox = $('.genreScroller');
    scrollBox.children().wrap('<td></td>');
    scrollBox.children().wrapAll('<table><tr></tr></table>');
    var table = $('table', scrollBox);
    var elements = $('ul', table);
    var elCount = elements.length;
    var width = table.width();
    var elWidth = parseInt(width/elCount);
    var elNumber = 0;

    $('.next').click(function(){
        if (elNumber < elCount - elsPerScreen){
            table.animate({
                marginLeft:'-=' + elWidth
            }, 300);
            elNumber ++;
        }
        return false;
    });
    $('.prev').click(function(){
        if (elNumber > 0){
            table.animate({
                marginLeft:'+=' + elWidth
            }, 300);
            elNumber --;
        }
        return false;
    });
    scrollBox.css('visibility', 'visible');
}


//flash-alphabet(letters)
function checkURL(url){ // function which in this example is called to determine target, if for given link returns false it is opened in _self if true then _blank

    $.Ajaxor.goToLink(url);
    return false;
//return true;
}

function checkURLPlayList(url){ // function which in this example is called to determine target, if for given link returns false it is opened in _self if true then _blank
  
    ClassLoader.ShowSmallLoader('#pListRightBar');
    var separator = url.indexOf('?', 0) == -1 ? '?' : '&';
    
    url = encodeURI(url);
    $.getJSON('/playlist' + url + separator + 'elementsPerPage=' + calculateElementsCount(), function(data){
        $('#pListRightBar').html(data.html);

        Navigation.getNavigationInfo(0, function(){
            Navigation.initPlaylistNavButtons();
        });

        if ('undefined' != typeof(data.title) && data.title != '' ) {
            document.title = data.title;
        }
        
        $('#breadCrumbs').html(data.breadCrumbs);
        //$('#pListRightBar .site-navigator a[ajaxor]').ajaxor();
        handleArtists();
        player.handleAddArtistToPlayList();
    });
    document.location.href = '#' + navigationUrlParamCutter(url);
    return false;
//return true;
}


var handleDragArtists = function(data){

};

var handleArtists = function(){
    $('#pListRightBar .artistslist').draggable({
        cursor: "move",
        revert: true,
        revertDuration: 500,
        start:function(){
            dragType = 'artist';
            dragId = $(this).attr('value');
            //alert($(this).html());
            $(this).html($(this).html());
            player.handleAddArtistToPlayList($(this));
            return false;
        },
        stop:function(){
            dragType = null;
            dragId = null;
            return false;
        }
    });

    $('#pListRightBar .paginator a').click(function(){
        ClassLoader.ShowSmallLoader('#pListRightBar');
        $.getJSON($(this).attr('href'), function(data){
            $('#pListRightBar').html(data.html);
            
            Navigation.getNavigationInfo(0,function(){
                Navigation.initPlaylistNavButtons();
            });
            handleArtists();
        });

        return false;
    });
}

var initAlphabet = function(){
    var letters_url = 'views/default/images/letters/';
    var flashvars = {
        xmlURL : "letters.xml?" + PRODUCT_VERSION, // path to xml from which to take letters and links
        callbackFunctionName : "checkURL" // name of function to call to determine link target, if not supplied it opens in _self
    };
    var params = {
        wmode : "opaque" // sets flash mode to backgroundless and transperent
    }
    var attributes = {};
    attributes.id = "AlfavitHolder";
    swfobject.embedSWF(letters_url + "letters.swf?" + PRODUCT_VERSION , "lettersBar", "966", "75", "9.0.0", false, flashvars, params, attributes);
}

var initLettersAlphabet = function(){
    var letters_url = 'views/default/images/letters/';
    var flashvars = {
        xmlURL : "letters.xml?" + PRODUCT_VERSION, // path to xml from which to take letters and links
        callbackFunctionName : "checkURL" // name of function to call to determine link target, if not supplied it opens in _self
    };
    var params = {
        wmode: "opaque", // sets flash mode to backgroundless and transperent
        bgcolor: "#e9e9e9" 
    }
    var attributes = {};
    attributes.id = "AlfavitHolder";
    swfobject.embedSWF(letters_url + "letters.swf?" + PRODUCT_VERSION, "lettersLettersBar", "837", "75", "9.0.0", false, flashvars, params, attributes);
}

var initPlayListAlphabet = function(){
    var letters_url = 'views/default/images/letters/';
    var flashvars = {
        xmlURL : "letters.xml?" + PRODUCT_VERSION, // path to xml from which to take letters and links
        callbackFunctionName : "checkURLPlayList" // name of function to call to determine link target, if not supplied it opens in _self
    };
    var params = {
        wmode : "opaque", // sets flash mode to backgroundless and transperent
        bgcolor: "#e9e9e9"
    }
    var attributes = {};
    attributes.id = "AlfavitHolder";
    swfobject.embedSWF(letters_url + "letters.swf?" + PRODUCT_VERSION, "lettersPlayListBar", "837", "75", "9.0.0", false, flashvars, params, attributes);
}

var player = null;


//initialization of a buffa scripts
var initAllBuffaScripts = function (sector){

    if ('undefined' == typeof sector){
        $('a[ajaxor]').ajaxor({});
    }else{
        $('a[ajaxor]', sector).ajaxor({});
    }
    
    scrollGenres();
    initAlphabet();
    initPlayListAlphabet();
    initLettersAlphabet();
    player.handleStart();

    //initSliderList($('#artistAlbumns .panel .click'), '/Artist/AjaxAlbumSongs', player.handlePlayList, player, true);
    initSliderList($('#artistAlbumns .panel .click'), '/music/_AjaxAlbumSongs', player.handlePlayAndAddSongAction, player, true);
    initSliderList($('#userPlaylistsBlock .panel .click'), '/playlist/_AjaxPlaylistSongs', player.handleAllActions, player);
    $('#userPlaylistsBlock .jScrollPaneContainer').each(function(){
        if (!$(this).children().eq(0).children().length){
            $(this).hide();
        }
    });
    if ("undefined" != typeof initPen){
        initPen();
    }

    //alert('afas');


    //$('#search_field').focus();
    setTimeout(function(){
        //MSQsetContainerHeight();

//    if ($("#search_field").length){
//            $("#search_field").focus();
//        }else if ($('#searchInput').length){
//            $('#searchInput').focus();
//        }

//$(document).pngFix();
    }, 1000);
    initGeneralSearcHint();
}



$(function(){
    player =  new PlayerController();
    //initialization of a buffa scripts
    initAllBuffaScripts();
    initRegionsFlags();

});

var ajaxLoadArtistPage = function(artistUrl){ 
    ClassLoader.ShowSmallLoader('#pListRightBar');
    
    $.ajax({
        url: '/playlist/artist/' + encodeURIComponent(artistUrl),
        type : 'POST',
        dataType: "json",
        success : function(data){
            $('#pListRightBar').html(data.html);

            Navigation.getNavigationInfo(0,function(){
                Navigation.initPlaylistNavButtons();
            });

            $('#breadCrumbs').html(data.breadCrumbs);
        },
        data : {
            isAjax: 1
        }
    });

    document.location.href = '#/music/' + navigationUrlParamCutter(artistUrl);

    return false;
}

var ajaxLoadSongPage  = function(artistUrl, songUrl){
    ClassLoader.ShowSmallLoader('#pListRightBar');
   
    $.ajax({
        url: '/playlist/song/' + encodeURIComponent(artistUrl) + '/' + encodeURIComponent(songUrl),
        type : 'POST',
        dataType: "json",
        success : function(data){
            $('#pListRightBar').html(data.html);

            Navigation.getNavigationInfo(0,function(){
                Navigation.initPlaylistNavButtons();
            });
            
            $('#breadCrumbs').html(data.breadCrumbs);
        },
        data : {
            isAjax: 1
        }
    });

    document.location.href = '#/music/' + navigationUrlParamCutter(artistUrl + '/' + songUrl);

    return false;
}

var handleDragAlbum = function(){
    $('#pListRightBar .albumslist').draggable({
        cursor: "move",
        revert: true,
        revertDuration: 500,
        start:function(){
            dragType = 'album';
            dragId = $(this).attr('value');
            $(this).html($(this).html());
            player.handleAddAlbumToPlayList($(this));
            return false;
        },
        stop:function(){
            dragType = null;
            dragId = null;
            return false;
        }
    }); 
}

var ajaxLoadAlbumsPage = function(artistUrl){
    ClassLoader.ShowSmallLoader('#pListRightBar');
    var separator = artistUrl.indexOf('?', 0) == -1 ? '?' : '&';

    $.ajax({
        url: '/playlist/albums/' + encodeURIComponent(artistUrl) + separator + 'elementsPerPage=' + calculateElementsCount(),
        type : 'POST',
        dataType: "json",
        success : function(data){
            $('#pListRightBar').html(data.html);

            Navigation.getNavigationInfo(0,function(){
                Navigation.initPlaylistNavButtons();
            });
            $('#breadCrumbs').html(data.breadCrumbs);
            handleDragAlbum();
            player.handleAddAlbumToPlayList();
        },
        data : {
            isAjax: 1
        }
    });
    
    document.location.href = '#/music/' + navigationUrlParamCutter(artistUrl);

    return false;
}

var handleDragSongs = function(){
    $('#pListRightBar .track').draggable({
        cursor: "move",
        revert: true,
        revertDuration: 500,
        start:function(){
            dragType = 'song';
            dragId = $(this).attr('value');
            $(this).html($(this).html());
            //player.handleAllActions($(this));

            player.handlePlaySongItem($(this));
            player.handleAddSongItemToPlayList($(this));
            return false;
        },
        stop:function(){
            dragType = null;
            dragId = null;
            return false;
        }
    });
}

var ajaxLoadSongsPage = function(artistUrl, albumUrl){
    ClassLoader.ShowSmallLoader('#pListRightBar');

    $.ajax({
        url: '/playlist/songs/' + encodeURIComponent(artistUrl) + '/' + encodeURIComponent(albumUrl),
        type : 'POST',
        dataType: "json",
        success : function(data){
            $('#pListRightBar').html(data.html);

            Navigation.getNavigationInfo(0,function(){
                Navigation.initPlaylistNavButtons();
            });
            $('#breadCrumbs').html(data.breadCrumbs);
            player.handlePlayList($('#pListRightBar'));
            handleDragSongs();
            player.handleAddSongToPlayList();
        },
        data : {
            isAjax: 1
        }
    });
   
    document.location.href = '#/music/' + navigationUrlParamCutter(artistUrl);

    return false;
}

var showAutoCompleteHint = true;
var generalSearchStart = function(event){
    
    if ('undefined' != event && event){
        if(event.keyCode != 13 || $('li.ac_over').length){
            return true;
        }
    };

    var search =$('#search_field').val();
    if ($('.ac_results').length){
        showAutoCompleteHint = false;
    }
    $.ajax({
        url: '/Search/' + encodeURIComponent(search),
        type : 'POST',
        dataType: "json",
        success : function(data){
            
            $.Ajaxor.replacePage(data.content);

            Navigation.getNavigationInfo(0, function(){
                Navigation.initSiteNavButtons();
            });

            player.handleAddSongToPlayList($('#songs_result_list'));
            player.handlePlayList($('#songs_result_list'));
            document.location.href = '#/search/' + navigationUrlParamCutter(search);

            if ('undefined' != typeof(data.title) && data.title != '' ) {
                document.title = data.title;
            }
        },
        complete:function(){
        //showAutoCompleteHint = true;
        },
        data : {
            searchString: search,
            isAjax: 1,
            sObj: 'song'
        }
    });
    $('#search_field').unautocomplete();
    setTimeout(function(){
        //$('.ac_results').remove();
        }, 4000);
    return false;
}


var selectedText = '';
//for error mesages
$(document).keypress(function(event){

    if((event.ctrlKey) && ((event.keyCode == 0xA) || (event.keyCode == 0xD))){

        sendErrorData.idSended = getSelText();
        var artistLinkSender = new BuffaSender(sendErrorData);
        artistLinkSender.showDialog();
    }

    return true;
});


function getSelText(){
    var txt = '';
    if (window.getSelection){
        txt = window.getSelection();
    }else if (document.getSelection){
        txt = document.getSelection();
    }else if (document.selection){
        txt = document.selection.createRange().text;
    }
    return new String(txt);
}

function formatResult(row) {
    return row[0].replace(/(<.+?>)/gi, '');
}

var initGeneralSearcHint = function(){
    if ($("#search_field").length){
        var input = $("#search_field");
        var width = parseInt(input.width()) + 40;
        input.autocomplete('/search/_AjaxGetSearchHint', {
            width: width,
            matchContains: true,
            formatResult: formatResult,
            selectFirst: false,
            onChange:function(){
                generalSearchStart();
            }
        });
    }

};

var reloadSimplePaginator = function(url, idContainer, navigationParam){
    ClassLoader.ShowSmallLoader($('#' + idContainer));
    var params = 'undefined' != typeof navigationParam ? {
        isNavigator: 'true'
    } : {};
    if (url.indexOf('?') != -1){
        url += '&elementsPerPage=' + calculateElementsCount();
    }else{
        url += '?elementsPerPage=' + calculateElementsCount();
    }

    url = url.replace("[", "@LEFT@DELIMITER@");
    url = url.replace("]", "@RIGHT@DELIMITER@");
    url = encodeURI(url);
    url = url.replace("@RIGHT@DELIMITER@", "]");
    url = url.replace("@LEFT@DELIMITER@", "[");

    $.getJSON(url, params, function(data){

        var cont = $('#' + idContainer).html(data.html);
        
        Navigation.getNavigationInfo(0,function(){
            Navigation.initPlaylistNavButtons();
        });
        $('#breadCrumbs').html(data.breadCrumbs);
  
        player.handleAddAlbumToPlayList(cont);
        player.handleAddArtistToPlayList(cont);
        player.handleAddSongToPlayList(cont);
        player.handlePlayList(cont);

        initAllBuffaScripts(cont);
    });
  
}

var reloadPaginator = function(url, idContainer){
    
    ClassLoader.ShowSmallLoader($('#' + idContainer));

    if (url.indexOf('?') != -1){
        url += '&elementsPerPage=' + calculateElementsCount();
    }else{
        url += '?elementsPerPage=' + calculateElementsCount();
    }

    

    url = url.replace("[", "@LEFT@DELIMITER@");
    url = url.replace("]", "@RIGHT@DELIMITER@");
    url = encodeURI(url);
    url = url.replace("@RIGHT@DELIMITER@", "]");
    url = url.replace("@LEFT@DELIMITER@", "[");

    $.getJSON(url, function(data){

        //==============================================
        if ($('#' + idContainer).length == 0) {
            if ($('#pListRightBar').length) {
                ClassLoader.ShowSmallLoader($('#pListRightBar'));
            }
            Navigation.siteNavigationGoBack();
            return;
        } 
        //==============================================

        var cont = $('#' + idContainer).html(data.html);
        
        Navigation.getNavigationInfo(0,function(){
            Navigation.initPlaylistNavButtons();
        });

        $('#breadCrumbs').html(data.breadCrumbs);
        //initAllBuffaScripts($('#' + idContainer));
        player.handleAddAlbumToPlayList(cont);
        player.handleAddArtistToPlayList(cont);
        player.handleAddSongToPlayList(cont);
        player.handlePlayList(cont);
        player.handleResults(cont, 1);

        handleDragSongs();
        handleDragAlbum();
        handleArtists();
        $('a[ajaxor]', cont).ajaxor({});

    //        $('a[ajaxor]', cont).click(function(){
    //            var href =  $(this).attr('href');
    //
    //            $.post(href, {
    //                isAjax:1
    //            }, function(data){
    //                player.handleResults(data);
    //                $.Ajaxor.replacePage(data);
    //
    //                if ('undefined' != typeof(data.title) && data.title != '' ) {
    //                    document.title = data.title;
    //                }
    //
    //            });
    //            return false;
    //        });
    
    });
}


