code:
Язык разметки сообщений

							Для оформления сообщений можно использовать разметку, которая включает в себя некоторые элементы разметки
							wakabamark, однако имеет свои расширения и особенности. Основные коды разметки представлены ниже.

Изображение (с сервиса Imgur):

https://i.imgur.com/XXXXXXX.jpg --> [i:XXXXXXX:] (не работает в разделах для общения)

Изображение (с сервиса Catbox):

https://files.catbox.moe/xxxxxx.jpg --> [c:xxxxxx.jpg:] (не работает в разделах для общения)

Жирный:

**Жирный**

Курсив:

*Курсив*

Моноширинный:

`Моноширинный`

Код (моноширинный блок):

/---
 моноширинный блок
\---

Спойлер:

%%Текст спойлера%%

Ссылка:

"Двач":https://2ch.net

Ссылка на пост:

>>номер_поста, например >>1.

Цитата:

> Цитируемый текст.

Цитата в тексте:

Тут >>пробелов не должно<< быть.

Заголовок:

Большой шрифт
**************

							Кроме перечисленных тут кодов существуют еще несколько, но пускай это будет сюрпризом.
							Например, можно попробовать использовать списки.


code:
<?php include(dirname(__FILE__) .'/../blog/chunks/blog_control.php'); ?>

Последние комментарии

					<?php if (sizeof($comments) > 0): ?>
					<?php foreach($comments as $comment): ?>
					<?php $post = Blog_BlogPostsModel::GetPost($comment['post_id']);
					$comment['post_title'] = $post['title']; ?>
					<div class="b-comment" id="comment_<?php echo($comment['id']); ?>">

							<?php echo(TemplateHelper::date('d M Y @ H:i:s', $comment['created_at'])); ?>, <a href="/news/res/<?php echo($comment['post_id']); ?>/"><?php echo($comment['post_title']); ?>
							(<a href="/news/res/<?php echo($comment['post_id']); ?>/#<?php echo($comment['id']); ?>">#<?php echo($comment['id']); ?>)

								<img src="/ico/remove.gif" width="16" height="16" alt="<?php echo($comment['id']); ?>" />

							<?php if($comment['author'] != 'anonymous'): $author = HomeBoardHelper::getBoard($comment['author']); ?>
							<a href="https://<?php echo($comment['author']); ?>/" class="b-comment_b-homeboard" title="Аноним выбрал принадлежность «<?php echo($author[1]); ?>»">
								<img src="/ico/homeboards/<?php echo($author[0]); ?>" width="16" height="16" alt="" />

							<?php endif; ?>

							<?php echo($comment['text']); ?>

					<?php endforeach; ?>
					<?php endif; ?>

					<textarea id="template_comment" style="display:none">
						<div class="b-comment" id="comment_<%=id%>">

								<%=created_at%>, <a href="/news/res/<%=post_id%>/"><%=post_title%>
								(<a href="/news/res/<%=post_id%>/#<%=id%>">#<%=id%>)

									<img src="/ico/remove.gif" width="16" height="16" alt="<%=id%>" />

								<% if (author[0] != "anonymous") { %>
								<a href="https://<%=author[0]%>/" class="b-comment_b-homeboard" title="Аноним выбрал принадлежность «<%=author[1][1]%>»">
									<img src="/ico/homeboards/<%=author[1][0]%>" width="16" height="16" alt="" />

								<% } %>

								<%=text%>

					</textarea>

repo_name: devarped/pierwszykanal

license: mit


code:
<?php include(dirname(__FILE__) .'/../blog/chunks/blog_control.php'); ?>

Последние действия модераторов

					Просмотр скрытых тредов

					<?php if (sizeof($comments) > 0): ?>
					<?php foreach($comments as $comment): if($comment): ?>

							<?php echo($comment); ?>

					<?php endif; endforeach; ?>
					<?php endif; ?>

					<textarea id="template_comment" style="display:none">
						<div class="b-comment" id="comment_<%=id%>">

								<%=created_at%>, <a href="/news/res/<%=post_id%>/"><%=post_title%>
								(<a href="/news/res/<%=post_id%>/#<%=id%>">#<%=id%>)

									<img src="/ico/remove.gif" width="16" height="16" alt="<%=id%>" />

								<%=text%>

					</textarea>


code: <?php include(dirname(__FILE__) .'/'. $page .'.php'); ?>


code: <?php echo eval('?> '.$preview_content.' <?php '); ?>


code:
-- MySQL dump 10.13  Distrib 5.1.41, for debian-linux-gnu (x86_64)
--
-- Host: localhost    Database: 1chan
-- ------------------------------------------------------
-- Server version	5.1.41-3ubuntu12.10

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `1chan_category`
--

DROP TABLE IF EXISTS `1chan_category`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `1chan_category` (
  `id` int(32) NOT NULL AUTO_INCREMENT,
  `public` tinyint(1) NOT NULL DEFAULT '0',
  `pos` int(32) NOT NULL DEFAULT '1',
  `name` varchar(255) NOT NULL,
  `title` varchar(255) NOT NULL,
  `description` text NOT NULL,
  `posts` int(32) NOT NULL DEFAULT '0',
  `code` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`(127)),
  KEY `code` (`code`(127))
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `1chan_comment`
--

DROP TABLE IF EXISTS `1chan_comment`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `1chan_comment` (
  `id` int(32) NOT NULL,
  `post_id` int(32) NOT NULL,
  `ip` varchar(255) NOT NULL,
  `author` varchar(32) DEFAULT 'anonymous',
  `created_at` int(32) NOT NULL,
  `text` text NOT NULL,
  `special_comment` text DEFAULT NULL,
  PRIMARY KEY (`id`,`post_id`),
  KEY `ip_index` (`ip`(16))
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `1chan_post`
--

DROP TABLE IF EXISTS `1chan_post`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `1chan_post` (
  `id` int(32) NOT NULL,
  `ip` varchar(255) DEFAULT NULL,
  `author` varchar(32) DEFAULT 'anonymous',
  `hidden` tinyint(1) NOT NULL DEFAULT '0',
  `pinned` tinyint(1) NOT NULL DEFAULT '0',
  `rated` tinyint(1) DEFAULT NULL,
  `closed` tinyint(1) NOT NULL DEFAULT '0',
  `rateable` tinyint(1) NOT NULL DEFAULT '1',
  `bumpable` tinyint(1) NOT NULL DEFAULT '1',
  `category` int(32) DEFAULT NULL,
  `created_at` int(32) NOT NULL,
  `updated_at` int(32) NOT NULL,
  `link` varchar(255) NOT NULL,
  `title` varchar(255) NOT NULL,
  `text` text NOT NULL,
  `text_full` text NOT NULL,
  `rate` int(32) NOT NULL DEFAULT '0',
  `comments` int(32) NOT NULL DEFAULT '0',
  `special_comment` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `hidden` (`hidden`,`rated`,`category`,`created_at`,`updated_at`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2012-07-10 17:32:45


code:
<?php
// настройки подключения к базе MySQL
define('SQL_HOST', '127.0.0.1');
define('SQL_NAME', '<dbname>');
define('SQL_USER', '<username>');
define('SQL_PASSWORD', '<password>');
// настройки подключения к реалплексору
define('REALPLEXOR_HOST', '127.0.0.1');
define('REALPLEXOR_PORT', '10010');
// настройки подключения к редису
define('REDIS_HOST', '127.0.0.1');
define('REDIS_PORT', '6379');
// настройки подключения к индексатору
define('SPHINX_HOST', '127.0.0.1');
define('SPHINX_PORT', '3312');
// настройки общей чат-комнаты
define('COMMON_ROOM_CONTROLWORD', '<controlword>');


code:
<?php
chdir(dirname(__FILE__));

/**
 * Скрипт для очистки онлайн-ссылок:
 */
require '../instance-config.php';
require '../app/classes/kvs.class.php';

$cache = KVS::getInstance();

$links   = $cache -> listGet('Blog_BlogOnlineModel', null, 'links');
if ($links) {
    foreach($links as $link)
        {
                        $cache -> listRemove('Blog_BlogOnlineModel', null, 'links', $link);
        }
}


code:
#!/bin/sh

cd /var/www/1chan/scripts
pgrep -f 'serverstatus.php' || php serverstatus.php&


code:
<?php
chdir(dirname(__FILE__));

/**
 * Проверка статуса доступности серверов:
 */
require '../instance-config.php';
require '../app/classes/kvs.class.php';

$cache = KVS::getInstance();
$links = unserialize($cache -> get('Blog_BlogLinksModel', null, 'links'));

foreach($links as $section => $section_links)
{
	foreach($section_links as $key => $link)
	{
		$headers = @get_headers($link['href']);
		if(!in_array(substr($headers[0], 9, 3), array(200, 303, 302, 301)))
		{
			$links[$section][$key]['offline'] = 1;
		} else {
			$links[$section][$key]['offline'] = 0;
		}
	}
}
$cache -> set('Blog_BlogLinksModel', null, 'links', serialize($links));

$links   = $cache -> listGet('Blog_BlogOnlineModel', null, 'links');
if ($links) {
    foreach($links as $link)
	{
		if (($current = unserialize($cache -> get('Blog_BlogOnlineModel', 'links', $link))) != null)
		{
			$headers = @get_headers($current['link']);
		    if(!in_array(substr($headers[0], 9, 3), array(200, 303, 302, 301)))
		    {
		        $cache -> listRemove('Blog_BlogOnlineModel', null, 'links', $link);
		    }
		}
		else
		{
			$cache -> listRemove('Blog_BlogOnlineModel', null, 'links', $link);
		}
	}
}


code:
#main table tr .action a { margin: 0 0 0 10px; text-decoration: none; color: #9b9b9b; }
#main table tr .action .edit { color: #c5a059; }
#main table tr .action .delete { color: #a02b2b; }
#main table tr .action .view { color: #55a34a; }
#main table tr .action a:hover { text-decoration: underline; }

#main fieldset p { margin: 0 0 7px 0; } /* half of the normal bottom margin */

.jNiceSelectWrapper ul {
	height: 99px;
}

.jNiceSelectWrapper div span {
	padding: 9px 7px 0;
}

button {
	width: 85px;
}


code:
#main fieldset p { margin: 0 0 7px 0; } /* half of the normal bottom margin */

.jNiceSelectWrapper div span {
	padding: 9px 7px 0;
}


code:
/* -------------
 * Buttons
 * ------------- */

button {
	margin: 0px;
	padding: 0px 0px;
	border: none;
	background-color: transparent;
	cursor: pointer;
	height: 29px;
	display: block;
	float: left;
	overflow: visible;
}

*:first-child+html button[type]{width: 1;} /* IE7 */

button span {
	background: transparent url(../img/btn_left.gif) no-repeat scroll right top;
	display: block;
	padding: 0px 10px 0px 0px; /* sliding doors padding */
	margin: 0px;
}

button span span {
	background: transparent url(../img/btn_right.gif) no-repeat left top;
	color: #646464;
	margin: 0;
	padding: 0 0 0 10px;
	font: 11px Arial, Helvetica, sans-serif;
	line-height: 29px;
	display: block;
	text-decoration: none;
}

/* -------------
 * Inputs
 * ------------- */
.jNiceInputWrapper {
	background: transparent url(../../elements/input_left.gif) no-repeat left top;
	height: 23px;
	padding: 0px;

}

.jNiceInputInner {
	background: transparent url(../../elements/input_right.gif) no-repeat right top;
	padding: 2px 4px 2px 0px;
	margin: 0px 0px 0px 4px;
}

.jNiceInputInner div {
	height: 19px;
}

.jNiceInputInner input {
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	line-height: 18px;
	vertical-align: middle;
	height: 17px;
	color:#404040;
	border: 0;
	padding: 0px;
	margin: 0px;
}

.jNiceSafari .jNiceInputInner div {
	position: relative;
	overflow: hidden;
}

.jNiceSafari input {
	background-color: none;
	position: absolute;
	top: -2px;
	left: -4px;
	height: 26px;
}

/* -------------
 * Radios
 * ------------- */
.jRadioWrapper {float: left; width: 25px;}
.jNiceRadio {
	background: transparent url(../img/radio.gif) no-repeat center top;
	vertical-align: middle;
	height: 14px;
	width: 15px;
	display:block;/*display: -moz-inline-block;*/
	margin: 0 10px 0 0;
}

/* -------------
 * Checkboxes
 * ------------- */
.jNiceCheckbox {
	background: transparent url(../img/checkbox.gif) no-repeat center top;
	vertical-align: middle;
	height: 13px;
	float: left;
	margin: 0 10px 0 0;
	width: 14px;
	display:block;/*display: -moz-inline-block;*/
}

/* -------------
 * Checked - Used for both Radio and Checkbox
 * ------------- */
.jNiceChecked { background-position: center bottom;}

/* -------------
 * Selects
 * ------------- */
.jNiceSelectWrapper {
	width: 280px;
	position:relative;
	height: 26px;
	float: left;
	border: none !important;
}

.jNiceSelectWrapper div span {
	float: none;
	position: absolute;
	width: 250px;
	height: 26px;
	background: url(../img/select_left.gif) no-repeat left top;
	line-height: 18px;
	font: 11px/11px Arial, Helvetica, sans-serif;
	color: #646464;
	padding: 7px 7px 0;
	overflow: hidden;
	border: none !important;
}

.jNiceSelectWrapper div a {
	display: block;
	position: absolute;
	right: 0px;
	width: 30px;
	border: none;
	height: 26px;
	background: url(../img/select_right.gif) no-repeat center center;
}

.jNiceSelectWrapper ul {
	position: absolute;
	width: 250px !important;
	top: 26px;
	left: 0px;
	list-style: none;
	background-color: #FFF;
	display: none;
	margin: 0px;
	padding: 0px;
	border: 1px solid #eaeaea;
	max-height: 99px;
	overflow: auto;
	overflow-y: auto;
	z-index:100;
}

.jNiceSelectWrapper ul li { width: auto !important; }

.jNiceSelectWrapper ul a {
	display: block;
	padding: 7px 7px;
	text-decoration: none;
	color: #9b9b9b;
	font: 11px/11px Arial, Helvetica, sans-serif;
	background-color: #FFF;
}

.jNiceSelectWrapper ul a:hover { background:#f6f6f6; }
.jNiceSelectWrapper ul a.selected { background: #f0f7fa; color: #c66653; }

/* -------------
 * Hidden - used to hide the original form elements
 * ------------- */
.jNiceHidden {display: none;}


code:
/* Basic  ---------------------------------------- */

.clear { clear: both; }

body {
	background: white;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #646464;
	text-align: center;
}

#wrapper {
	text-align: left;
	width: 930px;
	margin: 0 auto;
}

/* Logo  ---------------------------------------- */

h1 {
	margin: 15px 0 10px 5px;
	width: 225px;
	height: 28px;
	background: url(../img/transdmin-light.gif) no-repeat left top;
}

h1 a {
	display: block;
	width: 225px;
	height: 28px;
}

h1 span { display: none; }

/* Main Navigation ---------------------------------------- */

#mainNav {
	width: 918px;
	height: 37px;
	padding: 6px;
	margin: 0 0 30px 0;
	background: url(../img/top-menu-bg.gif) no-repeat left top;
	/* We used a background image making the thick border and the thin one to keep the html structure simple */
}

#mainNav li {
	float: left;
	height: 37px;
	border-right: 1px solid #ddd;
}

#mainNav li a {
	display: block;
	float: left;
	height: 37px;
	font-weight: bold;
	line-height: 37px;
	text-decoration: none;
	color: #646464;
	padding: 0 20px;
}

#mainNav li.logout {
	float: right;
	border-left: 1px solid #ddd;
	border-right: none;
}

#mainNav li a:hover { background: #fdfcf6; }

#mainNav li a.active, #mainNav li a.active {
	background: #f0f0f0 url(../img/top-menu-item-bg.gif) repeat-x left top;
	color: #454545;
}

/* Container ---------------------------------------- */

#containerHolder {
	background: #eee;
	padding: 5px;
}

#container {
	background: #fff url(../img/content.gif) repeat-y left top;
	border: 1px solid #ddd;
	width: 918px;
}

/* Sidebar ---------------------------------------- */

#sidebar {
	width: 179px;
	float: left;
}

#sidebar .sideNav { width: 179px; }

#sidebar .sideNav li { border-bottom: 1px solid #ddd; width: 179px; }

#sidebar .sideNav li a {
	display: block;
	color: #646464;
	background: #f6f6f6;
	text-decoration: none;
	height: 29px;
	line-height: 29px;
	padding: 0 19px;
	width: 141px;
}

#sidebar .sideNav li a:hover { background: #fdfcf6; }

#sidebar .sideNav li a.active, #sidebar .sideNav li a.active:hover {
	background: #f0f7fa;
	color: #c66653;
}

/* Breadcrumb ---------------------------------------- */

h2 {
	width: 718px;
	float: right;
	color: #646464;
	font-size: 16px;
	line-height: 16px;
	font-weight: bold;
	margin: 20px 0 0 0;
	padding: 0 0 10px 0;
	border-bottom: 1px solid #ddd;
}

h2 a {
	color: #646464;
	text-decoration: none;
}

h2 a.active { color: #c66653; }

h2 a:hover { text-decoration: underline; }

/* Content ---------------------------------------- */

#main {
	width: 700px;
	float: right;
	padding: 0 19px 0 0;
}

h3 {
	font-size: 14px;
	line-height: 14px;
	font-weight: bold;
	color: #5494af;
	padding: 0 0 0 10px;
	margin: 20px 0 10px;
}

#main table {
	border-top: 1px solid #ddd;
	width: 700px;
}

#main table tr td {
	background: #f6f6f6;
	padding: 0px 20px;
	height: 29px;
	line-height: 29px;
	border-bottom: 1px solid #ddd;
}

#main table tr.odd td {
	background: #fbfbfb;
}

#main table tr:hover td { background: #fdfcf6; }

#main table .action {
	text-align: right;
	padding: 0 20px 0 10px;
}

#main table tr .action a { margin: 0 0 0 10px; text-decoration: none; color: #9b9b9b; }
#main table tr:hover .action .edit { color: #c5a059; }
#main table tr:hover .action .delete { color: #a02b2b; }
#main table tr:hover .action .view { color: #55a34a; }

#main table tr:hover .action a:hover { text-decoration: underline; }

#main fieldset {
	border: 1px solid #ddd;
	padding: 19px;
	margin: 0 0 20px 0;
	background: #fbfbfb;
}

#main fieldset p { margin: 0 0 14px 0; float: left; width: 100%;  }

#main fieldset label {
	display: block;
	width: 100%;
	margin: 0 0 7px 0;
	line-height: 12px;
}

#main fieldset .text-long {
	border: 1px solid #ddd;
	background: #fff url(../img/input-shaddow.gif) no-repeat left top;
	font: 11px Arial, Helvetica, sans-serif;
	color: #646464;
	padding: 5px 7px;
	width: 264px;
	float: left;
	margin: 0 10px 0 0;
}

#main fieldset .text-medium {
	border: 1px solid #ddd;
	background: #fff url(../img/input-shaddow.gif) no-repeat left top;
	font: 11px Arial, Helvetica, sans-serif;
	color: #646464;
	padding: 5px 7px;
	width: 124px;
	float: left;
	margin: 0 10px 0 0;
}

#main fieldset .text-small {
	border: 1px solid #ddd;
	background: #fff url(../img/input-shaddow.gif) no-repeat left top;
	font: 11px Arial, Helvetica, sans-serif;
	color: #646464;
	padding: 5px 7px;
	width: 44px;
	float: left;
	margin: 0 10px 0 0;
}

#main fieldset .text-long:focus,
#main fieldset .text-medium:focus,
#main fieldset .text-small:focus,

#main fieldset textarea {
	resize: both;
}

.button-submit {
	font: 11px Arial, Helvetica, sans-serif;
	color: #646464;
	width: 94px;
	height: 29px;
	cursor: pointer;
	border: none;
	background: url(../img/button-submit.gif) no-repeat left top;
}

/* Footer ---------------------------------------- */

#footer {
	margin: 10px 0 30px 0;
	font-size: 11px;
	line-height: 11px;
	color: #9B9B9B;
	padding: 0 0 0 5px;
}

#footer a { color: #9B9B9B; }

#footer a:hover { text-decoration: none; }


code:
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	outline: 0;
	font-size: 100%;
	vertical-align: baseline;
	background: transparent;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}

/* remember to define focus styles! */
:focus {
	outline: 0;
}

/* remove textarea resize at Safari */
textarea {
	resize: none;
}

/* remember to highlight inserts somehow! */
ins {
	text-decoration: none;
}
del {
	text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
	border-collapse: collapse;
	border-spacing: 0;
}


code:
/* -----------------------------------------------

	* Screen Style Sheet

	* Name: Transdmin Light

	* Coded by: Perspectived
	  https://www.perspectived.com

----------------------------------------------- */

/* CSS reset by Eric Meyer */
@import url("reset.css");
@import url("layout.css");
@import url("jNice.css");
@import url("hack.css");


code:
/*
 * UPDATED: 12.19.07
 *
 * jNice
 * by Sean Mooney (sean@whitespace-creative.com)
 *
 * To Use: place in the head
 *  <link href="inc/style/jNice.css" rel="stylesheet" type="text/css" />
 *
 *
 * And apply the jNice class the form you want to style
 *
 * To Do: Add textareas, Add File upload
 *
 ******************************************** */
(function($){
	$.fn.jNice = function(options){
		var self = this;
		var safari = $.browser.safari; /* We need to check for safari to fix the input:text problem */

		/* each form */
		this.each(function(){
			/***************************
			  Buttons
			 ***************************/
			 var setButton = function(){
				$(this).replaceWith('<button id="'+ this.id +'" name="'+ this.name +'" type="'+ this.type +'" class="'+ this.className +'">'+ $(this).attr('value') +'');
			};
			$('input:submit, input:reset', this).each(setButton);

			/***************************
			  Check Boxes
			 ***************************/
			$('input:checkbox', this).each(function(){
				$(this).addClass('jNiceHidden').wrap('');
				var $wrapper = $(this).parent();
				$wrapper.prepend('');
				/* Click Handler */
				$(this).siblings('a.jNiceCheckbox').click(function(){
						var $a = $(this);
						var input = $a.siblings('input')[0];
						if (input.checked===true){
							input.checked = false;
							$a.removeClass('jNiceChecked');
						}
						else {
							input.checked = true;
							$a.addClass('jNiceChecked');
						}
						return false;
				});
				/* set the default state */
				if (this.checked){$('a.jNiceCheckbox', $wrapper).addClass('jNiceChecked');}
			});

			/***************************
			  Radios
			 ***************************/
			$('input:radio', this).each(function(){
				$input = $(this);
				$input.addClass('jNiceHidden').wrap('');
				var $wrapper = $input.parent();
				$wrapper.prepend('');
				/* Click Handler */
				$('a.jNiceRadio', $wrapper).click(function(){
						var $a = $(this);
						$a.siblings('input')[0].checked = true;
						$a.addClass('jNiceChecked');
						/* uncheck all others of same name */
						$('a[rel="'+ $a.attr('rel') +'"]').not($a).each(function(){
							$(this).removeClass('jNiceChecked').siblings('input')[0].checked=false;
						});
						return false;
				});
				/* set the default state */
				if (this.checked){$('a.jNiceRadio', $wrapper).addClass('jNiceChecked');}
			});

			/***************************
			  Selects
			 ***************************/
			$('select', this).each(function(index){
				var $select = $(this);
				/* First thing we do is Wrap it */
				$(this).addClass('jNiceHidden').wrap('

');
				var $wrapper = $(this).parent().css({zIndex: 100-index});
				/* Now add the html for the select */
				$wrapper.prepend('

');
				var $ul = $('ul', $wrapper);
				/* Now we add the options */
				$('option', this).each(function(i){
					$ul.append('
'+ this.text +'
');
				});
				/* Hide the ul and add click handler to the a */
				$ul.hide().find('a').click(function(){
						$('a.selected', $wrapper).removeClass('selected');
						$(this).addClass('selected');
						/* Fire the onchange event */
						if ($select[0].selectedIndex != $(this).attr('index') && $select[0].onchange) { $select[0].selectedIndex = $(this).attr('index'); $select[0].onchange(); }
						$select[0].selectedIndex = $(this).attr('index');
						$('span:eq(0)', $wrapper).html($(this).html());
						$ul.hide();
						return false;
				});
				/* Set the defalut */
				$('a:eq('+ this.selectedIndex +')', $ul).click();
			});/* End select each */

			/* Apply the click handler to the Open */
			$('a.jNiceSelectOpen', this).click(function(){
														var $ul = $(this).parent().siblings('ul');
														if ($ul.css('display')=='none'){hideSelect();} /* Check if box is already open to still allow toggle, but close all other selects */
    													$ul.slideToggle();
														var offSet = ($('a.selected', $ul).offset().top - $ul.offset().top);
														$ul.animate({scrollTop: offSet});
														return false;
												});

		}); /* End Form each */

		/* Hide all open selects */
		var hideSelect = function(){
			$('.jNiceSelectWrapper ul:visible').hide();
		};

		/* Check for an external click */
		var checkExternalClick = function(event) {
			if ($(event.target).parents('.jNiceSelectWrapper').length === 0) { hideSelect(); }
		};

		/* Apply document listener */
		$(document).mousedown(checkExternalClick);

		/* Add a new handler for the reset action */
		var jReset = function(f){
			var sel;
			$('.jNiceSelectWrapper select', f).each(function(){sel = (this.selectedIndex<0) ? 0 : this.selectedIndex; $('ul', $(this).parent()).each(function(){$('a:eq('+ sel +')', this).click();});});
			$('a.jNiceCheckbox, a.jNiceRadio', f).removeClass('jNiceChecked');
			$('input:checkbox, input:radio', f).each(function(){if(this.checked){$('a', $(this).parent()).addClass('jNiceChecked');}});
		};

	};/* End the Plugin */

	/* Automatically apply to any forms with class jNice */
	$(function(){$('form.jNice').jNice();	});

})(jQuery);