/**
 * Podpinanie parametru target dla link�w
 * rel = blank | top | self | parent
 */
function externalLinks() 
{
	if (!document.getElementsByTagName) 
	{
		return;
	}
	
	var anchors = document.getElementsByTagName("a");
	
	for (var i=0; i<anchors.length; i++) 
	{
		var anchor = anchors[i];
		
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "blank" || anchor.getAttribute("rel") == "top" || anchor.getAttribute("rel") == "self" || anchor.getAttribute("rel") == "parent"))
		{
			anchor.target = "_" + anchor.getAttribute("rel");
		}
	}
}
window.onload = externalLinks;

/*
 * Obsluga elementow ladowanych podczas ladowania sie strony
 */
$(document).ready(function()
{
	if(parseInt($(window).width()) < 800)
	{
		$('div#wrap').css("width", "984px");
	}
	
	/*
	 * Flash Left Top
	 */
    //$('#flash').flash(
    //	{ src: '/theme/img/flash.swf', 
    //	  width: 482, 
    //	  height: 148 },
    //	{ version: '9' }
    //);
	
	$("a#link-polecane").click(function () {
		$("a#link-polecane").addClass("ajax-active");
		$("a#link-podobne").removeClass("ajax-active");
		
		$("div#ramka-polecane").css("display", "block");
		$("div#ramka-podobne").css("display", "none");
	});
	$("a#link-podobne").click(function () {
		$("a#link-podobne").addClass("ajax-active");
		$("a#link-polecane").removeClass("ajax-active");
		
		$("div#ramka-podobne").css("display", "block");
		$("div#ramka-polecane").css("display", "none");
	});
	
	/*
	 *  Obsługa FAQ 
	 */
	var openLi = -1;
	
	$("ol#faq li").click(function() 
	{
		e = $("ol#faq li").index(this);
		
		if(openLi != e)
		{
			if (openLi >= 0) {
				$("ol#faq li:eq(" + openLi + ") div.faqContent").hide(200);
			}
			
			$("ol#faq li:eq(" + e + ") div.faqContent").show(200);
			
			openLi = e;
		}
	});
	
});


$(window).bind("resize", function()
{
	if(parseInt($(window).width()) < 800)
	{
		$('div#wrap').css("width", "984px");
	}
});

function setCalendar(Action)
{
	if(Action == 'next')
	{
		set_date = setDateView('next');
		
		$.ajax({ 
			type: 		"POST",
			url: 		"/engine/lib/setCalenda.php",
			data: 		"m=" + set_date[0] + "&y=" + set_date[1],		
			success: 	function(msg)
			{
				setDateCalendar('next');
				$("#content-calendar-set").html(msg);
			}
		});
		
	}
	else
	{
		set_date = setDateView('prev');
		
		$.ajax({ 
			type: 		"POST",
			url: 		"/engine/lib/setCalenda.php",
			data: 		"m=" + set_date[0] + "&y=" + set_date[1],		
			success: 	function(msg)
			{
				setDateCalendar('prev');
				$("#content-calendar-set").html(msg);
			}
		});
		
	}
}


function setDateCalendar(Action)
{
	if(Action == 'next')
	{
		mounth++;
		
		if(mounth == 13)
		{
			mounth = 1;
			year++;
		}
	}
	
	if(Action == 'prev')
	{
		mounth--;
		
		if(mounth == 0)
		{
			mounth = 12;
			year--;
		}
	}
}

function setDateView(Action)
{
	m = mounth;
	y = year;
	
	if(Action == 'next')
	{
		m++;
		
		if(m == 13)
		{
			m = 1;
			y++;
		}
	}
	
	if(Action == 'prev')
	{
		m--;
		
		if(m == 0)
		{
			m = 12;
			y--;
		}
	}
	
	return new Array(m, y);
}

/*
 * Obsluga drukowania
 */
function PagePrint(url)
{
	noweOkno = window.open(url, 'okienko', 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=no, status=no, width=570, height=500')
}

/*
 * Obsluga galerii zdjec
 */
$(function() 
{
	$('#foto-content a').lightBox();
});

$(function() 
{
	$('#maps-contact').lightBox();
});
