var myStreams = {
    init:function()
    {        
        //alert('myStreams.init');
        $('.potitem a').each(function(){
            $(this).bind('click', function(pEvent){ 
                
                //alert('select stream:' + $(this).attr('rel'));
                var nStreamID = $(this).attr('rel');
                if($(this).hasClass('active'))
                {
                    var strAction = 'remove';
                    $(this).removeClass('active');
                }
                else
                {
                    var strAction = 'add'; 
                    $(this).addClass('active');     
                }
                //alert(strRootPath+'mystreams/'+strAction+'/'+nStreamID+'.html');
                $.ajax({
                    cache: false,
                    url: strRootPath+'mystreams/'+strAction+'/'+nStreamID+'.html',
                    success: function(data) {
                        if(data != '')
                        {
                            //alert(data);    
                        }
                    }
                });
                
                pEvent.preventDefault();
            });  
        });
    },
    
    initBtn:function()
    {        
        $('.addstream').each(function(){
            $(this).click(function(e){
                var strURL = $(this).attr('rel');
                var Dest = $(this);

                if(strURL.length > 3)
                {
                    $.ajax({
                       cache: false,
                       url: strURL,
                       success: function(data) {
                               if(data == 'add')
                               {
                                   Dest.html('<img width="22" height="21" alt="" src="'+strRootPath+'images/icons_add.png" />');
                                   Dest.attr('rel',strURL.replace('remove','add'));
                               }
                               else if(data == 'remove')
                               {
                                   Dest.html('<img width="22" height="21" alt="" src="'+strRootPath+'images/icons_remove.png" />');
                                   Dest.attr('rel',strURL.replace('add','remove'));
                               }
                       }
                    });    
                }
                e.preventDefault();
            })
        });
    }
};

$(document).ready(function() { 
    myStreams.init(); 
    myStreams.initBtn();
});
