var SMG = {

	start: function() {
		this.tweakLayout();
		//this.tweakButtons();
		this.addFunctionalities();
		this.displayPartners();
		this.startRotator(5);
	},
	
	
	tweakLayout: function() {
		$('html').addClass('js');
		
		// 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');
				}
			});
		}
		
		// Give hover
		function giveHover($el) {
			$el.hover(function() {
				$el.addClass('fHover');
			}, function() {
				$el.removeClass('fHover');
			});
		}
		if ($.browser.msie && /MSIE 6.0/.test(navigator.userAgent)) {
			giveHover($('#nav'));
		}
		
		// Fix png links in IE6
		if ($.browser.msie && /MSIE 6.0/.test(navigator.userAgent)) {
			// logo
			if (document.getElementById('name')) {
				if ($('#name a').length) {
					var href = $('#name a:first').attr('href');
					$('#masthead').append('<a href="' + href + '" id="logo-fix"></a>');
				}
			}

		}
	},
	
	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="btn-l"></span><span class="btn-c">' + val + '</span><span class="btn-r"></span></a>');
			$submit.next().click(function() {
				$submit.click();
				return false;
			});
			$submit.hide();
		});
	},
	
	startRotator: function(interval) {
		if (document.getElementById('rotator')) {
			$('#rotator').cycle({
				fx: 'fade',
				timeout: 1000 * interval
			});
		}
	},
	
	displayPartners: function() {

		var flashvars = {};
		var params = {
			wmode: 'transparent'
		};
		var attributes = {};

		swfobject.embedSWF("swf/partners.swf?v=5", "partners-box", "657", "79", "8.0.0", "/display/swf/expressInstall.swf", flashvars, params, attributes);
	},
	
	addFunctionalities: function() {
		//create mailtos
		$('a.mail').each(function() {
			var $this = $(this);
			$this.text($this.text($this.text().replace('[malpka]', '@').replace('[kropeczka]', '.')));
			$this.attr('href', 'mailto:' + $this.text());
		});
		
		//adding blank
		$('a.blank').attr('target', '_blank');
	}
	
}

$(function() {
	SMG.start();
});