Cufon.replace('.cufon-light', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.blackcontent H2', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.form-cols', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.news-item .content-col .tytul', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.imb-test-step-2 .start-info p', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.ankieta-wrapper .imb-ankieta-title', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.ankieta-wrapper .imb-pytanie-number', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.resetpass-info-alpha', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.resetpass-info-alpha b, .resetpass-info-alpha strong', { hover: true, fontFamily: 'Palatino Linotype bold'});
Cufon.replace('.page-404 .col1a', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.page-404 .list', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.resetpass-info-pass span', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.imb-test-step-2 .start-info p b, .imb-test-step-2 .start-info p strong', { hover: true, fontFamily: 'Palatino Linotype bold'});
Cufon.replace('.imb-outro-info p', { hover: true, fontFamily: 'Palatino Linotype'});
Cufon.replace('.imb-outro-info p b, .imb-outro-info p strong', { hover: true, fontFamily: 'Palatino Linotype bold'});

var ExternalLink = function(e){
	if ($(this).attr('rel')==='_blank'){
		e.preventDefault();
		window.open( $(this).attr('href'), 'NewWindow'+new Date().getTime());
	}
};

var Menu = {
	intTop: -1,
	intBottom: -1,
	normalMenuHover: {},
	globalMenuHover: {},
	Init: function(){
		Menu.intTop = $('#menu-top a.active').parent().index();
		Menu.intBottom = $('#menu .menu-bottom-container').eq(Menu.intTopMenu).find('a.active').parent().index();
		Menu.normalMenuHover = {
			sensitivity: 3,
			interval: 100,
			over: Menu.ShowMenu,
			timeout: 100,
			out: function(){}
		};
		Menu.globalMenuHover = {
			sensitivity: 3,
			interval: 200,
			over: function(){},
			timeout: 1000,
			out: function(){Menu.SetMenu(Menu.intTop, Menu.intBottom)}
		};
		$('#menu-top li').hoverIntent(Menu.normalMenuHover);
		$('#menu').hoverIntent(Menu.globalMenuHover);
		
	},
	SetMenu: function(intTop, intBottom){
		$('#menu-top a').removeClass('active').eq(intTop).addClass('active');
		$('#menu .menu-bottom-container').removeClass('active').eq(intTop).addClass('active');
		Cufon.replace('.cufon-light', { hover: true, fontFamily: 'Palatino Linotype'});
	},
	ShowMenu: function(){
		var intTop = $(this).index();
		var intBottom = (intTop==Menu.intTop) ? Menu.intBottom : -1;
		Menu.SetMenu(intTop, intBottom);
		
	}
};

var Stopka = {
	intMinSize: 42,
	intOffset: 0,
	Init: function(){
		Stopka.Set();
		setInterval(Stopka.Set, 500);
		$(window).resize(Stopka.Set);
	},
	Set: function(){
		var intTop = $('#headerwrapper').height() + $('#walls').height();
		var intLeft = $(window).height() - intTop;
		if(intLeft>Stopka.intMinSize) $('#footer').css({top:intTop + Stopka.intOffset});
		else $('#footer').css({top: $(window).height() - Stopka.intMinSize + Stopka.intOffset});
	}
};

var Gazeta = {
	intLast: 0,
	Init: function(){
		Gazeta.intLast = $('#picContainer .pic').length -1;
		$('#left').click(Gazeta.LeftClick);
		$('#right').click(Gazeta.RightClick);
	},
	SetPage: function(intPage){
		$('#picContainer .pic').hide().eq(intPage).show();
		if(intPage>0)
			$('#left').addClass('active');
		else
			$('#left').removeClass('active');
		if(intPage<Gazeta.intLast)
			$('#right').addClass('active');
		else
			$('#right').removeClass('active');
	},
	LeftClick: function(e){
		e.preventDefault();
		var intCurrent = $('#picContainer .pic:visible').index();
		if(intCurrent>0) Gazeta.SetPage(intCurrent-1);
	},
	RightClick: function(e){
		e.preventDefault();
		var intCurrent = $('#picContainer .pic:visible').index();
		if(intCurrent<Gazeta.intLast) Gazeta.SetPage(intCurrent+1);
	}
};

var Legendy = {
	Init: function(){
		$('#legendy-wrapper #legendy-menu a').click(Legendy.ShowLegend);
	},
	ShowLegend: function(e){
		e.preventDefault();
		legenda = $(this).attr('class');
		if($(this).hasClass('active') == false){
			$('#legendy-wrapper #legendy-menu a').removeClass('active');
			$(this).addClass('active');
			$('#legendy-wrapper .content').hide();
			$('#legendy-wrapper .content.'+legenda).show();
		}
	}
};

var Popup = {
	objVideo: null,
	Init: function(){
		$('#popup-close').click(Popup.CloseClick);
		//Popup.objVideo = $('#two').clone(true);
		//$('#two').remove();
	},
	CloseClick: function(e){
		e.preventDefault();
		Popup.Hide();
	},
	Show: function(){
		$('#content object').css({'visibility':'hidden'});
		$('#content').css({'backgroundImage': 'url("/assets/images/bg-main.jpg")'});
		$('#popup').show();
	},
	Hide: function(){
		$('#two')[0].PauseVideo();
		$('#popup').hide();
		$('#content').css({'backgroundImage': 'none'});
		$('#content object').css({'visibility':'visible'});
	}
};

$(document).ready(function(){
	Menu.Init();
	Stopka.Init();
	Gazeta.Init();
	Legendy.Init();
	Popup.Init();
	$('a').click(ExternalLink);
	$('#select-country').selectbox();
	$('#select-day').selectbox();
	$('#select-month').selectbox();
	$('#select-year').selectbox();
	$('.jquery-selectbox-list').jScrollPane().hide();
});

