Namespace("Nbcu.App.Content.News.Blog");
Nbcu.App.Content.News.Blog = function(){ this.resetParams(); }
Nbcu.App.Content.News.Blog.inherits(Nbcu);

Nbcu.App.Content.News.Blog.method('init', function()
{
	this.setParam("contentType", "SS_BLOG");				
	this.setParam("contentSSUniqueKey", "BLOG_POST-");
	this.initDom();
    
});

Nbcu.App.Content.News.Blog.method('initDom', function()
{
	var THIS = this;
		
	jqN(document).ready(function()
    {
        // onclick event for submit button:
		jqN('#submit_your_story').click(function()
		{
			if(valForm()){
				return nbcu.app.content.news.blog.submitStory();
			}
		})
		
		// ratings
		jqN('.star-rating li a').click(function() {																	
			var c = jqN(this).text();
			var starID = jqN(this).parent().parent().attr("id");

			nbcu.util.common.loadClass("Nbcu.Sn.Rating");
			
			nbcu.sn.rating.setRating("void(0);", THIS.getParam("contentSSUniqueKey")+starID, null, null, THIS.getParam("contentType"), c);

			switch(c){
				case '1':
					jqN('#'+starID+' li.current-rating').css('width', '16px');
				break;						
				case '2':
					jqN('#'+starID+' li.current-rating').css('width', '32px');
				break;
				
				case '3':
					jqN('#'+starID+' li.current-rating').css('width', '48px')
				break;
				case '4':
					jqN('#'+starID+' li.current-rating').css('width', '64px')
				break;
				case '5':
					jqN('#'+starID+' li.current-rating').css('width', '81px')
				break;
			}				
			//jqN('#'+assetID+' ul.star-rating').next().text('Thank you for voting!')
			jqN('#'+starID).after('<small>Thank you for voting!</small>');
			jqN('#'+starID+' .star-rating li a').unbind('click');
			//THIS.logEvent({ event: 'rate', rating: c });
			return false;
		});
		
		jqN('.star-rating').hover(function(){
				//jqN('li.current-rating').hide();
				var starID = jqN(this).parent().parent().attr("id");
				jqN("#"+starID+" .current-rating").hide();
			}, 
			function() {
				//jqN('li.current-rating').show();
				var starID = jqN(this).parent().parent().attr("id");
				jqN("#"+starID+" .current-rating").show();
			})
        
    });// end doc ready	
});

Nbcu.App.Content.News.Blog.method('submitStory', function()
{
    // disable submit button:
    this.submit       = jqN('#submit_your_story').click(function() {
                            //return false;
														jqN(this).attr("disabled","true");
                        });
    // get form elements:
    this.url          = jqN('#url').val();
    this.contentTitle = jqN('#contentTitle').val();
    this.postText     = jqN('#postText').val();
    this.site         = jqN('#site').val();
    this.tags         = jqN('#tags').val().toLowerCase();
    this.form_uri     = jqN('#form_uri').val();
    
    jqN.ajax({
	    type: "POST",
			url: "/app/bootstrap/content/content.php",
      data: "url="+this.url+
              "&contentTitle="+this.contentTitle+
              "&postText="+this.postText+
              "&tags="+this.tags+
              "&form_uri="+this.form_uri+
              "&site="+this.site,
			dataType: 'text',
			success: function(msg){
					
						jqN('#text > p').html('Thank you for submitting your story, it will appear shortly.<br /><br /><a href="javascript:void(0);" class="additional_story">Click here to submit another story.</a>');						
												
						jqN("#new_from_you_form").fadeOut(function(){
							//jqN('#text').append('<p></p>');	
							jqN("#new_from_you_form").clearForm();
							jqN(".additional_story").click(function(){
								jqN("#text > p").remove();
								jqN("#text").append('<p>Fill out the form below to submit a story to the NBC.com News Blog.</p>');
								jqN("#new_from_you_form").fadeIn();
							
							});
						});
						
				},
			error: function(XMLHttpRequest, textStatus, errorThrown){
                    jqN('#text > p').html('All fields are required');
				},
        complete: function(XMLHttpRequest, textStatus) { 
                    return false; 
                },
		timeout:50000
	});
    

    return false;
})
		

Namespace("nbcu.app.content.news.blog");
nbcu.app.content.news.blog = new Nbcu.App.Content.News.Blog();
nbcu.app.content.news.blog.init();
