//J-Query [http://docs.jquery.com/]
// Copyright S.Botylen 2008


          $(document).ready(function(){
	          //url regex
	          var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
	          var exptags = /\[(b|u|i|s|center|code){1}]((.){1,}?)\[\/(\1){1}]/ig;
	          
	          //unhide comments 	          
   			  $("div#addcomment").removeClass("hidden_div");
   			  
   			  
   			  //colour owners comments in to hightlight them
   			  var $kids = $("#comments").contents("div");
   			  var username = "re0sless"
   			  
              for (var i = 0; i <= $kids.length-1 ; i ++)
              {
	              if (($kids.eq(i).children("h4").text()).toLowerCase().substring(0,username.length) == username)
	   			  {
		   		      $kids.eq(i).addClass("hilight_div");	  
	   			  }
	   			  
	   			  $kids.eq(i).children("p").html(($kids.eq(i).children("p").text())
	   			                    .replace(exp,"<a href='$1'>$1</a>")
	   			                    .replace(exptags,"<$1>$2</$1>")
	   			                                 );	   			  

              }
              
              
              //captcha image
              $("div#captchaimg").html('<img src="thirdparty/captcha/image.jpg?key=26c07de1a49110dca1a04e2af66e592b&site=c0fb0d16036e0288be969ab2def4ee70" alt="" border="0">');
              
              //form preview code             
              $("#pre_date").html('todays date');
              
              $("#add_comments_name").keyup(function(event){
	              $comment = $(this).val();
			      $comment = $comment.replace(/>/g, "&gt;")
			        .replace(/</g, "&lt;")
			        .replace(/\n/g, "")
			        .replace(/\n\n+/g, '');
			          
			      $('#pre_name').html( $comment + ' ');
			  });
			  
              $("#add_comments_body").keyup(function(event){
	              $comment = $(this).val();
			      $comment = $comment.replace(/>/g, "&gt;")
			        .replace(/</g, "&lt;")
			        .replace(/\n/g, "<br />")
			        .replace(/\n\n+/g, '<br /><br />')
			        .replace(exp,"<a href='$1'>$1</a>") 
			        .replace(exptags,"<$1>$2</$1>");
			      $('#pre_body').html( $comment );
			      
			      //alert($comment.replace(exptags,"<$1>$2<$1>"));
			      
			  });
			  
			  //Form validation
			  $("#add_comments").submit(function() {
				  $("#val_span").text("");
				  $("#com_span").text("");
				  
			      if ($("#add_comments_body").val() == "") {
			        $("#com_span").text("Please enter a comment");
			        return false;
			      }
			      else if ($("#val").val() == "") {
			        $("#val_span").text("Please enter the text as shown in the image");
			        return false;  
			      }else{
				     return true; 
			      }  
			      return false;
              });
              
              $("#image_table div a").click(function()
              {
	              l_url = $(this).html();
	              
	              if (l_url.length > 0)
	              {
		              l_url = l_url.replace('/thumbs','');
	                  $("#image_full").addClass("hidden_div").html('<a href="Javascript:;" id="dialog" title="Click to close this image">' + l_url + '</a>');   
						//set the pop-up's title
	                  $("#image_full").attr("title",$(l_url).attr("alt"));
	                  $("#image_full").removeClass("hidden_div").dialog({ 
    				    	modal: true, 
    					    overlay: { 
        				    opacity: 0.5, 
        				    background: "black" 
    					    },
    					    height:500,
    					    width:800
					    });  
				  }
              });
              
              /**
              *  Hides the large img hidden_div
              */
              $("#image_full").click(function ()
              {
	              $(this).dialog("close");
              });
         
 		  });