

var IdeaController = {

	editIdea: function( id)
	{
		
	},
	
    editTitle: function( id ) 
    {
        Element.hide( 'title-'+id, 'edit-title-link-'+id ); 
        Element.show( 'edit-title-'+id );
    },
    
    cancelEditTitle: function( id ) 
    {
        Element.show( 'title-'+id, 'edit-title-link-'+id ); 
        Element.hide( 'edit-title-'+id );
    },
    
    disableEditIdeaTitleForm: function( id )
    {
        Form.disable( 'edit-title-form-'+id );
        Element.show( 'progress-'+id )
        
    },
    
    enableEditIdeaTitleForm: function( id )
    {
        Form.enable( 'edit-title-form-'+id );
        Element.hide( 'progress-'+id )
    },
    ////////////////////////////////////////
    
    editBody: function( id )
    {
        Element.hide( 'body-'+id, 'edit-body-link-'+id ); 
        Element.show( 'edit-body-'+id );
       
       //['body-'+id, 'edit-body-link-'+id].each(Element.hide);
       
       //['edit-body-'+id].each(Element.show)
    },
    
    cancelEditBody: function( id ) 
    {
        Element.show( 'body-'+id, 'edit-body-link-'+id ); 
        Element.hide( 'edit-body-'+id );
    },
    
    disableEditIdeaBodyForm: function( id )
    {
        Form.disable( 'edit-body-form-'+id );
        Element.show( 'progress-body-'+id )
        
    },
    
    enableEditIdeaBodyForm: function( id )
    {
        Form.enable( 'edit-body-form-'+id );
        Element.hide( 'progress-body-'+id )
    },
    ////////////////////////////////////////
    
    
    addBody: function( id )
    {
        Element.hide( 'add-body-link-'+id ); //'body-'+id, 
        Element.show( 'add-body-'+id );
    },
    
    cancelAddBody: function( id ) 
    {
        Element.show( 'add-body-link-'+id ); //'body-'+id, 
        Element.hide( 'add-body-'+id );
    },
    
    disableAddIdeaBodyForm: function( id )
    {
        Form.disable( 'add-body-form-'+id );
        Element.show( 'add-progress-body-'+id )
        
    },
    
    enableAddIdeaBodyForm: function( id )
    {
        Form.enable( 'add-body-form-'+id );
        Element.hide( 'add-progress-body-'+id )
    }
}


var Editor = {
	
	wakeup: function( name )
	{
		var oEditor = FCKeditorAPI.GetInstance(name) ;
		try
		{
		oEditor.MakeEditable();
		}
		catch (e) {}
		oEditor.Focus();		
	}
}
////////////////////////////////
////////////////////////////////
////////////////////////////////


var FeedsController = {

    disableUpdateFeedForm: function()
    {
        Form.disable('update-feed');
        Element.show('progress')
    },
    
    
    
    enableUpdateFeedForm: function()
    {
        Form.enable('update-feed');
        Element.hide('progress')
    },
    
    
    hideUpdateFeedForm: function()
    {
        Effect.BlindUp($('edit-feed-content'));
    },
    
    
    editFeed: function( id, title, url )
    {
       if( $('edit-feed-content').style.display == 'none' )
            Effect.BlindDown( 'edit-feed-content', {duration:.5} )
            
       $('feed_id').value    = id;
       $('feed_title').value = title;
       $('feed_url').value   = url;     
    }

};


////////////////////////////////
////////////////////////////////
////////////////////////////////

var BadgeController = {

    color_map :{
	 	    black:  ['',''],
            red:    ['#ffcccc','#cc0000'],
            yellow: ['#ffffcc','#ffff00'],
            green:  ['#ccffcc','#00cc00'],
            blue:   ['#ccccff','#6666cc'],
            grey:   ['#eaeaea','#cccccc'],
            white:  ['#ffffff','#eaeaea']
    },

    select  :function( id, username )
    {
        $( id ).checked = true;
        
        this.chart_id    = id;
        this.username = username;
        // this.chart_size  = this.getChartSize();
        this.chart_color = this.getChartColor();
        
        this.updatePreview();
        this.refreshBadgeHtml(username);
    },
    
    clear :function(mode, username)
	{	
		if (mode == 'performance')	{
			$('badge-preview-performance-holder').innerHTML = '';
		}
		if (mode == 'recent_picks') {
			$('badge-preview-picks-holder').innerHTML = '';
		}
		else if (mode == 'chart') {
			$('badge-preview-holder').innerHTML = '';
		}
		this.refreshBadgeHtml(username);
	},
	
    load :function( id,username )
    {
        if( id == 'recent_picks' )
        {
           $( id ).checked = true;
            
            this.chart_id    = id;
			this.username = username;
            // this.chart_size  = this.getChartSize();
            this.chart_color = this.getChartColor();
            
            Element.show('picks-progress');
            // calls the rjs to render out the block
            new Ajax.Request( '/' + username + '/recent_picks', { asynchronous:true, evalScripts:true }); 			
        }
        else
        {
            this.showing_performance = true;            
            // set up chart params that get used by html render method
            Element.show('performance-progress');            
            // make the rjs request
            new Ajax.Request( '/' + username + '/performance_widget', { asynchronous:true, evalScripts:true });             
            // call renderPreview
        }
		this.refreshBadgeHtml(username);
    },
    
	chartCheckActions :function(user_name)
	{
		if ($(charts).checked) {
			$(performance).checked=true;
			BadgeController.select( 'performance', user_name);
		} else {
			$(performance).checked=false;
			$(sector_portfolio).checked=false;
			$(sector_portfolio).checked=false;
			$(sector_ratings).checked=false;
			$(activity_quarter).checked=false;
			$(activity).checked=false;
			BadgeController.clear('chart');
		}
	},
	
    refreshBadgeHtml :function(username)
	{   
		var request='http://www.socialpicks.com/js/widget/'+username+'?';
		var params='';
		if (document.getElementById('performance_widget').checked){
		  params+='t=performance';
		}
		if (document.getElementById('recent_picks').checked){
			if (params!="") params+='&';
			params+='chart=recent_picks';
		}	
		if (params == '') {
			$('badge-html').value = ''; 
		}else{
			if( this.chart_color ){
			  params+='&color='+this.chart_color;
			}
			if (this.chart_size){
			  params+='&size='+this.chart_size;
			}
			var url = request + params;
			var html = '<script type="text/javascript" src="'+url+'"></script>';
			$('badge-html').value=html
		}	
	},
	
    catchPerformanceHtml :function( html )
    {
        $('badge-html').value = html + $('badge-html').value
    },
    
    
    // getChartSize :function()
    // {
    // 	    
    //     if( $('small').checked )  return 'small';
    //     if( $('medium').checked ) return 'medium';
    //     if( $('large').checked )  return 'large';
    // },
    
    getChartColor :function()
    {
		return $('bgcolor_hex').value;
	//         if( $('red').checked    ) return 'red';
	//         if( $('yellow').checked ) return 'yellow';
	//         if( $('green').checked  ) return 'green';
	//         if( $('blue').checked   ) return 'blue';
	//         if( $('grey').checked   ) return 'grey';
	//         if( $('white').checked  ) return 'white';
	// return 'white';
    },

    getWidth :function()
    {
        switch( this.chart_size )
        {
            case 'small':
                return 200;
            break;
            
            case 'medium':
                return 260;
            break;
            
            case 'large':
                return 350;
            break;
        } 
    },
    
    setChartSize :function( id, username )
    {
        $( id ).checked = true;
        this.chart_size = id;
        
        this.updateBackground();
        this.refreshBadgeHtml(username);
    },
    
    setChartColor :function( id , username)
    {
        $( id ).checked = true;
        this.chart_color = id;
        
        this.updateBackground();
	    this.refreshBadgeHtml(username);
        //this.renderPreviewHtml();
    },
    
    
    getTitle :function()
    {
        var s = 'My <a href="http://socialpicks.com/">SocialPicks</a> ';
        
        switch( this.chart_id )
        {
            case 'performance':
                s += 'Peformance'
            break;
            
            case 'sector_portfolio':
                s += 'Portfolio Sectors'
            break;
            
            case 'sector_ratings':
                s += 'Portfolio Sector Ratings'
            break;
            
            case 'activity_quarter':
                s += 'Activity by Quarter'
            break;
            
            case 'activity':
                s += 'Activity'
            break;
        }
        
        return s;
    },
    
    updateBackground :function()
    {
		if (this.chart_color) {
        	$('badge-preview').style.backgroundColor = this.getChartColor();
        	$('badge-preview').style.borderColor = this.getChartColor();
		}
		
		if (this.chart_size) {
			$('badge-preview').style.width = this.getWidth();
			
		}
    },
    
     updatePreview :function()
    {
        this.updateBackground();
        
        $('badge-title').innerHTML = this.getTitle();
        
        var chart = new FusionCharts( '/lib/' + this.chart_map[this.chart_id], 'chart_preview', this.getWidth(), this.getHeight(), '0', '0' );
        chart.setDataURL( '/graph/' + this.chart_id + '/' + this.person_id );		   
		chart.render( 'badge-preview-holder' );
    }//,
    

}

////////////////////////////////
////////////////////////////////
////////////////////////////////

var FundController = {

    loading :function()
    {
        Element.show( 'add-fund-progress' )
    },
    
    complete :function()
    {  
        Element.hide( 'add-fund-progress' )
    }

}

////////////////////////////////
////////////////////////////////
////////////////////////////////

var InviteController = {
	
	loadp :function()
	{

		var headID = document.getElementsByTagName("head")[0];         
		var newScript = document.createElement('script');
		newScript.type = 'text/javascript';
		newScript.src = 'http://www.plaxo.com/css/m/js/util.js';
		headID.appendChild(newScript);		
	
		headID = document.getElementsByTagName("head")[0];         
		newScript = document.createElement('script');
		newScript.type = 'text/javascript';
		newScript.src = 'http://www.plaxo.com/css/m/js/basic.js';
		headID.appendChild(newScript);
		
		headID = document.getElementsByTagName("head")[0];         
		newScript = document.createElement('script');
		newScript.type = 'text/javascript';
		newScript.src = 'http://www.plaxo.com/css/m/js/abc_launcher.js';
		headID.appendChild(newScript);
	}
	
}

