//login scripts
function authenticationChange(){
	try{
		pageSessionUpdate();
	}catch(err){}
	if (getCookie("mml")!=null && getCookie("mml")!=""){
		//if the user is logged in
		$(".login").hide();
		$(".loggedin").show();
		
		//first gen comments height
		$("#CommentPost").css("height","auto");
		
		//second gen comments height
		$("#CommentsSection #CommentPost").css("height","248px");
		
		var username=getCookie("mmd").substring(0,getCookie("mmd").indexOf('|'));
		var userimage=getCookie("mmd").substring(getCookie("mmd").indexOf('|')+1);
		$(".username").html("Logged in as, <a href=\"#\" onclick=\"openwindow();tWin();return false\">"+username+"</a> | ");

		if (userimage!=null){
			$(".userimage").attr("src",userimage);
		} else{
			$(".userimage").attr("src","http://a3.twimg.com/profile_images/626884445/much-twitter-0110_bigger.jpg"); 
		}
		$("#CommentBox").show();
		$("#CommentSection .CommentInput").show();
		$("#LoginToComment").hide();
		$("#Comments .CommentReply").show();

		$("#loginState").replaceWith("<div id='loginState' style='text-indent: 0;'><img src='" + userimage + "' style='width:22px; height: 22px; padding: 1px 0 0 1px; margin-right: 3px;'> <div class='welcome' style='width: 61px;'>"+username+"<br/><a onclick=\"openwindow();tWin();return false\" style='color: #ff1f44;' href=\"#\">Edit profile</a> </div> <a href=\"#\" onclick='logout()' class='logout' style='display: block; float: left; text-indent: -9999px; width: 50px; height: 24px;'></a> </div>");
		$("#loginState").css('background-image', "url(http://www.muchmusic.com/mmconnect/images/logout.png)");  
		$("#loginState").css('width', "145px");  

		$(".CommentReply").each(function(){
			$(this).replaceWith("<a href=\""+$(this).attr("href")+"\" class=\"CommentReply\" onclick=\"CommentReply("+$(this).attr("href").substring($(this).attr("href").indexOf("#reply")).substring(6)+");return false\">REPLY</a>");
		});

	} else{
		//if the user is not logged in
		$(".loggedin").hide();
		$(".login").show();
		
		//first gen comments height
		$("#CommentPost").css("height","58px");
		
		//second gen comments height
		$("#CommentsSection #CommentPost").css("height","40px");

		//$(".CommentReply").replaceWith("<a href=\""+$(this).attr("href")+"\" class=\"CommentReply\" onclick=\"openwindow2();tWin2(); return false\">LOGIN TO REPLY</a>");
		$(".CommentReply").each(function() {
            $(this).attr("onclick","openwindow2();tWin2(); return false;").html("LOGIN TO REPLY");
        });

		$(".loggedin").hide();
		$(".login").show();
		$("#CommentBox").hide();
		$("#CommentSection .CommentInput").hide();
		$("#LoginToComment").show();
		$(".CommentReply").each(function(){
			$(this).replaceWith("<a href=\""+$(this).attr("href")+"\" class=\"CommentReply\" onclick=\"openwindow2();tWin2(); return false\">LOGIN TO REPLY</a>");
		});
		$("#loginState").replaceWith("<a id=\"loginState\" href=\"#\" onclick=\"openwindow2();tWin2(); return false\">Login or Logout</a>");
		$("#loginState").css('background-image', "url(http://www.muchmusic.com/mmconnect/images/login-top.png)");
		$("#loginState").css('width', "145px");
	}
	
	if(offset + commentPageSize < numcomments){
		$("#comment-navigation").html("<a href=\"#\" onclick=\"moreComments(); return false;\"> MORE COMMENTS <img src=\"http://www.muchmusic.com/mmconnect/images/down_arrow_small.gif\" /></a>");
	}
}
$(document).ready(function(){
	authenticationChange();
});	


