Cufon.replace('.gotham', {
	fontFamily : 'Gotham'
});
Cufon.replace('.gotham-bold', {
	fontFamily : 'Gotham Bold'
});
Cufon.replace('.gotham-book', {
	fontFamily : 'Gotham Light'
});
$(function() {

	/**/// instrukcje dla IE lt 9
	if ($.browser.msie && $.browser.version < 9) {
		// selektory css3
		$("table").attr('cellspacing', '0').find("tbody tr:nth-child(2n)")
				.addClass("odd");
		$(".nav-sub.double ul ul:last-child, #breadcrumbs li:last-child")
				.addClass("last-child");
		$(".related li:nth-child(2n)").addClass("nth-child");
		$(".related li:nth-child(2n+3)").addClass("clear");
	}

	/**/// instrukcje dla Opery
	if ($.browser.opera) {
		$("html").addClass("opera");
	}

	/**/// instrukcje dla Webkit
	if ($.browser.webkit) {
		$("html").addClass("webkit");
	}

	/**/// instrukcje dla Mozilla
	if ($.browser.mozilla) {
		$("html").addClass("mozilla");
	}

});

var intEs2 = setInterval("sTab()", 5000);
function sTab() {

	var _active = $('.osoba-kontakt').find('div.active');
	if (_active.next('div').length > 0) {
		_next = _active.next();
	} else {
		_next = $('.osoba-kontakt div:first');
	}
	_active.fadeTo(500, 0);
	_active.removeClass('active');
	_next.fadeTo(2000, 1);
	_next.addClass('active');

}

var intEs3 = setInterval("sTab3()", 10000);
function sTab3() {

	var _activeS = $('.content-hp-box').find('div.active');
	var _activeS_li = $('.nav-hp').find('li.active');

	if (_activeS.next().length > 0) {
		_nextS = _activeS.next();
	} else {
		_nextS = $('.content-hp-box div:first');
	}

	if (_activeS_li.next().length > 0) {
		_nextS_li = _activeS_li.next();
	} else {
		_nextS_li = $('.nav-hp li:first');
	}
	_activeS.removeClass('active');
	_nextS.addClass('active');
	_activeS_li.removeClass('active');
	_nextS_li.addClass('active');

}

startList = function() {
	initInputLabelFromInput('#form_kontakt_field_name');
	initInputLabelFromInput('#form_kontakt_field_firma');
	initInputLabelFromInput('#form_kontakt_field_phone');
	initInputLabelFromInput('#form_kontakt_field_email');
	initInputLabelFromInput('#form_kontakt_field_kommentar');
	$('#partners-list a').attr('target', '_blank');
	NavAkt();
	slide();
	if ($('div').hasClass('s-404')) {
		setTimeout('redirect()', 10000);
	}

	if ($('body').hasClass('kontakt')) {
		$('.form-kontakt .btn span').text('pola wymagane');
	}
};
window.onload = startList;

function slide() {
	$('.gal-marki img').each(function(s, d) {
		$(d).attr('id', 'slide' + s);
	});
}

function initInputLabelFromInput(input_id) {
	var input = $(input_id);
	if(input.length > 0){
		var label = input.closest('label');
		var showlabel = function() {
			if (!input.val().length) {
				label.addClass('showlabel');
			}
		};
		input.focus(function() {
			label.removeClass('showlabel');
		}).blur(function() {
			showlabel();
		});
		label.find('span').mousedown(function() {
			console.log('foo');
			input.focus();
		});
		showlabel();		
	}
}

function NavAkt() {
	(function() {
		var items = $('.menu-left #news-list li');
		var divs = $('.article-content-load div');
		var map = {};
		var currentHash = '';

		items.each(function(s) {
			var _this = $(this);

			var href = _this.find('a').attr('href');
			var pos = href.indexOf('#');
			var set = null;
			if (pos > -1) {
				set = href.substr(pos);
				map[set] = function() {
					items.removeClass('active');
					divs.removeClass('active');
					_this.addClass('active');

					$('.article-content-load div').eq(s).addClass('active');
				};
			}

			_this.click(function(e) {
				e.preventDefault();

				if (set) {
					currentHash = set;
					window.location.hash = set;
					map[set]();
				}
			});
		});

		var fromhash = function() {
			if (window.location.hash != currentHash) {
				if (map[window.location.hash]) {
					map[window.location.hash]();
				}
				currentHash = window.location.hash;
			}
		};
		fromhash();
		setInterval(fromhash, 300);
	})();

	$('.menu-top #news-list li').each(function(s, d) {
		$(d).click(function(e) {
			e.preventDefault();
			var _this = $(this);
			$('.menu-top #news-list li').removeClass('active');
			$('.article-content-load div').removeClass('active');
			var id_save = $('.gal-marki img').eq(s).attr('id');
			$('.gal-marki #slide0').attr('id', id_save);
			$('.gal-marki img').eq(s).attr('id', 'slide0');

			_this.addClass('active');
			$('.article-content-load div').eq(s).addClass('active');
			$('.gal div').eq(s).addClass('active');

		});
	});

	/*
	 * $('.gal-marki a').each( function(s,d){
	 * 
	 * $(d).click( function(e){ e.preventDefault(); var _this=$(this); var sS =
	 * s+1; $('.menu-top #news-list li').removeClass('active');
	 * $('.article-content-load div').removeClass('active'); var id_save =
	 * $('.gal-marki img').eq(sS).attr('id'); $('.gal-marki
	 * #slide0').attr('id',id_save); $('.gal-marki
	 * img').eq(sS).attr('id','slide0');
	 * 
	 * 
	 * 
	 * _this.addClass('active'); $('.article-content-load
	 * div').eq(sS).addClass('active'); $('.gal div').eq(sS).addClass('active'); } ); } );
	 */

	$('.nav-hp li').each(function(s, d) {

		$(d).click(function(e) {
			e.preventDefault();
			var _this = $(this);
			window.clearInterval(intEs3);

			$('.nav-hp li').removeClass('active');
			$('.content-hp-box div').removeClass('active');
			_this.addClass('active');
			$('.content-hp-box div').eq(s).addClass('active');

		});

	});

}
