var glob;

function mainLoop()
{
	swapImages(glob.obj,0);
	setTimeout("mainLoop();",glob.wait);
}

function swapImages(obj,i)
{
	if (obj[i].parentNode.style.display == 'block') {
		obj[i].parentNode.style.display = 'none';
		i++;
		if (!obj[i]) i=0;
		obj[i].parentNode.style.display = 'block';
	} else {
		i++;
		swapImages(obj,i);
	}
}

function openDialog(text){
	$("#dialog").html(text);
	$("#dialog").dialog({
		'modal':true,
		show: 'blind',
		hide: 'blind',
		'width': 540
	});
}

function openDialogBig(title,text){
	$("#dialog").html(text);// title: title,
	$("#dialog").dialog({
		'modal':true,
		show: 'blind',
		hide: 'blind',
		'width': 1000,
		'height': $(window).height()-100
	});
}

function addajax(data) {
	$('#zapform').html($('#art',data).find('#wynik').html());
	$('#zapform').show("blind",500);
}

$(document).ready(function(){
	/* Setting swaping images. */
	var tmp;
	tmp = document.getElementById('main_banner');
	glob = new Object();
	glob.obj = tmp.getElementsByTagName('img');
	glob.wait = 8000;
	tmp = Math.floor(Math.random()*glob.obj.length);
	while (tmp) {
		swapImages(glob.obj,0);
		tmp--;
	}
	setTimeout("mainLoop();",glob.wait);

	/* Temporal */
	$('#menu_lam ul').eq(2).find('a:contains("Zarządzanie projektami")').css('color','red').append(' - nowa specjalność');
	$('#adsdialog').dialog({
		'modal':true,
		'show':'blind',
		'hide':'blind',
		'zIndex':4000,
		'width':630
	});
	
	/* End of Michas` code. */

//$.getScript("./template/grb/jquery.backgroundPosition.js");
$(".video_center_mat div a").css( {backgroundPosition: "0 -300px"} )
	.mouseover(function(){$(this).stop().animate({backgroundPosition:"(0 -150px)"},{duration:100})})
	.mouseout(function(){$(this).stop().animate({backgroundPosition:"(0 -300px)"},{duration:800})})
$("#video_right .video_right_mat a").css( {backgroundPosition: "0 -300px"} )
	.mouseover(function(){$(this).stop().animate({backgroundPosition:"(0 -100px)"},{duration:100})})
	.mouseout(function(){$(this).stop().animate({backgroundPosition:"(0 -300px)"},{duration:800})})
$("#wizytowka").click(function () {$("#zapcontent:visible").toggle("blind",500);$("#wizcontent").toggle("blind",500);return false;});
$("#zzapcontent").click(function () {$("#zapcontent:visible").toggle("blind",500);return false;});
$("#zwizcontent").click(function () {$("#wizcontent:visible").toggle("blind",500);return false;});
$("#zapytanie").click(function () {$("#wizcontent:visible").toggle("blind",500);$("#zapcontent").toggle("blind",500);return false;});
$("#pmapa").click(function () {openDialog($("#mapa").html());return false;});
$("#partinfoa").click(function () {openDialog($("#partinfo").html());return false;});
$(".showmapa").click(function () {var tresc=$(this).parent().find(".mapa").html();openDialog(tresc);return false;});
$(".showcennik").click(function () {var tresc=$(this).parent().find(".cennik").html();openDialog(tresc);return false;});
    // validate signup form on keyup and submit
var validator = $("#zapform").validate({rules: {imie:"required",nazwisko:"required",zgoda1:"required",zgoda2:"required",telefon:{required: true,minlength:6},
email: {required: true,email: true}},messages: {imie: {required: " Pole Imie jest wymagane"},nazwisko: {required: " Pole Nazwisko jest wymagane"},
zgoda1: {required: " Zaznaczenie tego pola jest wymagane. "},zgoda2: {required: " Zaznaczenie tego pola jest wymagane. "},
telefon: {required: " Pole Telefon jest wymagane",minlength: " Wymagane min {0} znakow"},email: {required:" Pole Email jest wymagane",
email: " Prosze podac prawidlwy adres email"}},
// set this class to error-labels to indicate valid fields
success: function(label) {
// set as text for IE
label.html(" ").addClass("checked");},
submitHandler: function() {$('#zapform').find('#submitbutton').attr('disabled', 'disabled');$('#zapform').find('#submitbutton').attr('value', 'Wysylanie');
$.post("pg.php/zapform/",$('#zapform').serialize(), function(data){$('#zapform').hide("blind",1000);setTimeout(function(){addajax(data);}, 1000);
$('#zapform').find('#submitbutton').attr('disabled', '');});return false;}});});
