// jquery

var current_scroller_image = 1;
var scroller_images = 0;

$(document).ready(function(){

	$('a[rel*=lightbox]').lightBox();

	$("#h5-1").text(current_scroller_image+" z "+scroller_images);
	$("#go-next").click(function(){
		if (current_scroller_image < scroller_images)
		{
			current_scroller_image = current_scroller_image+1;
			$("#h5-"+current_scroller_image).text(current_scroller_image+" z "+scroller_images);
			$(".news-scroller").animate({"left": "-=367px"}, "fast");
			$(".news-scroller").animate({"left": "+=20px"}, "fast");
		}
    });
	$("#go-prev").click(function(){
		if (current_scroller_image > 1)
		{
			current_scroller_image = current_scroller_image-1;
			$("#h5-"+current_scroller_image).text(current_scroller_image+" z "+scroller_images);
			$(".news-scroller").animate({"left": "+=367px"}, "fast");
			$(".news-scroller").animate({"left": "-=20px"}, "fast");
		}
    });
	
	// ask for form
		var options = { 
			target:        '',   // target element(s) to be updated with server response 
			beforeSubmit:  showRequest,  // pre-submit callback 
			success:       showResponse  // post-submit callback 
		}; 
		$('#askforform').ajaxForm(options);
	
});

function showRequest() {
	return true;
}

function showResponse(responseText, statusText) {
	var obj = jQuery.parseJSON(responseText);
	if (obj.error == 1) {
		$('#askformessage').html('<span id="askformessagecontent" style="padding:5px; font-weight:bold; background-color:rgb(240,20,20); color:rgb(255,255,255)">'+obj.message+'</span>');
		setTimeout(function() {
			$('#askformessagecontent').fadeOut('slow');
		}, 2000);
	} else {
		$('#askformessage').html('<span id="askformessagecontent" style="padding:5px; font-weight:bold; background-color:rgb(0,150,0); color:rgb(255,255,255)">'+obj.message+'</span>');
		setTimeout(function() {
			$('#askformessagecontent').fadeOut('slow');
		}, 2000);
		setTimeout("hideaskfor()", 4000);
	}
}

function showaskfor()
{
	$('#askfor_bg').show();
	$('#askfor_bg').css("opacity","0.5");
    $('#askfor_bg').css("position","absolute");
    $('#askfor_bg').css("width", $(window).width() + "px");
    $('#askfor_bg').css("height", $(document).height() + "px");
	$('#askfor').show();
	$('#askfor').center();
}

function hideaskfor()
{
	$('#askfor_bg').hide();
	$('#askfor').hide();
}

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

// scripts

function addnewsletter()
{
	$("#newsletterfrom input[name=action]").val("insert");
	$("#newsletterfrom").submit();
}

function delnewsletter()
{
	$("#newsletterfrom input[name=action]").val("delete");
	$("#newsletterfrom").submit();
}

function validateform(formname, checkemail) {
	for(var i=0; i<fields.length; i++) {
		if (document.forms[formname].elements[fields[i]].value == '') {
			alert(fields_info[i]);
			document.forms[formname].elements[fields[i]].focus();
			return false;
		}
	}
	if (checkemail == 1)
	{
		if (validateemail(formname, document.forms[formname].elements['email'].value)) {
			return true;
		} else {
			return false;
		}
	}
}

function validateemail(formname, t) {
	maska = /^[0-9a-z_.-]+@([0-9a-z-]+.)+[a-z]{2,4}$/;
	if (maska.test(t)==false) { 
		alert("Podaj prawidłowy adres e-mail.");
		document.forms[formname].elements['email'].focus();
		return false;
	}
	return true;
}

function validateform1() {
 for(var i=0; i<fields.length; i++) {
  if (document.fo.elements[fields[i]].value == '' || document.fo.elements[fields[i]].value == 0) {
   alert(fields_info[i]);
   document.fo.elements[fields[i]].focus();
   return false;
  }
 }
 if (validateemail1(document.fo.elements['Email'].value)) {
  return true;
 } else {
  return false;
 } 
}

function validateemail1(t) {
  maska = /^[0-9a-z_.-]+@([0-9a-z-]+.)+[a-z]{2,4}$/;
  if (maska.test(t)==false) { 
    alert("Podaj poprawny adres e-mail");
    document.fo.elements['Email'].focus();
    return false;
  }
  return true;
}

function calculate_total()
{
	result = document.forms['rezerwacja'].elements['base'].value;
	result = result*1;
	if (document.forms['rezerwacja'].elements['posciel'].value == 'tak')
		result += (document.forms['rezerwacja'].elements['bedding-price'].value*document.forms['rezerwacja'].elements['osob'].value);
	if (document.forms['rezerwacja'].elements['internet'].value == 'tak')
		result += (document.forms['rezerwacja'].elements['internet-price'].value*document.forms['rezerwacja'].elements['dni'].value);
	if (document.forms['rezerwacja'].elements['krzeselko'].value == 'tak')
		result += document.forms['rezerwacja'].elements['chair-price'].value*1;
	result = Math.round(result*100);
	result = result/100;
	result = result.toFixed(2);
	document.forms['rezerwacja'].elements['total'].value = result;
}

// promy - daty

function kolnexodays_change(month, type)
{
	$("#"+type+"-kolnexodays").load('load.php?action=promy_kol_nexo&type='+type+'&month='+month);
}

function swinronnedays_change(month, type)
{
	$("#"+type+"-swinronnedays").load('load.php?action=promy_swin_ronne&type='+type+'&month='+month);
}

function sassronnedays_change(month, type)
{
	$("#"+type+"-sassronnedays").load('load.php?action=promy_sass_ronne&type='+type+'&month='+month);
}

// scroll images

if(!document.getElementById)
{
	if(document.all)
	{
		accessObj = function()
		{
			if(typeof document.all[arguments[0]]!="undefined")
			return document.all[arguments[0]]
			else
			return null
		}
	}
	else if(document.layers)
	{
		accessObj = function()
		{
			if(typeof document[arguments[0]]!="undefined")
			return document[arguments[0]]
			else
			return null
		}
	}
}
else
{
	accessObj = function()
	{
		return document.getElementById(arguments[0]);
	}
}

function setOpacity(objname, o)
{
	var obj = accessObj(objname);
	var per = o / 100;
	
    obj.style.opacity = (per);
    obj.style.MozOpacity = (per);
    obj.style.KhtmlOpacity = (per);
    obj.style.filter = 'alpha(opacity=' + o + ')';
}

// js

b0off = new Image();
b0off.src = "gfx/b-noc.gif";
b0on = new Image();
b0on.src = "gfx/b-noc1.gif";

b1off = new Image();
b1off.src = "gfx/b-prom.gif";
b1on = new Image();
b1on.src = "gfx/b-prom1.gif";

b2off = new Image();
b2off.src = "gfx/b-ob.gif";
b2on = new Image();
b2on.src = "gfx/b-ob1.gif";

b3off = new Image();
b3off.src = "gfx/b-gal.gif";
b3on = new Image();
b3on.src = "gfx/b-gal1.gif";

b4off = new Image();
b4off.src = "gfx/b-onas.gif";
b4on = new Image();
b4on.src = "gfx/b-onas1.gif";

b5off = new Image();
b5off.src = "gfx/b-kon.gif";
b5on = new Image();
b5on.src = "gfx/b-kon1.gif";

b6off = new Image();
b6off.src = "gfx/l-b2.gif";
b6on = new Image();
b6on.src = "gfx/l-b2a.gif";

b7off = new Image();
b7off.src = "gfx/l-b3.gif";
b7on = new Image();
b7on.src = "gfx/l-b3a.gif";

b8off = new Image();
b8off.src = "gfx/l-b4.gif";
b8on = new Image();
b8on.src = "gfx/l-b4a.gif";

b9off = new Image();
b9off.src = "gfx/l-b5.gif";
b9on = new Image();
b9on.src = "gfx/l-b5a.gif";

function myfun() {
	if (xmenu == 0) {
		document.gfx['b1'].src=b1off.src;
	}
}

function myfun2() {
	if (ymenu == 0) {
		document.gfx['b2'].src=b2off.src;
	}
}



function se(a,b) {
	window.location.href = 'mailto:'+a+'@'+b+'.pl';
}

function gotourl(a,b) {
	newwindow = window.open();
	newwindow.location.href = 'http://'+a+'.'+b+'.com';
} 

function flip(rid) {
	current=(document.getElementById(rid).style.display == 'none') ? 'block' : 'none';
	document.getElementById(rid).style.display = current;
}

function set(rid,mode) {
 if (document.getElementById(rid)) {
      current=(mode == 1) ? 'block' : 'none';
      document.getElementById(rid).style.display = current;
 }
}

function opensmallwindow(w,h) {
 smallwindow = window.open("", "smallwindow", "width="+w+", height="+h+", toolbar=no, scrollbars=yes");
 x = (screen.Width/2)-(w/2);
 y = (screen.Height/2)-(h/2);
 smallwindow.moveTo(x,y);
 smallwindow.focus();
}