var MyUI = {


	start: function() {
	
		// domyślne ustawienia i opcje
		this.defaultSetting();
		
		// ulepszenie i walidacja formularzy
		this.enhanceForm();
		
		// ulepszenie testu
		this.enhanceTest.init();
	
	},
	
	
	defaultSetting: function() {
		
		// enhance labels
		$('label').each(function(i) {
			$(this).attr('id', 'label_' + $(this).attr('for'));
		});
		
		// enhance links
		$("a[rel~='external']").attr('target', '_blank').addClass('new_window');
		$("a[class~='history_back']").click(function(e) {
			history.back();
			e.preventDefault();
		});
		
	},
	
	
	enhanceForm: function() {
	
		// dodanie interakcji dla pól formularzy - input
		$('input:text, textarea').bind({
			focus: function() {
				$(this).css(schema_style.input.on);
				$('#' + 'label_' + this.id).css(schema_style.input.on);
			},
			blur: function() {
				$(this).css(schema_style.input.off);
				$('#' + 'label_' + this.id).css(schema_style.input.off);
			}
		});

		// dodanie interakcji dla pól formularzy - button
		$('input:submit, input:button, input:reset').bind({
			mouseover: function() {
				$(this).css(schema_style.button.on);
			},
			mouseout: function() {
				$(this).css(schema_style.button.off);
			}
		});
		
	
	},
	
	
	enhanceTest: {
	
		init: function() {
	
			// strona testu
			if ($('div.test').size() > 0) {
			
				this.colourTest();
				this.enhanceChecbox();
				
			}
			
			
			// podsumowanie
			this.summaryTest();
			
			
			// wyniki testu
			if ($('.info_list').size() > 0) {
			
				// dodaj okrągłe rogi
				if (typeof $.corner ==='function' || typeof $.fn.corner === 'function') {
					$('.info_list').corner("25px");
				}
				
				// interaktywna tabelka
				$('tr').bind({
					mouseover: function() {
						$(this).css(schema_style.table.on);
					},
					mouseout: function() {
						$(this).css(schema_style.table.off);
					}
				});			
				
			}
		
		},
		
		
		colourTest: function() {
		
			// zmiana koloru tła po najechaniu na komórkę
			$('div.row_one').bind({
				mouseover: function() {
					$(this).css(schema_style.test_one.on);
				},
				mouseout: function() {
					$(this).css(schema_style.test_one.off);
				}
			});

			$('div.row_two').bind({
				mouseover: function() {
					$(this).css(schema_style.test_two.on);
				},
				mouseout: function() {
					$(this).css(schema_style.test_two.off);
				}
			});
		
			// zaokrąglenie rogów div pytań z wyjątkiem IE - komplikacje z jquery.checkbox
			if (!$.browser.msie && typeof $.corner === 'function' || typeof $.fn.corner === 'function') {
				$('div.row_one, div.row_two').corner("15px");
			}
		
		},
		
		
		enhanceChecbox: function() {
		
			// dodanie hover dla tekstu odpowiedzi
			$('div.test label').bind({
				mouseover: function() {
					$(this).css(schema_style.text_label.on);
				},
				mouseout: function() {
					$(this).css(schema_style.text_label.off);
				}
			});
		
			// zamiana standardowych formularzy na ładniejsze
			$('input:checkbox').checkbox();
		
		},
		
		
		summaryTest: function() {
		
			if ( ($("#test").size() > 0) && ($("#form_sms").size() > 0) ) {
			
				$("#test").validate({
					errorPlacement: function(error, element) {
						error.appendTo( element.parent("td").append("<div></div>") );
					},
					rules: {
						form_nazwisko: {
							required: true,
							minsize: 2,
							maxsize: 22
						},
						form_mail: {
							email: true
						},
						form_sms: {
							required: true,
							remote: page_path+"/ajax/sms.php"
						}
					},
					messages: {
						form_sms: {
							remote: 'Proszę wprowadzić prawidłowy kod dostępu.'
						}
					}
				});
			
			}
			
			// dodanie tab-zakładek
			if ($("#tabs_test").size() > 0) {
			
				$("#tabs_test").tabs({
					fxFade: true,
					fxSpeed: 'fast'
				});
			
			}
		
		}
	
	
	}
	
}


// po wczytaniu zawartości serwisu, załadowanie kodu javascript
$(document).ready(function() { MyUI.start() });
