/*
JavaScript pagination
by cookie.pl
*/

var Pagination = {
	tile_width: 21,
	this_pid: 1,

	init: function() {
		this.style_buttons(1);
		this.style_buttons(2);
		this.style_buttons(3);
		this.style_buttons(4);
		this.style_buttons(5);
		this.style_buttons(6);
		this.style_buttons(7);

		this.stretchers = document.getElementsByClassName('stretcher'); //div that stretches
		this.toggles = document.getElementsByClassName('page_but'); //div where I click on
		this.myAccordion = new fx.Accordion( this.toggles, this.stretchers, {opacity: true, height: true, duration: 400 } );

		this.checkHash();
		if (!this.checkHash()) this.myAccordion.showThisHideOpen(this.stretchers[0]);

		},

	print: function() {
			createPopUpWindow( 'http://'+window.location.host+window.location.pathname+'?print', 600, 560, 'woda_pitna_print');
			return false;
		},

	checkHash: function() {
			var found = false;
			this.toggles.each(function(h3, i){
				if (window.location.href.indexOf(h3.title) > 0) {
					Pagination.myAccordion.showThisHideOpen(Pagination.stretchers[i]);
					found = true;
				}
			});
			return found;
		},

	style_buttons: function(pid) {
		if ($('page'+pid+'_but')) {
			var num = pid - 1;
			var but = $('page'+pid+'_but');
			if(but.className != 'page_but_active') {
				but.style.backgroundPosition = '-' + num*this.tile_width + 'px 0%';
				}
			else {
				but.style.backgroundPosition = '-' + num*this.tile_width + 'px 100%';
				}
			but.onmouseover = function() {
				if(this.className != 'page_but_active') {
					var num = parseInt(this.id.replace('page','').replace('_but','')) - 1;
					this.style.backgroundPosition = '-' + num*Pagination.tile_width + 'px 100%';
					}
				};
			but.onmouseout = function() {
				if(this.className != 'page_but_active') {
					var num = parseInt(this.id.replace('page','').replace('_but','')) - 1;
					this.style.backgroundPosition = '-' + num*Pagination.tile_width + 'px 0%';
					}
				};
			}
		},

	avoid_scrolling: function() {
		$('page').style.position = 'fixed';
		},

	permit_scrolling: function() {
		$('page').style.position = 'absolute';
		},

	show_page: function(node) {
		if (node) {
			var num = parseInt(node.id.replace('page','').replace('_but','')) - 1;
			node.style.backgroundPosition = '-' + num*this.tile_width + 'px 100%';
			node.className = 'page_but_active';
			}
		},

	hide_pages: function() {
		for(pid=1; pid<8; pid++) {
			if ($('page'+pid+'_but')) {
				var num = pid - 1;
				$('page'+pid+'_but').style.backgroundPosition = '-' + num*this.tile_width + 'px 0%';
				$('page'+pid+'_but').className = 'page_but';
				}
			}
		}

}


var submenuKampShowHide;
function submenuKampInit() {
	submenuKampShowHide = new fx.Height($('kampania_submenu') , {duration: 400});
	$('kampania_but').onclick = function()
		{
					submenuCisowShowHide.hide();
					submenuGdzieShowHide.hide();
					newsletterShowHide.hide();
					//submenuDzienWodyShowHide.hide();
					$('cisowianka').className = 'collapsed';
					$('newsletter').className = 'collapsed';
					$('gdzie_pomagalismy').className = 'collapsed';

		if (parseInt($('kampania_submenu').style.height) == 0)
			$('kampania').className = 'expanded';
		else
			$('kampania').className = 'collapsed';
		}
	$('kampania_but').onmouseover = function() {
		$('kampania_but').style.textDecoration = 'underline';
		}
	$('kampania_but').onmouseout = function() {
		$('kampania_but').style.textDecoration = 'none';
		}
	}
var submenuCisowShowHide;
function submenuCisowInit() {
	submenuCisowShowHide = new fx.Height($('cisowianka_submenu') , {duration: 400});
	$('cisowianka_but').onclick = function()
		{
		$('kampania_submenu').style.height = "auto";
		submenuCisowShowHide.toggle();
					submenuProgShowHide.hide();
					newsletterShowHide.hide();
					submenuGdzieShowHide.hide();
					//submenuDzienWodyShowHide.hide();
					$('programy').className = 'collapsed';
					$('newsletter').className = 'collapsed';
					$('gdzie_pomagalismy').className = 'collapsed';

		if (parseInt($('cisowianka_submenu').style.height) == 0)
			$('cisowianka').className = 'expanded';
		else
			$('cisowianka').className = 'collapsed';
		}
	$('cisowianka_but').onmouseover = function() {
		$('cisowianka_but').style.textDecoration = 'underline';
		}
	$('cisowianka_but').onmouseout = function() {
		$('cisowianka_but').style.textDecoration = 'none';
		}
	}
var submenuProgShowHide;
function submenuProgInit() {
	submenuProgShowHide = new fx.Height($('programy_submenu') , {duration: 400});
	$('programy_but').onclick = function()
		{
		submenuProgShowHide.toggle();
					submenuKampShowHide.hide();
					submenuCisowShowHide.hide();
					submenuGdzieShowHide.hide();
					newsletterShowHide.hide();
					//submenuDzienWodyShowHide.hide();
					$('kampania').className = 'collapsed';
					$('cisowianka').className = 'collapsed';
					$('newsletter').className = 'collapsed';
					$('gdzie_pomagalismy').className = 'collapsed';

		if (parseInt($('programy_submenu').style.height) == 0)
			$('programy').className = 'expanded';
		else
			$('programy').className = 'collapsed';
		}
	$('programy_but').onmouseover = function() {
		$('programy_but').style.textDecoration = 'underline';
		}
	$('programy_but').onmouseout = function() {
		$('programy_but').style.textDecoration = 'none';
		}
	}
var newsletterShowHide;
function newsletterInit() {
	newsletterShowHide = new fx.Height($('newsletter_submenu') , {duration: 400});
	$('newsletter_but').onclick = function()
		{
		newsletterShowHide.toggle();
					submenuShowHide.hide();
					//submenuDzienWodyShowHide.hide();
					$('programy').className = 'collapsed';

		if (parseInt($('newsletter_submenu').style.height) == 0)
			$('newsletter').className = 'expanded';
		else
			$('newsletter').className = 'collapsed';
		}
	$('newsletter_but').onmouseover = function() {
		$('newsletter_but').style.textDecoration = 'underline';
		}
	$('newsletter_but').onmouseout = function() {
		$('newsletter_but').style.textDecoration = 'none';
		}
	}


/* Mateusz Edit 24.07 2008 */
/* gdzie_pomagalismy */
var submenuGdzieShowHide;
function submenuGdzieInit() {
	submenuGdzieShowHide = new fx.Height($('gdzie_pomagalismy_submenu') , {duration: 400});
	$('gdzie_pomagalismy_but').onclick = function()
		{
		submenuGdzieShowHide.toggle();
					submenuKampShowHide.hide();
					submenuCisowShowHide.hide();
					submenuProgShowHide.hide();
					newsletterShowHide.hide();
					//submenuDzienWodyShowHide.hide();

					$('kampania').className = 'collapsed';
					$('cisowianka').className = 'collapsed';
					$('programy').className = 'collapsed';
					$('newsletter').className = 'collapsed';

		if (parseInt($('gdzie_pomagalismy_submenu').style.height) == 0)
			$('gdzie_pomagalismy').className = 'expanded';
		else
			$('gdzie_pomagalismy').className = 'collapsed';
		}
	$('gdzie_pomagalismy_but').onmouseover = function() {
		$('gdzie_pomagalismy_but').style.textDecoration = 'underline';
		}
	$('gdzie_pomagalismy_but').onmouseout = function() {
		$('gdzie_pomagalismy_but').style.textDecoration = 'none';
		}
	}

function submenuDzienWodyInit()
{
	submenuDzienWodyShowHide = new fx.Height($('dzien_wody_submenu') , {duration: 400});
	$('dzien_wody_but').onclick = function()
	{
		submenuGdzieShowHide.hide();
		submenuKampShowHide.hide();
		submenuCisowShowHide.hide();
		submenuProgShowHide.hide();
		newsletterShowHide.hide();
		submenuDzienWodyShowHide.toggle();
		$('kampania').className = 'collapsed';
		$('cisowianka').className = 'collapsed';
		$('programy').className = 'collapsed';
		$('newsletter').className = 'collapsed';

		if (parseInt($('dzien_wody_submenu').style.height) == 0)
			$('dzien_wody').className = 'expanded';
		else
			$('dzien_wody').className = 'collapsed';
		}
	$('dzien_wody_but').onmouseover = function() {
		$('dzien_wody_but').style.textDecoration = 'underline';
	}
	$('dzien_wody_but').onmouseout = function() {
		$('dzien_wody_but').style.textDecoration = 'none';
	}
}


/* pop up window */
function createPopUpWindow(myURL,myWidth,myHeight,myName) {
	if(myName=='')
	{
		var day=new Date();
		var myName='a'+day.getTime();
	}
	var winl = (screen.width-myWidth)/6;
	var wint = (screen.height-myHeight)/4;
	var settings ='height='+myHeight+',';
	settings +='width='+myWidth+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars=1,';
	settings +='status=0,';
	settings +='resizable=1';
	win=window.open(myURL,myName,settings);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
	}




/*

var t = 10;
window.onload = function() {
new FloatLayer('how_can_u_help',15,15,10);
detach();
}

function detach(){
	lay=document.getElementById('how_can_u_help');
	l=getXCoord(lay);
	t=getYCoord(lay);
	lay.style.position='absolute';
	lay.style.top=t;
	lay.style.left=l;
	getFloatLayer('how_can_u_help').initialize();
	alignFloatLayers();
}*/

/* rekalma konkurs
function konkursImg() {
	var sidebar = document.getElementById('sidebar');
		sidebar.style.position = 'relative';
	var content = document.getElementById('content');

	if(!document.getElementById('konkursInfo')) {
		var infoImgA = document.createElement('a');
			infoImgA.href = '/aktualnosci/full/18';
			infoImgA.setAttribute('id', 'konkursInfo');
		var infoImg = document.createElement('img');
			infoImg.src = '/images/infobar-konkurs.jpg';
			infoImg.style.position = 'absolute';

		infoImgA.appendChild(infoImg);

		if(document.body.clientWidth < 1130) {
			infoImg.style.bottom = '0';
			infoImg.style.left = '-155px';
			sidebar.appendChild(infoImgA);
		}
		else {
			infoImg.style.top = '0';
			infoImg.style.right = '-140px';
			content.appendChild(infoImgA);
		}
	}
	else {
		var konkursInfo = document.getElementById('konkursInfo');
		var konkursInfoImg = konkursInfo.getElementsByTagName('img')[0];

		if(document.body.clientWidth < 1130) {
			konkursInfoImg.style.top = 'auto';
			konkursInfoImg.style.right = 'auto';
			konkursInfoImg.style.bottom = '0';
			konkursInfoImg.style.left = '-155px';
			sidebar.appendChild(konkursInfo);
		}
		else {
			konkursInfoImg.style.top = '0';
			konkursInfoImg.style.right = '-140px';
			konkursInfoImg.style.bottom = 'auto';
			konkursInfoImg.style.left = 'auto';
			content.appendChild(konkursInfo);
		}
	}
}

window.onresize = konkursImg;*/
