jQuery.noConflict();


var aktualnyZooverAjax = '0';
var zooverPhotoTab = [];
var zooverPhotoCount = 0;
var zooverActualMaxSite = 0;
var zooverActualMaxSiteColorBox = 0;
var zooverSeekInc = 0;
var galleryZooverColorbox = null;
var zooverPhotoTabColorBox = [];
urlForSearcher = "";
maxNumbers = 0;
galleryPositionIndex = 0;
galleryNextImg = true;
firstClick = true;
firstUpdate = true;
urlToDesc = "";
galleryStarted = false;
reloadGallery = false;
reloadGalleryUrl = "";

function loadMain(){
	loadSkiBookBanner();
}

function readyMain(){
	/* var aurlForSearcher = jQuery("#url-for-searcher").text();
	aurlForSearcher = aurlForSearcher.replace("hotele","2hotele");
	jQuery("#url-for-searcher").text(aurlForSearcher); */
	jQuery("#oferta-box-dialog-text:empty").parent().parent().hide();
	if(jQuery("#oferta-box-dialog-text").text() != ""){
		jQuery("#oferta-box-dialog-wrapper").hide();
		infoDialog(jQuery("#oferta-box-dialog-text").html(), "info");
	}
	if (jQuery.getUrlVar("tourOp")!='' && typeof jQuery.getUrlVar("tourOp") != 'undefined'){
		jQuery("select[name='touroperator'] option[value="+jQuery.getUrlVar("tourOp")+"]").attr("selected","selected");
	}
	urlToDesc = jQuery("#merlinOpis").text();
	jQuery("#domyslne_dorosli").text();
	initParametryzacja();
	initTabsBox();
	secure_reservation();
	showGwarancjaJakosci();
	jQuery("#komunikat").insertAfter("#kontener");
	jQuery("#komunikat_box").insertAfter("#kontener");
	jQuery("#komunikatp").insertAfter("#kontener");
	jQuery("#komunikatp_box").insertAfter("#kontener");
	if(jQuery("#hotel-tourop").css("display") == "block")
		initImages("#hotel-photo a");
	if(jQuery("#hotel").css("display") == "block")
		initImages("#country-photo > a");
	if (jQuery("#gmap").css("display") == "block") {
		showMap('mapaOkolicy');
		loadScript();
	}
	initGaleriaBox();
	initMeteo(); // Kod zabezpieczony od wewnątrz
	initZoover(); // Kod zabezpieczony od wewnątrz
	initFiczers();
	loadPartnerBanner();
}

function warunki(toid){
	if (toid != null && (toid == 'TOOP00081M' || toid == 'TOOP00150M'))
        	okno = window.open("/warunki/" + toid + ".htm","_blank","location=1,scrollbars=1,menubar=1,toolbar=0,status=0,resizable=1,directories=0");
	else if (toid != null && toid.indexOf("M") != -1)
        	okno = window.open("/warunki/" + toid + ".pdf","_blank","location=1,scrollbars=1,menubar=1,toolbar=0,status=0,resizable=1,directories=0");
	else
        	okno = window.open("/warunki/" + toid + ".htm","_blank","location=1,scrollbars=1,menubar=1,toolbar=0,status=0,resizable=1,directories=0");
}




function checkAvail(adres){
	showKomunikat('Trwa potwierdzanie dostępności oferty, proszę czekać...');
	turnusAvail = jQuery(".ui-accordion-content-active .check_turnus").text();
	if(turnusAvail != ""){
		jQuery.ajax({
			url: turnusAvail,
			dataType: 'xml',
			success: function(xml) {
				statusDialog = jQuery(xml).find("DialogStatus").text();
				if(statusDialog=="ok"){
					var tabCountries = ["egipt","maroko", "tunezja", "turcja"];
					if (jQuery.inArray(varArray["panstwoID"], tabCountries) != -1){
						replaceKomunikat(adres);
					} else {
						window.location.href = adres;
						hideKomunikat();
					}
				} else {
					hideKomunikat();
					jQuery(".ui-accordion-content-active .param_rozw_main").replaceWith(jQuery("#brak_dostepnosci").clone());
					jQuery(".ui-accordion-content-active .brak_dostepnosci").show();
				}
			},
			error: function(){
				hideKomunikat();
				jQuery(".ui-accordion-content-active .param_rozw_main").replaceWith(jQuery("#brak_dostepnosci").clone());
				jQuery(".ui-accordion-content-active .brak_dostepnosci").show();
			}
		});	
	}else if(jQuery("#oferta-box-dialog-text").text() == ''){
		//window.location.href=jQuery("#dodatkowyUrlDlaRezerwacji").attr("href");
		hideKomunikat();
		jQuery(".ui-accordion-content-active .param_rozw_main").replaceWith(jQuery("#brak_dostepnosci").clone());
		jQuery(".ui-accordion-content-active .brak_dostepnosci").show();
	}
}

function turnOnReserveButton(){
	jQuery(".ui-accordion-content-active .rezerwuj_button_box_none").fadeOut(1000,function(){
		jQuery(".ui-accordion-content-active .rezerwuj_button_box").fadeIn(2000);
	});
}


function reloadPhotoAndDesc(){
	var tour = jQuery("#hotel-param-offers .ui-state-active .tourOp").text();
	var catalog = tour == 'NPL' || tour == 'HIT' ? jQuery("#hotel-param-offers .ui-state-active .htlCat").text() : "";
	var directCatalog = jQuery("#hotel-param-offers .ui-state-active .htlCat").text();
	var seas =  tour == 'NPL' || tour == 'HIT' || tour == 'WYGO'  ? jQuery("#hotel-param-offers .ui-state-active .season").text() : "";
	var htlcode = jQuery("#hotel-param-offers .ui-state-active .htlCode").text();
	var updated = jQuery("#hotel-param-offers .ui-state-active .updated").text();
	var fromdata = jQuery("#hotel-param-offers .ui-state-active .fromdata").text();
	if (jQuery.getUrlVar("fromDate")!='' && typeof jQuery.getUrlVar("fromDate") != 'undefined'){
		fromdata = jQuery.getUrlVar("fromDate");
	} else
		fromdata="";
	var directPostFix = jQuery("#hotel-param-offers .ui-state-active .directPostFix").text();
	var urlToData = "/hotele/getdescription.xml?season=" + seas + "&htlcat=" + catalog + "&tourOp=" + tour + "&htlCode=" + htlcode + "&fromDate=" + fromdata;
	//var urlToData = "/hotele/getdescription.xml?season=" + seas + "&htlcat=" + catalog + "&tourOp=" + tour + "&htlCode=" + htlcode; 
	if (urlToData != urlToDesc && tour != 'FTON'){
		showKomunikat('Trwa ładowanie oferty, proszę czekać...');
		jQuery.ajax({
			url: urlToData,
			dataType: 'xml',
			success: function(data) {
				if (jQuery(data).find("status").text() == 'ok') {
					jQuery("#galeria_scroll .items").css("visibility","hidden");
					jQuery("#galeria_nr_zdjecia").css("visibility","hidden");
					if (urlToDesc == 'none'){
						jQuery('#ourOpis').text("");
						jQuery("#ourOpis").append(jQuery("#param_lead_main_box").clone().attr('id','none'));
						jQuery(".opinia_travelone_mainbox_bottom").css("background-position","-180px -347px");
					}
					opis = "<span class='header_opinia_param header_opinia_param_lead'> </span>";
					jQuery(data).find("texts").children("text").each(function(index,val){
						opis = opis + "<div class='lead_akapit_box'><span class='lead_akapit_box_title'>" + jQuery(this).children("subject").text() + "</span>" + jQuery(this).children("content").text() + "</div>";
						});
					jQuery('#param_lead_main_box').text("");
					jQuery('#param_lead_main_box').append(opis);
					
					i = 0;
					api = jQuery("#galeria_scroll.scrollable").data("scrollable");
					api.getItems().remove();
					photoContainer = [];
					jQuery("#target_tmp").html("");
					galleryPositionIndex = 0;
					jQuery("#test a").remove();
					jQuery(data).find("pictures").children("picture").each(function(index,val){
						photoContainer[i] =  jQuery(this).text();
						if (i == 0) {
							jQuery("#test").append("<a  style='z-index:98; position:relative; display: block; height: 210px; width: 260px;' rel='topGallery' href='" + jQuery(this).text() +"'><img src='http://www.egipt.info.pl//imgs/obiekt/loader_max.gif' width='260' height='210' style='opacity: 0;filter: alpha(opacity=0);'></a>");
							jQuery("#target").html("<div><img width='300' height='210' src='" + jQuery(this).text() +"'/></div>");
							api.addItem(jQuery("#target div").clone()).end();
						} else {
							jQuery("#test").append("<a  style='z-index:98;display: none; height: 210px; width: 260px;' rel='topGallery' href='" + jQuery(this).text() +"'><img src='http://www.egipt.info.pl//imgs/obiekt/loader_max.gif' width='260' height='210' style='opacity: 0;filter: alpha(opacity=0);'></a>");
						}
						i++;
					});
					if (photoContainer.length == 0){
						jQuery("#obiekt-box .galeria_description").css("visibility","hidden");
						jQuery("#obiekt-box .galeria_description span").css("display","none");
						jQuery("#obiekt-box .ster_right div").attr("id","galeria_ster_right_p");
					} else {
						jQuery("#obiekt-box .galeria_description").css("visibility","visible");
						jQuery("#obiekt-box .galeria_description span").css("display","block");
						jQuery("#obiekt-box .ster_right div").attr("id","galeria_ster_right_a");
					}
					jQuery("#test a[rel='topGallery']").colorbox({maxWidth:"1280px", maxHeight:"800px", photo:"true", current:"Zdjęcie {current} z {total}"});
					jQuery("#target").text("");
					jQuery('.galeria_description_number').text("");
					jQuery('.galeria_description_number').append("<span class='galeria_description_number'>zdjęcie <span id='galeria_nr_zdjecia'>1</span>/" + i + "</span>");
					jQuery("#galeria_scroll .items").css("visibility","visible");
					jQuery("#galeria_nr_zdjecia").css("visibility","visible");
					jQuery("#galeria_nr_zdjecia").html("1");
					var additional = jQuery("#hotel-param-offers .ui-state-active .tourOp").text() != "" ? "&tourOp="+jQuery("#hotel-param-offers .ui-state-active .tourOp").text() : "";
					additional = jQuery("#hotel-param-offers .ui-state-active .htlCode").text() != "" ? additional + "&htlCode="+jQuery("#hotel-param-offers .ui-state-active .htlCode").text() : "";
					//jQuery("#show_slide").attr("href", window.location.pathname+"?slide=1"+additional);
				}
				urlToDesc = urlToData;
			}
		});
		var urlToData2 = "/hotele/getgallerypictures.xml?season=" + seas + "&htlcat=" + catalog + "&tourOp=" + tour + "&htlCode=" + htlcode;
		reloadGalleryUrl = urlToData2;
		if(jQuery("#gallery").css("display") != "none"){
			reloadGalleryTourOp();
		} else {
			reloadGallery = true;
		}
		hideKomunikat();
	} else if (tour == 'FTON' && updated == 'false') {
		var directDesc = "/hotele/getdirectdescription.xml?direct="+htlcode+"-"+directCatalog+directPostFix;
		jQuery.ajax({
			url: directDesc,
			dataType: 'html',
			success: function(data) {
				jQuery("#hotel-param-offers .ui-state-active .updated").text('true');
				jQuery("#hotel-param-offers .ui-accordion-content-active .param_rozw_main").replaceWith(data);
				jQuery("#hotel-param-offers .ui-accordion-content-active").height('auto');
				jQuery("#hotel-param-offers .ui-accordion-content-active .pobierz_formularz_button a").attr('href','/static/tabelki/'+htlcode+"-"+directCatalog+directPostFix+".doc");
				jQuery(".big_blue_prize_direct").text(jQuery('#hotel-param-offers .ui-accordion-content-active .cena_turnus_zb').text());
				if (jQuery(".big_blue_prize_direct").hasClass("price-loading")){
					jQuery(".big_blue_prize_direct").removeClass("price-loading");
				}
				jQuery("#nasz_direct").text(jQuery('#hotel-param-offers .ui-accordion-content-active .nasz_direct_temp').text());
			}
		})
		hideKomunikat();
	} else if (tour == 'FTON' && updated == 'true') {
		jQuery("#hotel-param-offers .ui-accordion-content-active .pobierz_formularz_button a").attr('href','/static/tabelki/'+htlcode+"-"+directCatalog+directPostFix+".doc");
		jQuery(".big_blue_prize_direct").text(jQuery('#hotel-param-offers .ui-accordion-content-active .cena_turnus_zb').text());
		if (jQuery(".big_blue_prize_direct").hasClass("price-loading")){
			jQuery(".big_blue_prize_direct").removeClass("price-loading");
		}
		jQuery("#nasz_direct").text(jQuery('#hotel-param-offers .ui-accordion-content-active .nasz_direct_temp').text());
	}
}

function reloadGalleryTourOp(){
	jQuery.ajax({
		url: reloadGalleryUrl,
		dataType: 'html',
		success: function(data) {
			if (jQuery(data).find("gallerydata").attr("status") == 'ok') {
				
				
				jQuery("#galeriaPagesTourOp .navi a").each(function(index,val){
					jQuery(this).detach();
				});
				
				var api2 = jQuery("#galleryTourOpScrollable").data("scrollable");
				
				jQuery("#galleryTourOpScrollable").unbind("onBeforeSeek",tourOpGalleryHandler);
				
				var j = 0;
				api2.getItems().remove();
				api2.getConf().speed = 1;
				jQuery(data).find("gallerydata").children("div").each(function(index,val){
					j++;
					api2.addItem(jQuery(this).clone()).end();
				});
				if (j == 0) {
					jQuery("#target").html("<div class='galeria_miniatury_box gallery_boxTourOp galleryTourOpBrak'><span>Brak zdjęć organizatora</span></div>");
					api2.addItem(jQuery("#target div").clone()).end();
					jQuery("#target").text("");
				}
				api2.begin(1);
				api2.getConf().speed = 400;
				
				if(jQuery(data).find("gallerydata").attr("count") > 4) {
					jQuery("#galleryMoreLessTourOpLink").show();
					if(jQuery("#galleryMoreLessTourOp").attr("src") == "/imgs/przewodnik/arrow_down.jpg") {
						galleryMoreLessTourOp();
					}
				} else {
					jQuery("#galleryMoreLessTourOpLink").hide();
					if(jQuery("#galleryMoreLessTourOp").attr("src") == "/imgs/przewodnik/arrow_up.jpg") {
						galleryMoreLessTourOp();
					}
				}
				if(jQuery(data).find("gallerydata").attr("pages") > 1) {
					jQuery("#galeria_ster_leftTourOp").show();
					jQuery("#galeria_ster_rightTourOp").show();
					jQuery("#galeriaPagesTourOp").show();
				} else {
					jQuery("#galeria_ster_leftTourOp").hide();
					jQuery("#galeria_ster_rightTourOp").hide();
					jQuery("#galeriaPagesTourOp").hide();
				}
				
				jQuery("#galeriaPagesTourOp .navi a").each(function(index,val){
						var href = jQuery(this).attr("href");
						jQuery(this).text(parseInt(href.substring(1)) + 1);
						jQuery(this).addClass("galeria_pages_link");
				});
				
				jQuery("#galleryTourOpScrollable").bind("onBeforeSeek",tourOpGalleryHandler);
				jQuery("#galleryTourOpScrollable").data("scrollable").begin(0);
				
				jQuery(".gallery_boxTourOp a[rel='touropGallery']").colorbox({maxWidth:"1280px", maxHeight:"800px", photo:"true", current:"Zdjęcie {current} z {total}"});
			}
		}
	});
}


function showKomunikat(tresc){
	jQuery("#komunikat_tresc #tresc_kom").text(tresc);
	jQuery("#komunikat").css("height",jQuery(document).height());
	jQuery("#komunikat").css("width",jQuery("body").width());
	jQuery("#komunikat").show();	
	jQuery("#komunikat_box").css("left",jQuery(window).width()/2 - 185);
	jQuery("#komunikat_box").show();	
}

function hideKomunikat(){
	jQuery("#komunikat").fadeOut();	
	jQuery("#komunikat_box").fadeOut();	
}

function replaceKomunikat(adres){
	jQuery(".paszp_bottom_center").click(function() {
		window.location.href = adres;
	});
	jQuery("#komunikat").hide();	
	jQuery("#komunikat_box").hide();	
		jQuery("#komunikatp").css("height",jQuery(document).height());
		jQuery("#komunikatp").css("width",jQuery("body").width());
		jQuery("#komunikatp").show();
		jQuery("#komunikatp_box").css("left",jQuery(window).width()/2 - 185);
		jQuery("#komunikatp_box").show();
}

function hideKomunikatP(){
	jQuery("#komunikatp").fadeOut();	
	jQuery("#komunikatp_box").fadeOut();	
}

function changeOfertyURL(){
	bezposredniUrlDoOferty = window.location.protocol + '//' + window.location.hostname + window.location.pathname + jQuery(".ui-state-active .bezposredniUrl").text();
	if (jQuery.getUrlVar("code")!='' && typeof jQuery.getUrlVar("code") != 'undefined'){
		bezposredniUrlDoOferty = bezposredniUrlDoOferty + '&code='+jQuery.getUrlVar("code");
	} 
	if (jQuery("#search-check-chld").attr("checked")){
		kids_age = '';
		kids_count = 0;
		kids_comma = '';
		if (jQuery("#c1 option:selected").val()	!= ''){
			kids_count++;
			kids_age = jQuery("#c1 option:selected").val();
			kids_comma = ',';
		}
		if (jQuery("#c2 option:selected").val()	!= ''){
			kids_count++;
			kids_age = kids_age + kids_comma + jQuery("#c2 option:selected").val();
			kids_comma = ',';
		}
		if (jQuery("#c3 option:selected").val()	!= ''){
			kids_count++;
			kids_age = kids_age + kids_comma + jQuery("#c3 option:selected").val();
		}
		if (kids_count > 0)
			bezposredniUrlDoOferty = bezposredniUrlDoOferty + '&chd=' + kids_count + '&chage=' + kids_age;
			
	}
	bezposredniUrlDoOferty = bezposredniUrlDoOferty + '&adt=' + jQuery("select[name='dorosli'] option:selected").val();         
	var fromdata2 = jQuery("#hotel-param-offers .ui-state-active .fromdata").text();
	if (fromdata2 != null && fromdata2 != 'undefined' && fromdata2 != '')
		bezposredniUrlDoOferty = bezposredniUrlDoOferty + '&fromDate=' + fromdata2;
	jQuery("#anotherLinkDoOferty").attr("href2",bezposredniUrlDoOferty);
	jQuery("#popuplink_text").val(bezposredniUrlDoOferty);

	var fromu=bezposredniUrlDoOferty;
        var indfrom = fromu.indexOf('?');
        if (indfrom > 0) {
                var querystr = fromu.substring(indfrom);
                var printurl='http://' + document.domain + '/hotele/printpage.xml' + querystr + '&from=' + encodeURIComponent(fromu);
                jQuery("#anotherLinkDoOferty_print").attr("href",printurl);
        } else {
                jQuery("#anotherLinkDoOferty_print").hide();
		jQuery(".drukuj_opis_ico").hide();
        }
	
}

function changeSrc(ind){
	var api = jQuery("#galeria_scroll.scrollable").data("scrollable");
	var ind2 = ind - 1;
	var img = jQuery("#galeria_scroll .items div:eq("+ind+") img");
	jQuery(img).attr("src",jQuery("#target_tmp img:eq("+ind2+")").attr("src"));
	jQuery(img).attr("width",300);
	jQuery(img).attr("height",210);
	jQuery(img).attr("style","");
	galleryNextImg = true;
	if (ind != photoContainer.length - 1) jQuery(".galeria_sterowanie .ster_right div").attr("id","galeria_ster_right_a");
}

function openGalleryTab(){
	openTab('gallery');
}


function openTab(which){
	jQuery("#tabs-box").tabs('select', which);
	var targetOffset = jQuery("#tabs-box").offset().top;
	jQuery("html, body").animate({scrollTop: targetOffset}, 400);	
}

function changedTourop(){
	 var loc = window.location;
	 var pathName = loc.pathname.substring(0, loc.pathname.indexOf('xml') + 3);
	 var url = loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));
	 var additional =  jQuery("#tourop option:selected").val() != "" ? "?tourOp="+jQuery("#tourop option:selected").val() : "";
	if (jQuery.getUrlVar("code")!='' && typeof jQuery.getUrlVar("code") != 'undefined'){
		additional = additional == '' ? '?code='+jQuery.getUrlVar("code") : additional+'&code='+jQuery.getUrlVar("code");
	} else if (jQuery.getUrlVar("xCode")!='' && jQuery.getUrlVar("xCode")!='NaN' && typeof jQuery.getUrlVar("xCode") != 'undefined'){
		additional = additional == '' ? '?xCode='+jQuery.getUrlVar("xCode") : additional+'&xCode='+jQuery.getUrlVar("xCode");
	}
	 window.location.href=url+additional;
}

function changedKids() {
	if (jQuery("#search-check-chld:checked").val() == 1) {
		jQuery("#wyszukiwarka_box_kids_drops").show();
		jQuery("#wyszukiwarka_box_kids .pozdroz_z_dziecmi").hide();
		jQuery("#wyszukiwarka_box_kids .wiek_dzieci").show();
	}
	else {
		jQuery("#wyszukiwarka_box_kids_drops").hide();
		jQuery("#wyszukiwarka_box_kids .pozdroz_z_dziecmi").show();
		jQuery("#wyszukiwarka_box_kids .wiek_dzieci").hide();
	}
	if (jQuery("#c1 option:selected").val() != '' || jQuery("#c2 option:selected").val() != '' || jQuery("#c3 option:selected").val() != '')
		updateOffers(-5);
}

function getChildren(){
	inf=0;
	chd=0;
	if (jQuery("#search-check-chld:checked").val() == 1 ){
		child1 = jQuery("#c1 option:selected").val() != "" ?jQuery("#c1 option:selected").val() : "";
		child2 = jQuery("#c2 option:selected").val() != "" ?jQuery("#c2 option:selected").val() : "";
		child3 = jQuery("#c3 option:selected").val() != "" ?jQuery("#c3 option:selected").val() : "";
		child1 = typeof child1 == "undefined" ? "" : child1;
		if (child1 == "2-") {
		    child1="";
		    inf++;
		} else if( child1 != ""){
			chd++;
		}
		if (child2 != "" && typeof child2 !="undefined"){
		    if (child2=="2-") {
			    inf++;
		    } else {
			    child1 = child1 !="" ? child1+","+child2 : child2;
			    chd++;
		    }
		}
		if (child3 != "" && typeof child3 !="undefined") {
		    if (child3=="2-"){
			    inf++;
		    } else {
			    child1 = child1 !="" ? child1+","+child3 : child3;
			    chd++;
		    }
		}
		if(jQuery("#typ_obiektu").text() != 'AP' ) {
			chage = child1!= "" ? "&chage="+child1: "";
			inf = inf==0 ? "" : "&inf="+ inf;
			chd = chd==0 ? "" : "&chd="+ chd;
		} else {
			chage="";
			inf="";
			chd= "";
		}
	} else {
		chage="";
		inf="";
		chd="";
	}
	url = chage+inf+chd;
	return url;	
}
function changedBoard(which) {
	jQuery("#wyzywienie_domyslne").text(which);
	/*if (jQuery("#param_wyzywienie").val() == which) {
		jQuery("#param_wyzywienie").attr('selectedIndex',0);	
		jQuery("#wyzywienie_domyslne").text("none");
	} else if (jQuery("#param_wyzywienie option[value='" + which + "']").length > 0) { 
		jQuery("#wyzywienie_domyslne").text(which);
	}*/
	updateOffers('-4');
}
function changedDeparture(which) {
	var name = "";
	name = which == 'F' ? 'plane' : name;
	name = which == 'BU' ? 'bus' : name;
	name = which == 'H' ? 'wlasny' : name;
	if (name!='' && jQuery("#"+which).hasClass("param_wyzywienie_active")){
		jQuery("#param_wyjazd .param_wyzywienie_active div").removeClass();
		jQuery("#param_wyjazd .param_wyzywienie_active div").addClass("param_ico_black_" + name);
		jQuery("#param_wyjazd .param_wyzywienie_active").removeClass("param_wyzywienie_active");
		if (which == 'H'){
			jQuery('.bez_wlasnego_dojazdu').show();
			jQuery('.parametryzacja_terminy').css('width','262px');
			jQuery('.terminy_param').css('width','262px');
		} 
	} else {
		var klasa = jQuery("#param_wyjazd .param_wyzywienie_active div").attr("class");
		klasa = klasa != '' && klasa != undefined ? klasa.replace("white","black") : "" ;
		jQuery("#param_wyjazd .param_wyzywienie_active div").removeClass();
		if (klasa != '')
			jQuery("#param_wyjazd .param_wyzywienie_active div").addClass(klasa);
		jQuery("#param_wyjazd .param_wyzywienie_active").removeClass("param_wyzywienie_active");
		if (which!='')
			jQuery("#"+which).addClass("param_wyzywienie_active");
		jQuery("#param_wyjazd .param_wyzywienie_active div").removeClass();
		jQuery("#param_wyjazd .param_wyzywienie_active div").addClass("param_ico_white_" + name);
		jQuery(".opis_wyjazd_type").css("display","none");
		if (which!='') 
			jQuery('#opis_wyjazd_'+which).css("display","inline");
		if (which == 'H'){
			jQuery('.bez_wlasnego_dojazdu').hide();
			jQuery('.parametryzacja_terminy').css('width','466px');
			jQuery('.terminy_param').css('width','466px');
		} else {                                       
			jQuery('.bez_wlasnego_dojazdu').show();
			jQuery('.parametryzacja_terminy').css('width','262px');
			jQuery('.terminy_param').css('width','262px');
		}
	}
	initParametryzacja();
}

function setAkDojazd() {
	var akdoj = jQuery(".ui-state-active .akdojazd").text();
	if (akdoj == 'samolot') { 
		jQuery("#opis_wyjazd_F").css("display","inline");
		jQuery("#opis_wyjazd_BU").css("display","none");
		jQuery("#opis_wyjazd_H").css("display","none");
	} else if (akdoj == 'autokar') {
		jQuery("#opis_wyjazd_BU").css("display","inline");
		jQuery("#opis_wyjazd_F").css("display","none");
		jQuery("#opis_wyjazd_H").css("display","none");
	} else if (akdoj == 'wlasny') {
		jQuery("#opis_wyjazd_H").css("display","inline");
		jQuery("#opis_wyjazd_F").css("display","none");
		jQuery("#opis_wyjazd_BU").css("display","none");
	}
}

function startParamAccordeon(){
	if (jQuery("#nastepneOferty") && jQuery("#nastepneOferty").length == 0 && jQuery("#poprzednieOferty") && jQuery("#poprzednieOferty").length == 0 )
		jQuery("#paginator").remove();
	if (jQuery(".wyjzad_z_param option:selected").val() != '')
		jQuery(".miasto_konkretne").text("");
	jQuery("#hotel-param-offers").accordion({
			change: function(event,ui) {
				jQuery(".formatka").hide();
				jQuery(".big_blue_prize").text(jQuery(".ui-accordion-content-active .total_prize_value").text());
				jQuery("#akt_htlCode").text(jQuery(".ui-state-active .htlCode").text());
				jQuery("#akt_tourOp").text(jQuery(".ui-state-active .tourOp").text());
				jQuery("#obiekt_name_MDS").text(jQuery(".ui-state-active .hotelName").text());
				setAkDojazd();
				jQuery("#biura-podrozy").attr("href","http://www.travelone.pl/biura-podrozy/tourOp.xml?kod="+jQuery(".ui-state-active .tourOpId").text());
				jQuery("#biura-podrozy-warunki").attr("href","javascript:warunki('" + jQuery(".ui-state-active .tourOpId").text() + "M')");
				//if(jQuery(".ui-state-active .tourOpId").text() != '') jQuery(".left_dodatkowe_info_image").attr("src","http://www.travelone.pl/photo/mini/"+jQuery(".ui-state-active .tourOpId").text()+"-0001.jpg");
				jQuery("#dodatkowyUrlDlaRezerwacji").attr("onclick","checkAvail('"+jQuery(".ui-accordion-content-active .urlDoRezerwacji").attr("href")+"');");
				jQuery(".paramtryzacja_list_separator_vert").css('display','block');
				jQuery(".ui-state-active .paramtryzacja_list_separator_vert").css('display','none');
				jQuery(".ui-accordion-content-active .zapytaj_button_box").css("visibility","visible");
				jQuery("#formatka #afterFormatkaOK").css("display","none");
				jQuery("#formatka #afterFormatkaBAD").css("display","none");
				jQuery("#hotel-param-offers .param_rozw_info_main_box").css("height","auto");
				if (jQuery("#akt_tourOp").text() == 'RDLF'){
					jQuery("#rudolf_bez_ubezpieczenia").hide();
					jQuery("#rudolf_bez_ubezpieczenia_2").show();
					jQuery("#rudolf_bez_ubezpieczenia_3").hide();
				}else{
					jQuery("#rudolf_bez_ubezpieczenia").show();
					jQuery("#rudolf_bez_ubezpieczenia_2").hide();
					jQuery("#rudolf_bez_ubezpieczenia_3").show();
				}
				changeOfertyURL();
				reloadPhotoAndDesc();	
			}
	});
	reloadPhotoAndDesc();	
	
}

function checkPrice(){
	var cena = jQuery("#hotel-param-offers .ui-accordion-content-active .popup_param .price_total").text();
	if (jQuery("#hotel-param-offers .ui-accordion-content-active .popup_param .price_total").text().indexOf("zł") == -1 && jQuery("#hotel-param-offers .ui-accordion-content-active .popup_param .price_total").text().indexOf("EUR") == -1 && jQuery("#hotel-param-offers .ui-accordion-content-active .popup_param .price_total").text().indexOf("USD") == -1 ){
		jQuery("#hotel-param-offers .param-loading").css("height",jQuery("#hotel-param-offers").height());
		jQuery("#hotel-param-offers .param-loading:hidden").fadeIn();
		
		var urlForCheck = "/hotele/checkmdsprice.xml";
		var parAdults = jQuery(".dorosli_pob_param option:selected").val();
		var adtAge = "";
		var chages = "";
		var infages = "";
		var chdcount = 0;
		var infcount = 0;
		for (i = 0; i < Number(parAdults) ; i++){
			adtAge += "19800101,";
		}	
			
		if (jQuery("#search-check-chld").is(":checked")){
			//var terminDo = jQuery("#hotel-param-offers .ui-state-active .terminDo").text();
			var terminDo = jQuery("select[name='data_wyjazdu'] option:selected").val();
			var c1 =jQuery("#c1 option:selected").val();
			var c2 =jQuery("#c2 option:selected").val();
			var c3 =jQuery("#c3 option:selected").val();
			if (c1	!= "" ){
				c1 = c1 == "2-" ? "1":c1;
				var tempDate = Number(terminDo.substring(0,4))-Number(c1);
				if (c1 == "1"){
					infcount++;
					infages = tempDate + terminDo.substring(4).replace(/-/g,"");
				}else{
					chdcount++;
					chages = tempDate + terminDo.substring(4).replace(/-/g,"");
				}
			}
			if (c2 != "" ){
				c2 = c2 == "2-" ? "1":c2;
				var tempDate = Number(terminDo.substring(0,4))-Number(c2);
				if (c2 == "1"){
					infages = infages == "" ? "" : infages + ",";
					infcount++;
					infages = infages + tempDate + terminDo.substring(4).replace(/-/g,"");
				}else{
					chages = chages == "" ? "" : chages + ",";
					chdcount++;
					chages = chages + tempDate + terminDo.substring(4).replace(/-/g,"");
				}
			}
			if (c3 != "" ){
				c3 = c3 == "2-" ? "1":c3;
				var tempDate = Number(terminDo.substring(0,4))-Number(c3);
				if (c3 == "1"){
					infages = infages =="" ? "" : infages + ",";
					infcount++;
					infages = infages + tempDate + terminDo.substring(4).replace(/-/g,"");
				}else{
					chages = chages == "" ? "" : chages + ",";
					chdcount++;
					chages = chages + tempDate + terminDo.substring(4).replace(/-/g,"");
				}
			}
			if(jQuery("#typ_obiektu").text() != 'AP' ) {
				if( chages != "")
					chages = "&chda=" + chages + "&parChd=" + chdcount;
				if( infages != "")
					infages = "&infa=" + infages + "&parInf=" + infcount;
			}
		}
		
		urlForCheck = urlForCheck + "?kodId=" + jQuery("#hotel-param-offers .ui-state-active .kodId").text();
		urlForCheck = urlForCheck + "&parAdt=" + parAdults;
		urlForCheck = urlForCheck + "&adta=" + adtAge.substring(0,adtAge.length-1);
		if(jQuery("#typ_obiektu").text() != 'AP' )
			urlForCheck = urlForCheck + chages + infages;
		jQuery.ajax({
			url: urlForCheck,
			dataType: 'html',
			success: function(data) {
				jQuery("#hotel-param-offers .param-loading").fadeOut();
				jQuery("#hotel-param-offers .ui-accordion-content-active .popup_param").replaceWith(data);
				/*time to check persons age.. */
				jQuery("#hotel-param-offers .ui-accordion-content-active .popup_list_main_box .persona").each(function(index){
					var age = "19" + jQuery(this).attr("age").substring(4);
					/* Fix on 2012, 2013... year*/
                                        var terminDo = jQuery("select[name='data_wyjazdu'] option:selected").val();
                                        var biezacyrok = parseISO8601(terminDo);
                                        var d = new Date().getFullYear();
                                        if (biezacyrok) {
                                                d = biezacyrok.getFullYear();
                                        }
					age = Number(d) - Number(age)
					var who = "";
					//alert(age);
					if ( age > 99){
						if ( age == 100 || age == 101 ){
							who = "Niemowlę";
						} else {
							age = age - 100;
							if ( age == 2 || age == 3 || age == 4)
								who = "Dziecko (" + age + " lata)";
							else
								who = "Dziecko (" + age + " lat)";
						}
					} else if ( age < 16 ){
						if ( age == 2 || age == 3 || age == 4)
							who = "Dziecko (" + age + " lata)";
						else
							who = "Dziecko (" + age + " lat)";
					} else {
						who = "Dorosły";
					}
					jQuery(this).text(who);	
				});
			},
			error: function(){
				jQuery("#hotel-param-offers .param-loading").fadeOut();
			}
		});
	} else {
		jQuery("#hotel-param-offers .ui-accordion-content-active .popup_param").fadeIn();	
	}
	
	
}

function hideKalkulacja(){
	jQuery("#hotel-param-offers .ui-accordion-content-active .popup_param").fadeOut();		
}

function hideLinkBezp(){
	jQuery("#popuplink").fadeOut();
}

function openLinkBezp(){
	jQuery("#popuplink").fadeIn();
}


function showFormatka(){
	if (firstClick == true){
		jQuery("#hotel-param-offers .ui-accordion-content-active").css("height","auto");
		fristClick = false;
	}
	if (jQuery("#afterFormatkaBAD").is(":hidden") && jQuery("#afterFormatkaOK").is(":hidden")){
		var formatka = jQuery("#formatka");
		jQuery("#formatka").remove();
		jQuery(formatka).appendTo("#hotel-param-offers .ui-accordion-content-active .formatka");
		jQuery("#formatka").show();
	} 
	jQuery("#formatka #afterFormatkaOK").css("display","none");
	jQuery("#formatka #afterFormatkaBAD").css("display","none");
	jQuery("#formatka table").show();
	jQuery("#formatka form input").css("visibility","visible");
	jQuery("#hotel-param-offers .ui-accordion-content-active .formatka").slideDown("slow",function(){
		jQuery("#formatka input[name='hotel']").val(jQuery("#obiekt-box .object_name").text());
		//jQuery("#formatka input[name='dojazd']").val(jQuery("#param_wyjazd_active").val());
		jQuery("#formatka input[name='dojazd']").val(jQuery("#hotel-param-offers .ui-state-active .akdojazd").text());
		jQuery("#formatka input[name='data_od']").val(jQuery(".parametryzacja_naglowek_main_box .terminy_param option:selected").val());
		jQuery("#formatka input[name='data_do']").val(jQuery("#hotel-param-offers .ui-state-active .terminDo").text());
		jQuery("#formatka input[name='kodId']").val(jQuery("#hotel-param-offers .ui-state-active .kodId").text());
		jQuery("#formatka input[name='tourOp']").val(jQuery("#hotel-param-offers .ui-state-active .tourOp").text());
		jQuery("#formatka input[name='htlCode']").val(jQuery("#hotel-param-offers .ui-state-active .htlCode").text());
		jQuery("#formatka input[name='xcode']").val(jQuery("#hotel-param-offers .ui-state-active .xcode").text());
		var link =  window.location.pathname + "?kodId="+ jQuery("#formatka input[name='kodId']").val()/*  + "&tourOp=" + jQuery("#formatka input[name='tourOp']").val() + "&htlCode=" + jQuery("#formatka input[name='htlCode']").val() */;
		jQuery("#formatka input[name='link']").val(link);
		if ( jQuery("#hotel-param-offers .ui-state-active .miasto_konkretne").text() != ""){
			jQuery("#formatka input[name='miasto_wyjazdu']").val(jQuery("#hotel-param-offers .ui-state-active .miasto_konkretne").text());
		} else if( jQuery(".wyjzad_z_param option:selected").val() != ''){
			jQuery("#formatka input[name='miasto_wyjazdu']").val(jQuery(".wyjzad_z_param option:selected").text());
		} else{
			jQuery("#formatka input[name='miasto_wyjazdu']").val('wlasny');
		}
		jQuery("#formatka input[name='cena']").val(jQuery("#hotel-param-offers .ui-accordion-content-active .total_prize_value").text().replace(" zł",""));
		jQuery("#hotel-param-offers .ui-accordion-content-active .zapytaj_button_box").css("visibility","hidden");
		var targetOffset = jQuery("#hotel-param-offers").offset().top;
		jQuery("html, body").animate({scrollTop: targetOffset}, 400);	
	});
}

function hideFormatka(){
	jQuery(".ui-accordion-content-active .formatka").slideUp("slow",function(){ 
			jQuery(".ui-accordion-content-active .zapytaj_button_box").css("visibility","visible");
			jQuery("#formatka").appendTo("#content_main");
	});
}


function sendForm(){
	var urlForZapytanie = '/hotele/wyslij_zapytanie_sokmds.xml';
	var addParams = jQuery("#formatka form").serialize();
	jQuery("#wloading").show();
	jQuery.ajax({
		type: 'POST',
		url: urlForZapytanie,
		data: encodeURI(encodeURI(addParams)),
		scriptCharset: "utf-8" ,
		contentType: "application/x-www-form-urlencoded; charset=UTF-8",
		dataType: 'xml',
		success: function(data) {
			if (jQuery(data).find('result').text() == 'OK' || jQuery(data).find('result').text() == 'ok') {
				showGoodResponse();
			} else {
				showBadResponse();
			}
		},
		error: function(){ showBadResponse(); }
	});  
	 
}


function showGoodResponse(){
	jQuery("#wloading").hide();
	jQuery("#formatka table").hide();
	jQuery("#formatka form input").css("visibility","hidden");
	jQuery("#formatka #afterFormatkaOK").css("display","inline");
	jQuery("#formatka #afterFormatkaOK table").css("display","inline");
	jQuery(".ui-accordion-content-active .zapytaj_button_box").css("visibility","visible");
}

function showBadResponse(){
	jQuery("#wloading").hide();
	jQuery("#formatka table").hide();
	jQuery("#formatka form input").css("visibility","hidden");
	jQuery("#formatka #afterFormatkaBAD").css("display","inline");
	jQuery("#formatka #afterFormatkaBAD table").css("display","inline");
	jQuery(".ui-accordion-content-active .zapytaj_button_box").css("visibility","visible");
}

function updateDates(){
	jQuery(".param-loading").css("height",jQuery("#hotel-param-offers").height());
	jQuery(".param-loading:hidden").fadeIn();
	tourOp = "";
	htlCode = "";
	searcher = "&searcher=1";
	urlForSearcher = jQuery("#url-for-searcher").text();
	
	searcher = searcher + "&adt="+jQuery('.dorosli_pob_param option:selected').val();
	searcher = searcher + getChildren();
	searcher = searcher + "&from="+jQuery('.wyjzad_z_param option:selected').val() + "&wyjazd="+jQuery('.wyjzad_z_param option:selected').val();
	if (jQuery.getUrlVar("tourOp")!='' && typeof jQuery.getUrlVar("tourOp") != 'undefined'){
		tourOp = jQuery.getUrlVar("tourOp");
	}
	if (jQuery.getUrlVar("htlCode")!='' && typeof jQuery.getUrlVar("htlCode") != 'undefined'){
		htlCode = jQuery.getUrlVar("htlCode");
	}
	// test fixera dla DR
	if (tourOp=='FTON' && htlCode==''){
		htlCode = jQuery("#akt_htlCode").text();
	}
	if (jQuery('#tourop option:selected').val() == tourOp  && htlCode !="") {
		urlForSearcher = urlForSearcher.replace('code','none');
		searcher = searcher + "&tourOp="+tourOp+"&htlCode="+htlCode ;
	} else {
		if (jQuery('#tourop option:selected').val() != '') 
			searcher = searcher + "&tourOp="+jQuery('#tourop option:selected').val();
	}
	
	if (typeof jQuery("#param_wyjazd_active").val() != 'undefined'){
		searcher = searcher + "&wyj=" +jQuery("#param_wyjazd_active").val();
	}
	
	if (jQuery('#tourop option:selected').val() == "FTON" && htlCode == ""){
		searcher = searcher + "&htlCode=" + jQuery("#direct_htlCode").text();
	}
	jQuery.ajax({
		url: urlForSearcher+searcher,
		dataType: 'html',
		success: function(data) {
			jQuery(".terminy_param").replaceWith(data);
			updateOffersAndPobyt();
		},
		error: function(){}
	});
}

function initParametryzacja(){
	jQuery(".param-loading").css("height",jQuery("#hotel-param-offers").height());
	jQuery(".param-loading:hidden").fadeIn();
	var tourOp ="";
	var htlCode ="";
	var urlForSearcher = jQuery("#url-for-searcher").text();
	
	var searcher = "";
	if (jQuery.getUrlVar("tourOp")!='' && typeof jQuery.getUrlVar("tourOp") != 'undefined'){
		tourOp = jQuery.getUrlVar("tourOp");
	}
	if (jQuery.getUrlVar("htlCode")!='' && typeof jQuery.getUrlVar("htlCode") != 'undefined'){
		htlCode = jQuery.getUrlVar("htlCode");
	}
	// test fixera dla DR
	if (tourOp=='FTON' && htlCode==''){
		htlCode = jQuery("#akt_htlCode").text();
	}
	if (jQuery.getUrlVar("adt")!='' && typeof jQuery.getUrlVar("adt") != 'undefined'){
		adtVal = parseInt(jQuery.getUrlVar("adt"));
		jQuery("select[name='dorosli'] option[value='"+ adtVal +"']").attr("selected","1");
	} else {
		jQuery("select[name='dorosli'] option[value='"+jQuery("#domyslne_dorosli").text()+"']").attr("selected","selected");
	}
	if (jQuery.getUrlVar("chd")!='' && typeof jQuery.getUrlVar("chd") != 'undefined'){
		jQuery('#search-check-chld').click();
		if (jQuery("#search-check-chld:checked").val() == 1) {
			jQuery("#wyszukiwarka_box_kids_drops").show();
			jQuery("#wyszukiwarka_box_kids .pozdroz_z_dziecmi").hide();
			jQuery("#wyszukiwarka_box_kids .wiek_dzieci").show();
		}
		else {
			jQuery("#wyszukiwarka_box_kids_drops").hide();
			jQuery("#wyszukiwarka_box_kids .pozdroz_z_dziecmi").show();
			jQuery("#wyszukiwarka_box_kids .wiek_dzieci").hide();
		}
		if (jQuery.getUrlVar("chage")!='' && typeof jQuery.getUrlVar("chage") != 'undefined'){
			var chd_age = jQuery.getUrlVar("chage");
			var child_age_arr = [];
			child_age_arr= chd_age.split(',');
			jQuery(child_age_arr).each(function(index){
				jQuery("#wyszukiwarka_box_kids_drops select:eq("+index+") option[value="+jQuery(this).get()+"]").attr("selected","1")
			}); 
			
		}
	} else if (jQuery("#domyslne_dzieci").text() != '0'){
		jQuery("#search-check-chld").attr("checked","1");
		if (jQuery("#search-check-chld:checked").val() == 1) {
			jQuery("#wyszukiwarka_box_kids_drops").show();
			jQuery("#wyszukiwarka_box_kids .pozdroz_z_dziecmi").hide();
			jQuery("#wyszukiwarka_box_kids .wiek_dzieci").show();
		}
		else {
			jQuery("#wyszukiwarka_box_kids_drops").hide();
			jQuery("#wyszukiwarka_box_kids .pozdroz_z_dziecmi").show();
			jQuery("#wyszukiwarka_box_kids .wiek_dzieci").hide();
		}
		if (jQuery("#domyslne_dzieci").text() == "1") {
			jQuery("#c1 option[value='5']").attr("selected","selected");
		} else if (jQuery("#domyslne_dzieci").text() == "2") {
			jQuery("#c1 option[value='5']").attr("selected","selected");
			jQuery("#c2 option[value='5']").attr("selected","selected");
		} else if (jQuery("#domyslne_dzieci").text() == "3") {
			jQuery("#c1 option[value='5']").attr("selected","selected");
			jQuery("#c2 option[value='5']").attr("selected","selected");
			jQuery("#c3 option[value='5']").attr("selected","selected");
		} 
			
	}
	if (jQuery('#tourop option:selected').val() == tourOp  && htlCode !="") {
		urlForSearcher = urlForSearcher.replace('code','none');
		searcher = searcher + "&tourOp="+tourOp+"&htlCode="+htlCode ;
	} else {
		if (jQuery('#tourop option:selected').val() != '') 
			searcher = searcher + "&tourOp="+jQuery('#tourop option:selected').val();
	}
	
	if (typeof jQuery("#param_wyjazd_active").val() != 'undefined'){
		searcher = searcher + "&wyj=" +jQuery("#param_wyjazd_active").val();
	}
	
	if (jQuery('#tourop option:selected').val() == "FTON" && htlCode == ""){
		searcher = searcher + "&htlCode=" + jQuery("#direct_htlCode").text();
	}
	jQuery.ajax({
		url: urlForSearcher+searcher+"&dropdowns=1",
		dataType: 'html',
		success: function(data) {
			jQuery("#new-data").replaceWith(data);
			jQuery(".parametryzacja_naglowek_main_box .terminy_param").replaceWith(jQuery("#new-data .terminy_param"));
			jQuery(".parametryzacja_naglowek_main_box .dl_pob_param").replaceWith(jQuery("#new-data .dl_pob_param"));
			if (firstUpdate == true ){
				jQuery("select[name='dlugosc_pobytu'] option[value='"+jQuery("#dlugosc_domyslna").text()+"']").attr("selected","selected");
			}
			jQuery(".parametryzacja_naglowek_main_box .wyjzad_z_param").replaceWith(jQuery("#new-data .wyjzad_z_param"));
			jQuery(".parametryzacja_naglowek_main_box #param_wyzywienie").replaceWith(jQuery("#new-data #param_wyzywienie"));
			var domwyz = jQuery('#wyzywienie_domyslne').text();
			if (domwyz != ""){
				jQuery("#param_wyzywienie").val(domwyz);
				//jQuery("li#"+jQuery('#wyzywienie_domyslne').text()).addClass("param_wyzywienie_active");
			}
			if (jQuery("#param_wyjazd_active").val() == 'H'){
				jQuery('.bez_wlasnego_dojazdu').hide();
				jQuery('.parametryzacja_terminy').css('width','466px');
				jQuery('.terminy_param').css('width','466px');
			}
			if (jQuery("#oferta_niedostepna").text() != ''){
				addDefaultItem('terminy_param');	
				addDefaultItem('dl_pob_param');	
				firstUpdate = false;
				if (jQuery(".big_blue_prize_direct").hasClass("price-loading")){
					jQuery(".big_blue_prize_direct").removeClass("price-loading");
				}
				if (jQuery(".big_blue_prize").hasClass("price-loading")){
					jQuery(".big_blue_prize").removeClass("price-loading");
				}
				var rodzajStrony = getParameter('p');
				if (rodzajStrony == 'opinie') {
					openTab("zoover");
				}
				jQuery("#anotherLinkDoOferty_print").hide();
				jQuery(".drukuj_opis_ico").hide();
				jQuery("#social-send").hide();
			} else {
				//fix
				jQuery(".terminy_param option[value='"+jQuery("#data_domyslna").text()+"']").attr("selected","selected");	
				searcher = searcher + "&data="+jQuery('select[name="data_wyjazdu"] option:selected').val();
				searcher = searcher + getChildren();
				jQuery.ajax({
					url: urlForSearcher+searcher+"&dropdowns=1",
					dataType: 'html',
					success: function(data) {
						jQuery("#new-data").replaceWith(data);
						jQuery(".parametryzacja_naglowek_main_box .dl_pob_param").replaceWith(jQuery("#new-data .dl_pob_param"));
						if (firstUpdate == true ){
							jQuery("select[name='dlugosc_pobytu'] option[value='"+jQuery("#dlugosc_domyslna").text()+"']").attr("selected","selected");
						}
						jQuery(".parametryzacja_naglowek_main_box #param_wyzywienie").replaceWith(jQuery("#new-data #param_wyzywienie"));
						jQuery("#new-data .wyjzad_z_param").remove();
						jQuery("#new-data .terminy_param").remove();
						jQuery("select[name='miejsce_wyjazdu'] option[value='"+jQuery("#miasto_domyslne").text()+"']").attr("selected","selected");
						jQuery("#miasto_domyslne").text("");
						var domwyz = jQuery('#wyzywienie_domyslne').text();
						if (domwyz != ""){
							jQuery("#param_wyzywienie").val(domwyz);
							//jQuery("li#"+jQuery('#wyzywienie_domyslne').text()).addClass("param_wyzywienie_active");
						}
						updateOffers(-7);
					},
					error: function(){}
				});
			}
		},
		error: function(){}
	});
	
}

function addDefaultItem(which){
	jQuery('.'+which).prepend( new Option('- dowolny -','') );
	jQuery('.'+which +' option[value=""]').attr("selected","selected");
	jQuery('.'+which +' option[value=""]').attr("disabled","disabled");
}

function updateOffersAndPobyt(){
	jQuery(".param-loading").css("height",jQuery("#hotel-param-offers").height());
	jQuery(".param-loading:hidden").fadeIn();
	tourOp ="";
	htlCode ="";
	urlForSearcher = jQuery("#url-for-searcher").text();
	
	searcher = "";
	if (jQuery.getUrlVar("tourOp")!='' && typeof jQuery.getUrlVar("tourOp") != 'undefined'){
		tourOp = jQuery.getUrlVar("tourOp");
	}
	if (jQuery.getUrlVar("htlCode")!='' && typeof jQuery.getUrlVar("htlCode") != 'undefined'){
		htlCode = jQuery.getUrlVar("htlCode");
	}
	// test fixera dla DR
	if (tourOp=='FTON' && htlCode==''){
		htlCode = jQuery("#akt_htlCode").text();
	}
	if (jQuery('#tourop option:selected').val() == tourOp  && htlCode !="") {
		urlForSearcher = urlForSearcher.replace('code','none');
		searcher = searcher + "&tourOp="+tourOp+"&htlCode="+htlCode ;
	} else {
		if (jQuery('#tourop option:selected').val() != '') 
			searcher = searcher + "&tourOp="+jQuery('#tourop option:selected').val();
	}
	if (jQuery("#param_wyjazd_active").val() != 'H' && jQuery('.wyjzad_z_param option:selected').val() != undefined) 
		searcher = searcher + "&wyjazd="+jQuery('.wyjzad_z_param option:selected').val();
	
	if (typeof jQuery("#param_wyjazd_active").val() != 'undefined')
		searcher = searcher + "&wyj=" +jQuery("#param_wyjazd_active").val();
	
	searcher = searcher + "&data="+jQuery('select[name="data_wyjazdu"] option:selected').val();
	searcher = searcher + getChildren();
	
	if (jQuery('#tourop option:selected').val() == "FTON" && htlCode == ""){
		searcher = searcher + "&htlCode=" + jQuery("#direct_htlCode").text();
	}
	jQuery.ajax({
		url: urlForSearcher+searcher+"&dropdowns=1",
		dataType: 'html',
		success: function(data) {
			jQuery("#new-data").replaceWith(data);
			jQuery(".parametryzacja_naglowek_main_box .dl_pob_param").replaceWith(jQuery("#new-data .dl_pob_param"));
			jQuery(".parametryzacja_naglowek_main_box #param_wyzywienie").replaceWith(jQuery("#new-data #param_wyzywienie"));
			jQuery("#new-data .wyjzad_z_param").remove();
			jQuery("#new-data .terminy_param").remove();
			var domwyz = jQuery('#wyzywienie_domyslne').text();
			if (domwyz != ""){
				jQuery("#param_wyzywienie").val(domwyz);
				//jQuery("li#"+jQuery('#wyzywienie_domyslne').text()).addClass("param_wyzywienie_active");
			}
			updateOffers(-6);
		},
		error: function(){}
	});	
}

function updateOffersAndDrops(){
	jQuery(".param-loading").css("height",jQuery("#hotel-param-offers").height());
	jQuery(".param-loading:hidden").fadeIn();
	tourOp ="";
	htlCode ="";
	urlForSearcher = jQuery("#url-for-searcher").text();
	
	searcher = "";
	if (jQuery.getUrlVar("tourOp")!='' && typeof jQuery.getUrlVar("tourOp") != 'undefined'){
		tourOp = jQuery.getUrlVar("tourOp");
	}
	if (jQuery.getUrlVar("htlCode")!='' && typeof jQuery.getUrlVar("htlCode") != 'undefined'){
		htlCode = jQuery.getUrlVar("htlCode");
	}
	// test fixera dla DR
	if (tourOp=='FTON' && htlCode==''){
		htlCode = jQuery("#akt_htlCode").text();
	}
	if (jQuery('#tourop option:selected').val() == tourOp  && htlCode !="") {
		urlForSearcher = urlForSearcher.replace('code','none');
		searcher = searcher + "&tourOp="+tourOp+"&htlCode="+htlCode ;
	} else {
		if (jQuery('#tourop option:selected').val() != '') 
			searcher = searcher + "&tourOp="+jQuery('#tourop option:selected').val();
	}
	
	if (typeof jQuery("#param_wyjazd_active").val() != 'undefined'){
		searcher = searcher + "&wyj=" +jQuery("#param_wyjazd_active").val();
	}
	
	if (jQuery('#tourop option:selected').val() == "FTON" && htlCode == ""){
		searcher = searcher + "&htlCode=" + jQuery("#direct_htlCode").text();
	}
	jQuery.ajax({
		url: urlForSearcher+searcher+"&dropdowns=1",
		dataType: 'html',
		success: function(data) {
			jQuery("#new-data").replaceWith(data);
			jQuery(".parametryzacja_naglowek_main_box .dl_pob_param").replaceWith(jQuery("#new-data .dl_pob_param"));
			jQuery(".parametryzacja_naglowek_main_box .wyjzad_z_param").replaceWith(jQuery("#new-data .wyjzad_z_param"));
			jQuery(".parametryzacja_naglowek_main_box #param_wyzywienie").replaceWith(jQuery("#new-data #param_wyzywienie"));
			var domwyz = jQuery('#wyzywienie_domyslne').text();
			if (domwyz != ""){
				jQuery("#param_wyzywienie").val(domwyz);
				//jQuery("li#"+jQuery('#wyzywienie_domyslne').text()).addClass("param_wyzywienie_active");
			}
			jQuery("#new-data .terminy_param").remove();
			updateOffers(-7);
		},
		error: function(){}
	});	
}
function updateOffers(pageNumber){
	var tourOp = "";
	var htlCode = "";
	var searcher = "";
	var urlForSearcher = jQuery("#url-for-searcher").text();
	
	// usuwamy opcje dowolne
	jQuery(".terminy_param option[value='']").remove();
	jQuery(".dl_pob_param option[value='']").remove();
	
	if (pageNumber != '-1' && pageNumber != '-2' && pageNumber != '-3' && pageNumber != '-4' && pageNumber != '-5' && pageNumber != '-6' && pageNumber != '-7' && pageNumber != '-8'){
		searcher = searcher+"&current_page="+pageNumber;
		maxNumbers = maxNumbers < pageNumber ? pageNumber : maxNumbers;
		if (maxNumbers != 0 ) searcher = searcher+"&max_page=" + maxNumbers;
	} else {
		maxNumbers = 0;	
	}
	if (jQuery.getUrlVar("tourOp")!='' && typeof jQuery.getUrlVar("tourOp") != 'undefined'){
		tourOp = jQuery.getUrlVar("tourOp");
	}
	if (jQuery.getUrlVar("htlCode")!='' && typeof jQuery.getUrlVar("htlCode") != 'undefined'){
		htlCode = jQuery.getUrlVar("htlCode");
	}
	// test fixera dla DR
	if (tourOp=='FTON' && htlCode==''){
		htlCode = jQuery("#akt_htlCode").text();
	}
	if (jQuery('#tourop option:selected').val() == tourOp  && htlCode !="") {
		urlForSearcher = urlForSearcher.replace('code','none');
		searcher = searcher + "&tourOp="+tourOp+"&htlCode="+htlCode ;
	} else {
		if (jQuery('#tourop option:selected').val() != '') 
			searcher = searcher + "&tourOp="+jQuery('#tourop option:selected').val();
	}
	if (firstUpdate == true ){
		jQuery(".terminy_param option[value='"+jQuery("#data_domyslna").text()+"']").attr("selected","selected");
		if (jQuery.getUrlVar("kodId")!='' && typeof jQuery.getUrlVar("kodId") != 'undefined'){
			searcher = searcher + "&kodId=" + jQuery.getUrlVar("kodId");
		}
	}
	if (jQuery('.terminy_param option:selected').val() != undefined ){
		searcher = searcher + "&termin="+jQuery('.terminy_param option:selected').val();
		searcher = searcher + "&date="+jQuery('.terminy_param option:selected').val();
	}
	if (pageNumber != '-8' && pageNumber != '-6') {
		searcher = searcher + "&pobyt="+jQuery('.dl_pob_param option:selected').val();
	}
	if (jQuery("#param_wyjazd_active").val() != 'H' && jQuery('.wyjzad_z_param option:selected').val() != undefined) {
		searcher = searcher + "&wyjazd="+jQuery('.wyjzad_z_param option:selected').val();
	}
	var wyzywienieSearch = jQuery("#param_wyzywienie").val();
	if (wyzywienieSearch != undefined ){
		if (wyzywienieSearch == 'inne'){
			searcher = searcher + "&wyz=snack,obiad";
		} else if (wyzywienieSearch == 'prog'){
			searcher = searcher + "&wyz=prog";
		} else if (wyzywienieSearch == 'brak'){
			searcher = searcher + "&wyz=brak";
		} else {
			searcher = searcher + "&wyz=" + wyzywienieSearch;
		}
	}
	if (jQuery("#param_wyjazd_active").val() != undefined){
		searcher = searcher + "&wyj=" +jQuery("#param_wyjazd_active").val();
	}
	if(jQuery("#typ_obiektu").text() == 'AP' ) {
		var dzieci = getChildren() != '' ? parseInt(getChildren()) : "";
		var dorosli = parseInt(jQuery('.dorosli_pob_param option:selected').val());
		dorosli = dorosli + dzieci;
		searcher = searcher + "&adt="+dorosli;
	} else if(jQuery('.dorosli_pob_param option:selected').val() != undefined ){
		searcher = searcher + "&adt="+jQuery('.dorosli_pob_param option:selected').val() + getChildren();
	}
	jQuery(".param-loading").css("height",jQuery("#hotel-param-offers").height());
	jQuery(".param-loading:hidden").fadeIn();
	if (jQuery('#tourop option:selected').val() == "FTON" && htlCode == ""){
		searcher = searcher + "&htlCode=" + jQuery("#direct_htlCode").text();
	}
	jQuery.ajax({
		url: urlForSearcher+searcher,
		dataType: 'html',
		success: function(data) {
			var tempDiv = "";
			if ( jQuery("#hotel-param-offers #brak_wynikow_main_box_center") && jQuery("#hotel-param-offers #brak_wynikow_main_box_center").length > 0){
				tempDiv = jQuery("#hotel-param-offers #brak_wynikow_main_box_center .brak_wynikow_akcent");
				var tempDiv4 = jQuery("#hotel-param-offers #brak_wynikow_main_box_center .info_wyniki_box_brak");
			}
			jQuery("#content_main").append(jQuery("#formatka"));
			jQuery("#formatka").hide();
			jQuery("#paginator").remove();
			jQuery("#hotel-param-offers").replaceWith(data);
			jQuery(".our_phone_dest").text(jQuery("#phone-number").text());
			 
			if ( jQuery("#hotel-param-offers #brak_wynikow_main_box_center") && jQuery("#hotel-param-offers #brak_wynikow_main_box_center").length > 0){
				var text = "";
				text = pageNumber == '-2' ? "liczba osób dorosłych" : text;
				text = pageNumber == '-3' ? "długość pobytu" : text;
				text = pageNumber == '-4' ? "wyżywienie" : text;
				text = pageNumber == '-5' ? "liczba/wiek dzieci" : text;
				text = pageNumber == '-6' ? "termin lub liczbę osób dorosłych" : text;
				text = pageNumber == '-7' ? "transport lub liczbę osób dorosłych" : text;
				text = pageNumber == '-8' ? "wyjazd z" : text;
				jQuery("#brak_wynikow_main_box_center .brak_wynikow_akcent").text(text);
				var tempDiv2 = jQuery("#brak_wynikow_main_box_center .brak_wynikow_akcent");
				var tempDiv3 = jQuery("#brak_wynikow_main_box_center .info_wyniki_box_brak");
				if (tempDiv.length > 0 && tempDiv2.length == 1) {
					tempDiv2 = jQuery('<div>').append(tempDiv2.clone()).remove().html();
					tempDiv = jQuery('<div>').append(tempDiv.clone()).remove().html();
					var tempDiv4 = jQuery('<div>').append(tempDiv4.clone()).remove().html();
					if (tempDiv.indexOf(tempDiv2) != -1) {
						jQuery(tempDiv4).insertBefore("#brak_wynikow_main_box_center .info_wyniki_box_brak");
						tempDiv3.remove();
					}
					else {
						jQuery(tempDiv4).insertBefore("#brak_wynikow_main_box_center .info_wyniki_box_brak");
					}
				}
				jQuery("#kod_oferty_obiektu").hide();
				jQuery("#box_additional_info").hide();
				jQuery("#anotherLinkDoOferty").hide();
				jQuery("#anotherLinkDoOferty_pic").hide();
				jQuery("#anotherLinkDoOferty_print").hide();
				jQuery(".drukuj_opis_ico").hide();
				jQuery("#social-send").hide();
				jQuery("#social_container").hide();
				jQuery("#social_container2").hide();
				jQuery("<div style='display: none;' class='param-loading'></div>").insertBefore("#hotel-param-offers .parametryzajcja_list_element_main_box");
				if (firstUpdate == true ){
					var rodzajStrony = getParameter('p');
					if (rodzajStrony == 'opinie') {
						openTab("zoover");
					}	
				}
				if (jQuery(".big_blue_prize_direct").hasClass("price-loading")){
                                	jQuery(".big_blue_prize_direct").removeClass("price-loading");
                        	}
			} else {
				startParamAccordeon();
				var nowaCena = parseInt(jQuery(".ui-accordion-content-active .total_prize_value").text());
				if (jQuery("select[name='data_wyjazdu'] option:selected").text().indexOf("zł") == -1 && jQuery("select[name='data_wyjazdu'] option:selected").text().indexOf("od") == -1 &&  jQuery(".ui-accordion-content-active .total_prize_value") != '' && jQuery(".ui-accordion-content-active .total_prize_value").text() !=''){
					jQuery("select[name='data_wyjazdu'] option:selected").text(jQuery("select[name='data_wyjazdu'] option:selected").val() + "\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 od " + nowaCena + " zł");
				} else {
					var indexOfZ = jQuery("select[name='data_wyjazdu'] option:selected").text().indexOf("zł");	
					var staraCena = parseInt(jQuery("select[name='data_wyjazdu'] option:selected").text().substring(22,indexOfZ-1));
					jQuery("select[name='data_wyjazdu'] option:selected").text(jQuery("select[name='data_wyjazdu'] option:selected").val() + "\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 od " + nowaCena + " zł");
				}
			
				jQuery("#kod_oferty_obiektu").show();
				jQuery("#box_additional_info").show();
				jQuery("#anotherLinkDoOferty").show();
				jQuery("#anotherLinkDoOferty_pic").show();
				jQuery("#anotherLinkDoOferty_print").show();
				jQuery(".drukuj_opis_ico").show();
				jQuery("#social-send").show();
				jQuery("#social_container").show();
				jQuery("#social_container2").show();
				jQuery("<div style='display: none;' class='param-loading'></div>").insertBefore("#hotel-param-offers .ui-state-active");
				if (firstUpdate == true ){
					var rodzajStrony = getParameter('p');
					if (rodzajStrony == 'opinie') {
						openTab("zoover");
					}	
					if (jQuery.getUrlVar("kodId")!='' && typeof jQuery.getUrlVar("kodId") != 'undefined'){
						var found = false;
						var kod = jQuery.getUrlVar("kodId");
							jQuery("#hotel-param-offers h3 div .kodId").each(function(index){
								if(jQuery(this).text() == kod){
									jQuery("#hotel-param-offers").accordion("activate", index);
									found= true;
								};
							});
					}
				}
			}
			firstUpdate = false;
			translateDays();
			changeOfertyURL();
			if (jQuery("#tourop option").length > 2 && jQuery("#tourop option:selected").val() == '') jQuery(".touroperator_do_ukrycia").css("visibility","visible");
			jQuery("#biura-podrozy").attr("href","http://www.travelone.pl/biura-podrozy/tourOp.xml?kod="+jQuery(".ui-state-active .tourOpId").text());
			jQuery("#biura-podrozy-warunki").attr("href","javascript:warunki('" + jQuery(".ui-state-active .tourOpId").text() + "M')");
			jQuery("#dodatkowyUrlDlaRezerwacji").attr("onclick","checkAvail('"+jQuery(".ui-accordion-content-active .urlDoRezerwacji").attr("href")+"');")
			jQuery("#biura-podrozy").attr("href","http://www.travelone.pl/biura-podrozy/tourOp.xml?kod="+jQuery(".ui-state-active .tourOpId").text());
			//if(jQuery(".ui-state-active .tourOpId").text() != '') jQuery(".left_dodatkowe_info_image").attr("src","http://www.travelone.pl/photo/mini/"+jQuery(".ui-state-active .tourOpId").text()+"-0001.jpg");
			jQuery("select[name='dl_pob_param'] option[value='"+jQuery(".ui-accordion-content-active .dlugosc_pobytu_d").text()+"']").attr("selected","selected");
			jQuery(".ui-state-active .paramtryzacja_list_separator_vert").css('display','none');
			jQuery(".big_blue_prize").text(jQuery(".ui-accordion-content-active .total_prize_value").text());
			if (jQuery(".big_blue_prize").hasClass("price-loading")){
				jQuery(".big_blue_prize").removeClass("price-loading");
			}
			setAkDojazd();
			jQuery("#akt_htlCode").text(jQuery(".ui-state-active .htlCode").text());
			jQuery("#akt_tourOp").text(jQuery(".ui-state-active .tourOp").text());
			if (jQuery("#akt_tourOp").text() == 'RDLF'){
				jQuery("#rudolf_bez_ubezpieczenia").hide();
				jQuery("#rudolf_bez_ubezpieczenia_2").show();
				jQuery("#rudolf_bez_ubezpieczenia_3").hide();
			}else{
				jQuery("#rudolf_bez_ubezpieczenia").show();
				jQuery("#rudolf_bez_ubezpieczenia_2").hide();
				jQuery("#rudolf_bez_ubezpieczenia_3").show();
			}
			jQuery("#obiekt_name_MDS").text(jQuery(".ui-state-active .hotelName").text());
			jQuery(".dl_pob_param option[value='"+jQuery("#hotel-param-offers .ui-accordion-content-active .dlugosc_pobytu_d").text()+"']").attr("selected","selected");
			jQuery(".parametryzajcja_list_element_main_box").mouseenter(function() {
					jQuery(this).css("cursor","pointer");
			}).mouseleave(function() {
					jQuery(this).css("cursor","default");
			});

		},
		error: function(){
			firstUpdate = false;
		}
	});
	jQuery(".parametryzacja_main_box").css("float","left");
	jQuery(".parametryzacja_main_box").css("float","none");
	
}


/* Odczytywanie parametru GET */
function getParameter(paramName) {
  var searchString = window.location.search.substring(1), i, val, params = searchString.split("&");
  for (i = 0; i < params.length; ++i) {
    val = params[i].split("=");
    if (val[0] == paramName) {
      return unescape(val[1]);
    }
  }
  return null;
}
function translateDays(){
	jQuery("#hotel-param-offers h3 .parametryzajcja_list_element_main_box table tbody tr td span").children().each(function(index,val){
		if(jQuery(this).filter("[class='dzien-tygodnia']").size() == 1){
			var myDateArray = jQuery(this).attr("date").split("-");
			var newDate = new Date(myDateArray[0],myDateArray[1]-1,myDateArray[2]).getDay(); 
			if (newDate == '1'){
				jQuery(this).text('poniedziałek');
			} else if (newDate == '2') {
				jQuery(this).text('wtorek');
			} else if (newDate == '3') {
				jQuery(this).text('środa');
			} else if (newDate == '4') {
				jQuery(this).text('czwartek');
			} else if (newDate == '5') {
				jQuery(this).text('piątek');
			} else if (newDate == '6') {
				jQuery(this).text('sobota');
			} else if (newDate == '0') {
				jQuery(this).text('niedziela');
			}
		}
	});
}


function turnOnReserveButton(){
	jQuery("#oferta-box-reserve-btn > img").fadeOut(1000,function(){
		jQuery("#offer-reserve").fadeIn(2000);
	});
}

function initUrls(){
	jQuery("#oferta-box-more-doplata").toggle(
		function(){
			jQuery("#oferta-box-properties").show();
			jQuery("#oferta-box-more-doplata").html("ukryj dodatkowe informacje");
		},function(){
			jQuery("#oferta-box-properties").hide();
			jQuery("#oferta-box-more-doplata").html("zobacz dodatkowe informacje");
		});	
	jQuery("#oferta-price-val a").click(function(){
		if(jQuery("#oferta-box-properties").css("display") == "none"){
			jQuery("#oferta-box-more-doplata").click();
			jQuery("#oferta-box-properties").show();
			window.location = "#k2_doplata";
		}
	});
	jQuery(".oferta-box-more-tourop").click(function(){
		if(jQuery("#hotel-tourop").css("display") == "none"){
			jQuery("#tabs-box").tabs("select","hotel-tourop");	
		}
	});
}

function loadInfoBanner(serwis, nr_tel){
	var params = {
		quality: "high",
		allowscriptaccess: "always",
		wmode: "transparent"
	};
	swfobject.embedSWF("http://www." + varArray["serwis"] +"/flash/oferta/infolinia_oferta_small.swf?ClickTag=http://www."+ serwis +"&nr="+ nr_tel +"&panstwo="+ serwis, "oferta-box-infolinia", "183", "70", "9.0.0", "", "", params, "", "");
	jQuery("#oferta-box-reserve-btn:empty").next().css("float","none");
}

function loadSkiBookBanner(){
		var params = {
		quality: "high",
		allowscriptaccess: "always",
		wmode: "transparent"
	};
	swfobject.embedSWF("http://www." + varArray["serwis"] +"/flash/bannery/billboard_183x140.swf", "hotel-secure-reserve-box-banner", "183", "140", "9.0.0", "", "", params, "", "");
}

function loadPartnerBanner() {
        var params = {
                quality : "high",
                allowscriptaccess : "always",
                wmode : "opaque"
        };
        swfobject.embedSWF("http://www.chorwacja.pl/flash/bannery/austriainfo_box183x140_tranzyt.swf", "banner-partner", "183", "140",
                        "9.0.0", "", "", params, "");
}

jQuery.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return jQuery.getUrlVars()[name];
  }
});

function initFiczers(){
	jQuery("#test").show();
	jQuery("#target").show();
	jQuery("#obiekt-box .galeria_description").show();
	jQuery(".opis_wyjazd_type").css("display","none");
	//jQuery('#opis_wyjazd_'+jQuery("#param_wyjazd .param_wyzywienie_active").attr("id")).css("display","inline");
	jQuery('#opis_wyjazd_'+jQuery("#param_wyjazd_active").val()).css("display","inline");
	jQuery(".opinia_travelone_mainbox_bottom").toggle(function(){
		jQuery("#ourOpis").slideDown("slow",function(){
			jQuery(".opinia_travelone_mainbox_bottom").css("background-position","-180px -386px");
		});
	},function(){
		jQuery("#ourOpis").slideUp("slow",function(){
			jQuery(".opinia_travelone_mainbox_bottom").css("background-position","-180px -347px");
		});
	});
	jQuery("#dodatkowyUrlDlaRezerwacji").mouseenter(function() {
			jQuery(this).css("text-decoration","underline");
	}).mouseleave(function() {
			jQuery(this).css("text-decoration","none");
	});	
}
function fbs_click() {
	u='http://' + document.domain + jQuery('#anotherLinkDoOferty').attr('href2');
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&amp;t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}
function fbs_click2() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&amp;t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}
function addFavorites(){
	if (document.all) {
		window.external.addFavorite(document.location.href,document.getElementsByName('description')[0].content);
	} else if (window.sidebar){
		window.sidebar.addPanel(document.location.href,document.getElementsByName('description')[0].content);
	}
}
function initGaleriaBox(){
    jQuery("#galeria_scroll.scrollable").scrollable({
        circular: false,
        mousewheel: true,
        onSeek: function(event, index){
            jQuery("#galeria_nr_zdjecia").html(index+1);
        },
        onBeforeSeek: function(event,index){
        	// tak te if'y to obsluga strzalek:1- jeden lub zero obrazkow 2- pierwszy element, 3- ostatni element, 4- po zaladowaniu kolejnego obrazka, 5- przed zaladowaniem kolejnego obrazka, 6-pozostale
		/*  if (photoContainer.length == 1) {
			jQuery(".galeria_sterowanie .ster_left img").attr("src","/imgs/site/narty/lewo_P.png");
			jQuery(".galeria_sterowanie .ster_right img").attr("src","/imgs/site/narty/prawo_P.png");
		} else  */ if (index == 0 ){
			jQuery(".galeria_sterowanie .ster_left div").attr("id","galeria_ster_left_p");
			jQuery(".galeria_sterowanie .ster_right div").attr("id","galeria_ster_right_a");
		} else if (index >= photoContainer.length - 1 ){
			jQuery(".galeria_sterowanie .ster_right div").attr("id","galeria_ster_right_p");
			jQuery(".galeria_sterowanie .ster_left div").attr("id","galeria_ster_left_a");
		} else if ( galleryNextImg && index == galleryPositionIndex ){
			jQuery(".galeria_sterowanie .ster_right div").attr("id","galeria_ster_right_a");
			jQuery(".galeria_sterowanie .ster_left div").attr("id","galeria_ster_left_a");
		} else if ( index >= galleryPositionIndex){
			jQuery(".galeria_sterowanie .ster_right div").attr("id","galeria_ster_right_p");
			jQuery(".galeria_sterowanie .ster_left div").attr("id","galeria_ster_left_a");
		} else {
			jQuery(".galeria_sterowanie .ster_right div").attr("id","galeria_ster_right_a");
			jQuery(".galeria_sterowanie .ster_left div").attr("id","galeria_ster_left_a");
		}
		
		api = jQuery("#galeria_scroll.scrollable").data("scrollable");
		if (index < photoContainer.length){
			jQuery("#test a:eq("+api.getIndex()+")").css("display","none");
			jQuery("#test a:eq("+index+")").css("display","block");
		}
        	if (index < photoContainer.length && api.getIndex()+1 == index && galleryPositionIndex < index && galleryNextImg){
        		jQuery(".galeria_sterowanie .ster_right img").attr("id","galeria_ster_right_p");
        		galleryPositionIndex++;
			galleryNextImg = false;
        		jQuery("#target").html("<div><img src='http://www.egipt.info.pl//imgs/obiekt/loader_max.gif' width='300' height='210'></div>");
        		jQuery("#target_tmp").append("<img width='300' height='210' src='" +photoContainer[index] +"' onload='changeSrc("+ index +");'/>");
			api.addItem(jQuery("#target div").clone()).end();
			jQuery("#target").text("");
		} 
        }
    });
    jQuery("#test").insertAfter(jQuery(".galeria_sterowanie .ster_left"));
    jQuery(".galeria_sterowanie a.next, .galeria_sterowanie a.prev").hover(function(){
        jQuery(this).addClass('galeria_ster-hover');
      },function(){
        jQuery(this).removeClass('galeria_ster-hover');
    });
}

function initTabsBox(){
	var indexOfOffers;
	jQuery("#tabs-box ul li").children().each(function(index){
			//alert(index);
			if(jQuery(this).filter("[title='offers']").size() == 1){
				indexOfOffers=index;
			};
	});
	
	jQuery("#tabs-box").tabs({ 
		spinner: '<em class="tabs-loader">Wczytuję&#160;&#160;&#160;&#160;&#160;&#160;</em>',
		cache: true,
		disabled: [indexOfOffers],
		load: function(event,ui){
			/*if(ui.panel.id == "offers"){*/
				jQuery("#hotel-offers tr:[href]").each(function(){
					if(jQuery(this).attr("id") == jQuery("#oferta-box-kod span").html()){
						jQuery(this).remove();
					}else{
						jQuery(this).click(function() {
							url = jQuery(this).attr("href");
							location.href = url;
						});
					}
				});
				if(jQuery("#hotel-offers tr:[href]").size() == 0)
					jQuery("#tabs-box").tabs("disable",ui.index);
			//}
		},
		select: function(event,ui){
				if(jQuery(ui.tab).attr("href") == "#gallery" && galleryStarted == false){
					galleryStarted = true;
					initGallery();
					if (naszobiekt != "")
						reloadZooverGallery(1,1);
				}
				if(jQuery(ui.tab).attr("href") == "#gallery" && reloadGallery == true){
					reloadGalleryTourOp();
				}
		},
		show: function(event,ui){
			if(jQuery(ui.tab).attr("href") == "#gallery" && galleryStarted == false){
				galleryStarted = true;
				initGallery();
				if (naszobiekt != "")
					reloadZooverGallery(1,1);
			}
		}
	});
	//if (jQuery(".plan_wakacje_term select option").size() == 0){	
	//	
	//}
		
	jQuery("#tabs-box ul.ui-tabs-nav li").each(function(index){
		jQuery(document.createElement('li')).css({ 	'background-image':'url(/imgs/obiekt/param_separator_menu.jpg)',
								'background-repeat':'no-repeat',
								'float':'left',
								'height':'22px',
								'width':'2px',
								'border-bottom-width':'thin',
								'border-top-style':'none',
								'border-right-style':'none',
								'border-bottom-style':'solid',
								'border-left-style':'none',
								'border-bottom-color':'#56a7f8' }).insertAfter(this);
	});
	jQuery("#tabs-box").bind('tabsselect', function(event, ui){
		if (ui.panel.id == "gmap"){
			if (map == undefined) {
				showMap('mapaOkolicy');
				loadScript();
			}
		}
		if (ui.panel.id == "hotel-tourop"){
			initImages("#hotel-photo a");
		}
		if (ui.panel.id == "hotel"){
			initImages("#country-photo > a");	
		}
	});
	jQuery("#hotel-photo a, #country-photo > a, #country-photo > div > a").click(function(){
		showDialog(jQuery(this).attr("href"), 580, 750); return false;
		});
			
}


function reloadOffers(pageNumber){		
}


function initImages(imagesDiv){
	//alert(imagesDiv);
	jQuery(imagesDiv).each(function(id){
		if (jQuery(this).children().size() == 0) {
			//alert(imagesDiv);
			imgURL = jQuery(this).text();
			jQuery(this).html('<img src="' + imgURL + '" width="174"/>');
		}
	});
}

function showMap(nazwa){
	if(nazwa=='mapaOkolicy') {
		jQuery("#gmap").show();
    }
}

function hideMap(){
        jQuery("#gmap").hide();
	clearMarkers();
	removeGoogleMapsDynamic();
}

function mycarousel_itemLoadCallback(carousel, state)
{
    for (var i = carousel.first; i <= carousel.last; i++) {

    	if (carousel.has(i)) {
            continue;
        }
        if (i > mycarousel_itemList.length) {
            break;
        }
        //var preloadImg = new Image();
		newElem = carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i-1]));
        newElem.children().click(function(){
			newIndex = jQuery("ul#oferta-box-carousel li").index(jQuery(this).parent());
			newImg = mycarousel_itemList[newIndex];
			jQuery("#oferta-box-img-wrapper tr td img").hide();
			jQuery("#oferta-box-img-wrapper tr td").addClass("loading");
			
			var nImg = new Image();
			jQuery(nImg).load(function(){
				
				if (this.width > 300) {
					this.width = 300;
				}
				if (this.height > 200) {
					this.height = 200;
				}
				jQuery("#oferta-box-img-wrapper tr td").removeClass("loading");
				jQuery("#oferta-box-preview-navi:hidden").show();
				jQuery("#oferta-box-img-wrapper tr td img").replaceWith(this);
				jQuery(this).fadeIn("normal");
				
				jQuery("#oferta-box-preview img, #oferta-box-preview span").unbind("click");
				jQuery("#oferta-box-preview img, #oferta-box-preview span").click(function(){
					//url = window.location + '&slide=' + newImg.slide;
					//jQuery("#dialog:empty").append('<iframe width="750px" height="580px" frameborder="0" src/>');
					//jQuery("#dialog iframe").attr("src",newImg.slide);
					//jQuery("#dialog").dialog("open");
					showDialog(newImg.slide, 580, 750);
				});
			}).attr("src",newImg.ref);
			
			jQuery("#oferta-box-preview-navi1").html("Zdjęcie " + (newIndex + 1) + "/" + mycarousel_itemList.length);
		});
		
		if(i==1){
			newElem.children().click();	
		}
	}
};


function mycarousel_getItemHTML(item)
{
	return '<img src="' + item.url + '" width="75" height="50"/>';
};

function secure_reservation(){
			jQuery("#pokaz").click(function(){
				jQuery("#secure-rsv-pokaz").hide();
				jQuery("#secure-rsv-ukryj").show();
				jQuery("#secure-rsv-btn-pokaz").hide();
				jQuery("#secure-rsv-btn-ukryj").show();
				jQuery("#secure-rsv-full").slideDown("slow");
			});
			jQuery("#ukryj").click(function(){
				jQuery("#secure-rsv-full").slideUp("slow", function(){
					jQuery("#secure-rsv-ukryj").hide();
					jQuery("#secure-rsv-btn-ukryj").hide();
					jQuery("#secure-rsv-pokaz").show();
					jQuery("#secure-rsv-btn-pokaz").show();	
				});
				});
};

function parseISO8601(dateStringInRange) {
        var isoExp = /^\s*(\d{4})-(\d\d)-(\d\d)\s*$/, date = new Date(NaN), month, parts = isoExp
                        .exec(dateStringInRange);

        if (parts) {
                month = +parts[2];
                date.setFullYear(parts[1], month - 1, parts[3]);
                if (month != date.getMonth() + 1) {
                        date.setTime(NaN);
                }
        }
        return date;
}


