window.addEvent('domready',function(){
		
		initiate_actions();

		var hash = $get('#',window.location),
		available = ($(hash)) ? true:false; 
		
		if($chk(hash) && !available ){
			
			
			if(hash == 'updateQuestion' && thisAsker == thisUser){
		
				$('update_form').show();
		
			}
			
			if(hash == 'editQuestion' && thisAsker == thisUser){
				get_edit_question_form(thisThread)			
			}

			if(hash == 'Answer'){
			
				focusNawte();			
			}
						
		}
		
		$$('.attached_img').each(function(el){

			el.addEvent('click', function(){

				box = new StickyWin.Modal({
	        		content: '<div style="width:500px;position:relative;color:white"><img style="max-height:500px !important;height:auto;width:500px !important;width:auto;" src="'+this.get('src')+'"/>'+'<u class="clear" style="float:right;font-size:11px;cursor:pointer" onclick="hideBox()">'+ 'close' + '</u></div>' ,
	       			hideOnClick: true
	       			//relativeTo:$$('body')
	        		//evalScripts: true,
	        		//caption: 'You Must Be Logged In To Do That!'
	    		});



			});


		});
		$$('.breadcrumb')[$$('.breadcrumb').length-1].setStyle('font-weight','bold').setStyle('font-size','16px');

		$try(function(){
	
		if(usercard.alerted === true || usercard.alerted == '1' || usercard.alerted == 1){
			
			
			$try(function(){
			
				$$('#follow_button').store('sticky',follow_sticky);
				
			});
			
			$$('#follow_button').set('class','unalert_button');	
				
			$$('#follow_button span').set('html',"Remove From My Favorites");
		}

	
		});
		function logged_in_unfollow(){

       var followRequest = new Request({
            method: 'post',
            url: ffurl + 'user.php?ajax',
            data: {'do':'unsubscribe', 'threadid':thisThread,'type':'remove'},
            onSuccess: function (txt) {
				txt = JSON.decode(txt);
				if(txt.error == null){
							
					$$('#follow_button').set('class','alert_button');	
					$$('#follow_button span').set('html',"Add To My Favorites");
				}
				else{
					StickyWin.alert('Sorry', txt.error);
            	}
			}

        });



        followRequest.send();

}

	$$('#submit_update_question').addEvent('click', function()
	{
		update_submit();
	});

	$('follow_button').addEvent('click', function() 
		{
		
			  if (isloggedin == true) {

					if(usercard.alerted == null || usercard.alerted == 0 || usercard.alerted == '0' || usercard.alerted == false){

						logged_in_follow();
						usercard.alerted = 1;				
	
					}
				
					else {
				
						logged_in_unfollow();
						usercard.alerted = 0;		
					}		


		        }

		        else {

					guest_follow_email();
					
				}

		});
	

});
handle_rating_popup = function(pid){

	if (typeof ptips == "undefined"){window.ptips = []}
	if (typeof ratingPopups == "undefined"){window.rating_popups = new Hash();}
	
	setToggle($('agree_' +pid),$('disagree_'+pid));
	
	$('rating_graph_'+pid).addEvent('click',function(){
	
		var post  = $(this).get('post');
	
		if(rating_popups.has(post)){
			rating_popups[post].destroy();
		}
		
		var popup = new CustomPointy($(this),$('rating_graph_'+pid+'_content').get('html'));
		rating_popups[post] = popup;
	
	
		
	});
	$('rating_graph_'+pid).addEvent('mousedown',function(a){
		var bgp = $(this).getStyle('background-position').split(' ');
		bgp[1] = "-48px";
		$(this).setStyle('background-position',bgp.join(' '));
	}).addEvent('mouseup',function(a){
		var bgp = $(this).getStyle('background-position').split(' ');
		bgp[1] = "-24px";
		$(this).setStyle('background-position',bgp.join(' '));
	}).addEvent('mouseenter',function(a){
		var bgp = $(this).getStyle('background-position').split(' ');
		bgp[1] = "-24px";
		$(this).setStyle('background-position',bgp.join(' '));
	}).addEvent('mouseleave',function(a){
		var bgp = $(this).getStyle('background-position').split(' ');
		bgp[1] = "0px";
		$(this).setStyle('background-position',bgp.join(' '));
	});
	ptips.push(
	
		new Tips.Pointy($('rating_graph_'+pid),{
		
			pointyTipOptions: {
				point: 6,
				width: "auto",
				pointyOptions: {
					closeButton: false
			}
		}
		
		
		})
	
	);

};	
	clickAgree = function(el){
	
		if(el.retrieve('state')=='off'){
			giveFeedback(el,$(el).get('postid'), 1);
		}
	};
	
	clickDisagree = function(el){
	
		if(isloggedin == false){
			get_join_form();
		}
		else if(el.retrieve('state')=='off'){
		
			var postId = $(el).get('postid');
		
			completeDisagree(el,postId, -1,{
			
				'title':phrases['give_feedback'],
				'directions':phrases['why_was_this_answer_unhelpful']		
			});
		}	
		
	
	};

handle_reply_box = function(pid){
	$(pid+'_reply_form').addEvent('keyup',function(){
	
		var left = 1000-this.value.length;
		
		var target = $(pid+'_char_count');
		
		target.set('html',left);
		
		if (left > 0){
		
			target.getParent().setStyle('color','black');		
		
		}
		else if(left == 0){
				
			target.getParent().setStyle('color','red');
		
		}
		
		
	});

};


quoteQuestion = function(user,post){

	var template = "[QUOTE={username};{postid}]{postcontent}[/QUOTE]";
	var sub = {'username':user,'postid':post,'postcontent':$('firstpost_pagetext').value};
	
	var quote = template.substitute(sub);
	
	tbody.setValue(quote + tbody.getValue());
	focusNawte();
};

 //^^^^^en_views/showthread_views/question.tpl.php^^^^^ 


function hideBox(){

	box.hide();

}



 //^^^^^en_views/showthread_views/attached_images.tpl.php^^^^^ 



	orderingBy = '#oldest';
	orderingBy = orderingBy.toLowerCase();
	$$(orderingBy).addClass('on').getParent().set('href','#'+orderingBy);
	

 //^^^^^en_views/showthread_views/command_bar.tpl.php^^^^^ 



hideSticky = function(){
	
	$try(function(){
		
		follow_sticky.hide();
		
	});
		
};
	
function followRequest(email){
	
	        var followRequest = new Request({
            method: 'post',
            url: ffurl + 'thread.php',
            data: {'do':'alert','t':thisThread,'email':email},
            onSuccess: function (txt) {
				txt = JSON.decode(txt);
				if(txt.error == null){
					$('follow_button').retrieve('sticky').destroy();
						follow_sticky  = new StickyWin({
						  content: new StickyWin.UI.Pointy("Thanks!  You will be emailed when there are new replies.", {
									    width: 200,
									    direction: 12,
									    theme: 'dark',
									    closeButton: false
									}),
						  relativeTo: $('follow_button'),
			
						  position:'bottom',
						  edge: 'topRight',
						  offset:{x:100,y:12}
						});	
						$('follow_button').store('sticky',follow_sticky);		
					
					hideSticky.delay(2500);	

				}
				else{
					StickyWin.alert('Sorry', txt.error);
            	}
			}
        });



        followRequest.send();
	
}

function checkEmail() {

	var email_string = $('email_form').get('value');
	if (email_string.contains('@') && email_string.contains('.')) {
		
		followRequest(email_string);
		
	}
	
	else{
		
		StickyWin.alert('Error','You must enter a valid e-mail address.');
		
	}

}

function guest_follow_email(){

	var getEmailTemplate = 	"<div class='clear'></div>"+
							"<table><tr><td valign='middle'>"+
							"<input id='email_form' type='text' style='height:18px;margin-right:3px'/>"+
							"</td><td valign='middle'>"+
							"<input type='submit' value='Alert Me' class='gray_button' onclick='checkEmail()' style='top:5px'/>"+
							"</td></tr></table>"+
							"<div class='clear'></div>";
					

	
			var follow_sticky  = new StickyWin({
			  content: new StickyWin.UI.Pointy("Enter Your Email Address:", getEmailTemplate, {
						    width: 250,
						    direction: 12,
						    theme: 'dark'
						}),
			  relativeTo: $('follow_button'),

			  position:'bottom',
			  edge: 'topRight',
			  offset:{x:125,y:12}
			});	
	
	$('follow_button').store('sticky',follow_sticky);	

}

function logged_in_follow(){

       
       var followRequest = new Request({
            method: 'post',
            url: ffurl + 'thread.php',
            data: {'do':'alert','t':thisThread},
            onSuccess: function (txt) {
				txt = JSON.decode(txt);
				if(txt.error == null){
					$$('#follow_button span').set('html',"Remove From My Favorites");	
						follow_sticky  = new StickyWin({
						  content: new StickyWin.UI.Pointy("Thanks!  You will be emailed when there are new replies.", {
									    width: 200,
									    direction: 12,
									    theme: 'dark',
									    closeButton: false
									}),
						  relativeTo: $('follow_button'),
			
						  position:'bottom',
						  edge: 'topRight',
						  offset:{x:100,y:12}
						});			
										
					$$('#follow_button').store('sticky',follow_sticky)
					.set('class','unalert_button');	
						
					hideSticky.delay(2500);	

				}
				else{
					StickyWin.alert('Sorry', txt.error);
            	}
			}

        });



        followRequest.send();

}




	
var updater = new Class({
	submit: function()
	{	
		new Request.JSON({
		method: 'post',
		url : ffurl + 'thread.php',
		data: 
		{
			'do' : 'update',
			'update_message': $('utitle').get('value'),
			't' : thisThread,
			'attach_posthash': posthash
		},
		onComplete: function(response)
			{
				if(response.error)
					StickyWin.alert('Sorry', response.error);
				else
				{
					//StickyWin.alert('Thanks', response.response);
					reloadBrowser();
				}
			}
		}).send();
	}
});


function update_submit()
{

	update_handler = new updater();
	update_handler.submit();
}






 //^^^^^en_views/showthread_views/question.tpl.php^^^^^ 

var page_count = 1 ; 
 //^^^^^en_views/showthread_views/pagination.tpl.php^^^^^ 



	orderingBy = 'Oldest';
	orderingBy = orderingBy.toLowerCase();
	
	function showOrderMenu(){
		$('order_by').setStyle('height','88px');	
	}

	function hideOrderMenu(){
		$('order_by').setStyle('height','22px');	
	}


	
	
 //^^^^^en_views/showthread_views/pagination.tpl.php^^^^^ 



function prevRep(id,key){

	var newkey = key-1;
	$$('div[rep='+id+'_'+key+']').hide();
	$$('div[rep='+id+'_'+newkey+']').show();

}

function nextRep(id,key){

	var newkey = key+1;
	$$('div[rep='+id+'_'+key+']').hide();
	$$('div[rep='+id+'_'+newkey+']').show();
}


 //^^^^^en_views/showthread_views/reputation_feedback.tpl.php^^^^^ 


