// JavaScript Document

//var $j = jQuery.noConflict();

$(document).ready(function(){
						
    //alert("Testing 1...2...3");
    
    //adds the correct text string Review or Reviews depending whether number is 1 or not
    $("div.twd-postfootericons a[title*='Comment on']").each(function(){
			commentLinkArray = $(this).html().split(' ');
			reviewsLink = null;
			if(commentLinkArray[0]=="1"){reviewsLink =" Website Review "}else{reviewsLink =" Website Reviews "};
    		$(this).html(" "+commentLinkArray[0]+reviewsLink);
    		$(this).attr("title","Leave a review if you are an approved reviewer");
    });
    
    $("H4#comments").each(function(){
		commentHeaderArray = $("H4#comments").html().split(' ');
    	var reviews = null;
    	if(commentHeaderArray[0]=="One"){reviews=" Review of "}else{reviews=" Reviews of "};
    	$("H4#comments").html(commentHeaderArray[0]+reviews+commentHeaderArray[3]);
	});
    
    //encourages visitors to give feedback on the review
    $("<div><strong>Do you like this review?</strong></div>").insertBefore('div.thumblock');
    
    //the following tests to see if the user has previously submitted a review by
    // comparing their logged in user name to the list of authors in the comment thread
    $('textarea#comment').focus(function(){
    		
    		var user = null;
    		user = $('p.logged-in-as a').html();
    		
    		var previousArray = [];
    		var previousArray = $('div.comment-author cite a').map(function(){
    			return $(this).html();
    		});
    		
    		if($.inArray(user,previousArray)!=-1){
				alert("Woops! Looks like you've already submitted a review for this site.");
				$(this).blur();
			};

    		
    });
    
    //adds a more relevant heading in place of the default wordpress comment heading
    $('h3#reply-title').html('Leave a review (Must be an authorized Reviewer)');
	
	//adds to the "allowed HTML" label in the comments section. Tags themselves
	// must be added by editing the functions.php file in the theme layer
	//$(p.form-allowed-tags code).append('&lt;ul&gt;&lt;li&gt;');
	
	//Makes browser shot links open in a new tab window
	$('div.browsershot a').attr("target", "_blank");
	$('a.manual-image').attr("target", "_blank");//for images added manually when browsershot doesnt work
 
});   
