
	$(document).ready(function () {
		$.each($('.default-value'), function (k, input) {
			input = $(input);
			input.defaultValue = input.attr('value');
			input.focus(ref(input, function () {
				if (this.attr('value') == this.defaultValue)
					this.attr('value', '');
			}));
			input.blur(ref(input, function () {
				if (this.attr('value') == '')
					this.attr('value', this.defaultValue);
			}));
		});

		$('._blank').click(function () {
			window.open(this.href);
			return false;
		});

		var switch_tab = function () {
			$('.index').parent().fadeOut("normal", ref(this, function () {
				$('.art').hide();
				$('#' + $(this).parent().parent().attr('id').replace('tab-', 'art-')).show();

				$('.index').css('background-image', 'url(' + JS_HOST + 'view/img/back/' + $(this).parent().parent().attr('id').replace('tab-', '') + '.png)');

				$('.index').parent().fadeIn("normal");
			}));

			$('.tabs li').removeClass('active');
			$(this).parent().parent().addClass('active');
		};

		$('.tabs a').click(function (e) {
			clearInterval(tab_switching);
			
			ref(this, switch_tab)();

			e.stopPropagation();
			return false;
		});

		var tab_switching = setInterval(function () {
			if ($('.tabs li.active').next().length > 0) {
				ref($('.tabs li.active').next().find('a').get(0), switch_tab)();
			} else {
				ref($('.tabs li:first-child').find('a').get(0), switch_tab)();
			}
		}, 8000);

		$('.no-copy').each(function () {
			this.lastValue = $(this).val();
		});

		$('.no-copy').keydown(function () {
			this.lastValue = $(this).val();
		});

		$('.no-copy').change(function () {
			//console.log(Math.abs(this.lastValue.length - $(this).val()));
			
			if (($(this).val().length - this.lastValue.length) > 2) {
				$(this).val(this.lastValue);
			}
		});
	});

	function ref(object, method) {
		return function () {
			return method.apply(object, arguments);
		};
	}

	function debug(v) {
		try {
			if (is_def(console))
				console.info(v);
		} catch (e) {
		}
	}

	function load_editor_for(f, style, load_css, maxchars) {
//		var _editor = {
//			mode : "exact",
//			theme : "advanced",
//			language: "pl",
//			elements : f,
//			skin : "o2k7",
//			skin_variant : "silver",
//			plugins : "safari,style,layer,table,advhr,advimage,advlink,emotions,iespell,contextmenu" + (maxchars ? ",maxchars" : ""),
//			// Theme options
//			theme_advanced_buttons1 : "bold,italic,underline,|,bullist,numlist,|,forecolor,fontsizeselect,|,outdent,indent,|,link,unlink,image,|,removeformat,cleanup,code,fullscreen",
//			theme_advanced_buttons2 : "",
//			theme_advanced_buttons3 : "",
//			theme_advanced_buttons4 : "",
//			theme_advanced_toolbar_location : "top",
//			theme_advanced_toolbar_align : "center",
//			theme_advanced_statusbar_location : "bottom",
//			theme_advanced_resizing : true,
//			theme_advanced_path : false,
//
//			max_chars : maxchars ? maxchars : 99999999,
//			max_chars_indicator : "lengthBox",
//
//			content_css: JS_HOST + "view/style/editor.css" ,
//			body_id: "text",
//			body_class: " " + style
//		};
//
//		tinyMCE.init(_editor);
	}
