var _config = {
	controller: '',
	action: ''
}

var js_lang = {
	'pl': { 'twoj_adres': 'Twój adres e-mailowy' },
	'en': { 'twoj_adres': 'Your e-mail address' }
};

var Root = {

	init: function() {

		// Fancybox
		$('.fancyboxImage').fancybox({
			titleShow: false
		});

		$('#newsletterSignin1').fancybox({
			titlePosition: 'inside',
			transitionIn: 'none',
			transitionOut: 'none',
			titleShow: false
		});

		$('#newsletterSignin2').fancybox({
			titlePosition: 'inside',
			transitionIn: 'none',
			transitionOut: 'none',
			titleShow: false
		});

		if ($.browser.msie && parseInt($.browser.version) == 6) {
				$('.mainMenu > .menu2 > li').each(function(i,el){

					$(this).bind('mouseenter',function(e){
							$(this).children("li").addClass('hover');
							$(this).children("a").addClass('hover');
							$(this).addClass('hover');


						}).mouseleave(function(e) {
							$(this).children("li").removeClass('hover');
							$(this).children("a").removeClass('hover');
							$(this).removeClass('hover');
						});
				});
			}

		// Na skróty
		if (_config.controller != 'index') {

			$('#shortcuts').each(function(i,el){

					$(this).bind('mouseenter',function(e){
							$(this).children("#shortcutsList").show();
							$(this).children("#shortcuts").show();
							$(this).children("#shortcutsButton").addClass('hover');

						}).mouseleave(function(e) {
							$(this).css('height','auto');
							$(this).children("#shortcutsList").hide();
							$(this).children("#shortcutsList").removeClass('hover');
							$(this).children("#shortcutsButton").removeClass('hover');

						});
				});
		}

		// Newsletter
		var newsletter1 = $('#newsletter1');
		var newsletterEmail1 = newsletter1.find('#newsletterEmail1');
		var modal1 = newsletter1.find('#modal1');

		newsletterEmail1.focus(function(){
			$(this).val('');
		}).blur(function(){
			if ($(this).val() == '')
				$(this).val(js_lang[LANG]['twoj_adres']);
		}).val(js_lang[LANG]['twoj_adres']);

		newsletter1.find('#newsletterSignin1').click(function(){
			$.post(WEB_ROOT + 'newsletter,signin.html', {
				email: newsletterEmail1.val()
			}, function(response){
				modal1.html(response);
			});

			return false;
		});

		var newsletter2 = $('#newsletter2');
		var newsletterEmail2 = newsletter2.find('#newsletterEmail2');
		var modal2 = newsletter2.find('#modal2');

		newsletterEmail2.focus(function(){
			$(this).val('');
		}).blur(function(){
			if ($(this).val() == '')
				$(this).val(js_lang[LANG]['twoj_adres']);
		}).val(js_lang[LANG]['twoj_adres']);

		newsletter2.find('#newsletterSignin2').click(function(){
			$.post(WEB_ROOT + 'newsletter,signin.html', {
				email: newsletterEmail2.val()
			}, function(response){
				modal2.html(response);
			});

			return false;
		});

		// Wyszukiwarka
		$('#searchForm .inputKeywords').focus(function(){
			if ($(this).val() == 'Szukaj:')
				$(this).val('');
		}).blur(function(){
			if ($(this).val() == '')
				$(this).val('Szukaj:');
		});
	}
}

$(document).ready(function(){
	var controller = _config.controller.charAt(0).toUpperCase() + _config.controller.substr(1);

	Root.init();

	if (window[controller] != undefined) {
		if (typeof(window[controller]['init']) == 'function') {
			window[controller]['init']();
		}

		if (typeof(window[controller][_config.action]) == 'function') {
			window[controller][_config.action]();
		}
	}
});

