var Wifi = {

	start: function() {
		this.tweakLayout();
		this.tweakButtons();
		this.tweakCheckboxes();
		this.addFunctionalities();
	},
	
	
	tweakLayout: function() {
		$('html').addClass('js');
		var global = this;
		
		// Sign inputs for IE
		if ($.browser.msie) {
			$('input').each(function() {
				if ($(this).attr('type') == 'text') {
					$(this).addClass('text');
				}
				else if ($(this).attr('type') == 'password') {
					$(this).addClass('password');
				}
				else if ($(this).attr('type') == 'checkbox') {
					$(this).addClass('checkbox');
				}
				else if ($(this).attr('type') == 'radio') {
					$(this).addClass('radio');
				}
			});
		}
	},
	
	tweakButtons: function() {
		$('input.button').each(function() {
			var $submit = $(this);
			var classes = this.className;
			var val = $submit.attr('value');
			$submit.after('<a class="' + classes + '"><span class="binner">' + val + '</span></a>');
			$submit.next().click(function() {
				$submit.click();
				return false;
			});
			$submit.hide();
		});
	},
	
	addFunctionalities: function() {
		//search field
		$('#search .field input').each(function() {
			if (!document.getElementById('main-page')) {
				var $this = $(this);
				$this.addClass('pre');
				$this.val('szukaj hotspota - wpisz miasto');
				$this.focus(function() {
					$this.val('')
					$this.removeClass('pre');
					$this.unbind('focus');
				});
			}
		});
		
		//search-more button
		$('#search-more').each(function() {
			var $this = $(this);
			var txt = $this.find('.binner').text();
			$this.find('.binner').html('<span class="dropdown">' + txt + '</span>');
			var $adv = $('#advanced-search-options');
			$this.toggle(function() {
				$adv.slideDown();
				$this.addClass('down');
				if (document.getElementById('main-page')) {
					$this.find('.dropdown').text('ukryj więcej opcji');
				}
				return false;
			}, function() {
				$adv.slideUp();
				$this.removeClass('down');
				if (document.getElementById('main-page')) {
					$this.find('.dropdown').text('więcej opcji');
				}
				return false;
			});
		});
	},
	
	tweakCheckboxes: function() {
		$('body').append('<img id="preloaded" src="css/i/chckbx/chckbx-on.png" style="display:none" alt="" />');
		setTimeout(function() {
			$('#preloaded').remove();
		}, 500);
		$('label.check').each(function() {
			var $label = $(this);
			$label.find(':checkbox:first').each(function() {
				var check = this;
				var $check = $(this);
				$label.addClass('chckbx');
				if (check.checked) {
					$label.addClass('on');
				}
				$check.hide();
				
				$label.click(function() {
					check.checked = !check.checked;
					if (check.checked) {
						$label.addClass('on');
					}
					else {
						$label.removeClass('on');
					}
					return false;
				});
			
			});
		});
	}
}

$(function() {
	Wifi.start();
})