jQuery(document).ready(function(){
	ChangeList();
	
	var DateFrom = $('#datefrom');
	var DateTo = $('#dateto');
	
	if ($('#LCJ_flash').length > 0)  {
		var flashvars = {};
		var params = {};
		swfobject.embedSWF("/travel/images/LCJ_czarter-izrael_230x75.swf", "LCJ_flash", "230", "75", "8", "9.0.0", flashvars, params);
	}
	
	DateFrom.change(function(){
		if ((DateFrom.val() != '' && DateTo.val() == '') || (DateTo.val() < DateFrom.val())) {
			$.ajax({
				type: "GET",
				data: "date="+ DateFrom.val(),
				url : "/travel/includes/next_day.php",
				success : function (next_day) {
					DateTo.val(next_day);
				}
			});
		}
	});	
	
	function search_select(search_url, list_id) {
		var search_path_url = location.pathname.split('/');
		//var search = search_path_url.indexOf(search_url); -> nie dziala w IE
		var search = jQuery.inArray(search_url, search_path_url);
		search = ++search;
		var id_url = search_path_url[search];
		
		if (search_url == 'datefrom') {
			if (id_url != -1) {
				$('#datefrom').val(id_url);
			}
		} else if (search_url == 'dateto') {
			if (id_url != -1) {
				$('#dateto').val(id_url);
			}
		} else if (search_url == 'standard') {
			$('#List'+list_id+'_child').find("a:contains("+ id_url +")").addClass('selected');
			var napis = $('#List'+list_id+'_child a.selected .ddTitleText').text();
			$('#List'+list_id+'_titletext').text(napis);
		} else {
			/*
			$('#List'+list_id+' option[value=' + id_url +']').attr("select","selected");
			
			FillList("List1", "country");
			FillList("List2", "categories");
			*/
			$('#List'+list_id+'_child .'+ id_url).addClass('selected');
			var napis = $('#List'+list_id+'_child .'+ id_url +' .ddTitleText').text();
			$('#List'+list_id+'_titletext').text(napis);
		}
	}
	
	if ((location.href.indexOf("search.php") != -1 || location.href.indexOf("search3.php") != -1) && ((location.href.indexOf("top5") == -1) && (location.href.indexOf("lastminute") == -1) && (location.href.indexOf("specjalne") == -1) && (location.href.indexOf("nowosci") == -1))) {
		search_select('country', 1);
		search_select('categories', 2);
		search_select('wyjazd', 3);
		search_select('period', 4);
		search_select('datefrom', 0);
		search_select('dateto', 0);
		search_select('transport', 5);
		search_select('standard', 6);
		search_select('maintenance', 7);
	}
	if (location.href.indexOf("search2.php") != -1) {
		search_select('country', 1);
		$('.pagination .prev, .pagination .next').hide();
	}	
	if (location.href.indexOf("search3.php") != -1) {
		$('.pagination .prev, .pagination .next').hide();
	}	
		
	$('.pagination span.separator:last').remove();
	$('.pagination').removeClass('hide').addClass('show');
	
	if (location.href.indexOf("search.php") == -1) {
		$.scrollTo('#trips', 0);
	}
	else {
		$.scrollTo('#f1', 0);
	}
	
	jQuery('.totop').click(function () {
		scroll(0,0);
		return false;
	});
	$('a[rel$="external"]').click(function(){
		this.target = "_blank";
    });
	
	//jQuery("#tabs").tabs({fxFade: true,fxSpeed: 'fast'});
	
	jQuery("#tabs").tabs(
	{ 
		fxFade: true, 
		fxSpeed: 'fast', 
		onShow:function(event, ui) 
		{ 
			if(ui.id == "tabs-3")
			{
				google.maps.event.trigger(mapa, 'resize'); 
			}
		}
	});
	
	if ( jQuery.browser.opera ) {
		jQuery(".navigation").hrzAccordion({eventTrigger:"click",openOnLoad:"4",cycle: false,handlePositionArray: "left,left,left,left",fixedWidth:"761"});
	} else {
		jQuery(".navigation").hrzAccordion({eventTrigger:"click",openOnLoad:"4",cycle: false,handlePositionArray: "left,left,left,left"});
	}
	
	//ZMIANA OFERT W AKORDEONIE
	for(var z=0; z<4; z++) {
		jQuery("#navigationContent"+z+" .ContentImage").eq(0).addClass('selected');
		jQuery("#navigationContent"+z+" .navigationContent1").eq(0).addClass('selected');
		$("#navigationContent"+z+" ul.navigationContentPagination li.show_offer a").eq(0).addClass('active_offer');
	}
	// TOP OFERTY
	var licznik = 0;
	jQuery("#navigationContent0 .change_offer").click(function() {
		licznik++;
		var counter = $("#navigationContent0 ul.navigationContentPagination li.show_offer a").length;
		if (licznik >= counter) 
			licznik = 0; 
		
		$("#navigationContent0 ul.navigationContentPagination li.show_offer a").removeClass('active_offer');
		$("#navigationContent0 ul.navigationContentPagination li.show_offer a").eq(licznik).addClass('active_offer');
		
		$("#navigationContent0 .ContentImage").removeClass('selected'); 
		$("#navigationContent0 .ContentImage").eq(licznik).addClass('selected'); 
		
		$("#navigationContent0 .navigationContent1").removeClass('selected'); 
		$("#navigationContent0 .navigationContent1").eq(licznik).addClass('selected'); 
	});
	// END TOP OFERTY
	// LAST MINUTE
	var licznik = 0;
	jQuery("#navigationContent1 .change_offer").click(function() {
		licznik++;
		var counter = $("#navigationContent1 ul.navigationContentPagination li.show_offer a").length;
		if (licznik >= counter) 
			licznik = 0; 
		
		$("#navigationContent1 ul.navigationContentPagination li.show_offer a").removeClass('active_offer');
		$("#navigationContent1 ul.navigationContentPagination li.show_offer a").eq(licznik).addClass('active_offer');
		
		$("#navigationContent1 .ContentImage").removeClass('selected'); 
		$("#navigationContent1 .ContentImage").eq(licznik).addClass('selected'); 
		
		$("#navigationContent1 .navigationContent1").removeClass('selected'); 
		$("#navigationContent1 .navigationContent1").eq(licznik).addClass('selected'); 
	});
	// END LAST MINUTE
	// OFERTA SPECJALNA
	var licznik = 0;
	jQuery("#navigationContent2 .change_offer").click(function() {
		licznik++;
		var counter = $("#navigationContent2 ul.navigationContentPagination li.show_offer a").length;
		if (licznik >= counter) 
			licznik = 0; 
		
		$("#navigationContent2 ul.navigationContentPagination li.show_offer a").removeClass('active_offer');
		$("#navigationContent2 ul.navigationContentPagination li.show_offer a").eq(licznik).addClass('active_offer');
		
		$("#navigationContent2 .ContentImage").removeClass('selected'); 
		$("#navigationContent2 .ContentImage").eq(licznik).addClass('selected'); 
		
		$("#navigationContent2 .navigationContent1").removeClass('selected'); 
		$("#navigationContent2 .navigationContent1").eq(licznik).addClass('selected'); 
	});
	// END OFERTA SPECJALNA
	// NOWOSCI
	var licznik = 0;
	jQuery("#navigationContent3 .change_offer").click(function() {
		licznik++;
		var counter = $("#navigationContent3 ul.navigationContentPagination li.show_offer a").length;
		if (licznik >= counter) 
			licznik = 0; 
		
		$("#navigationContent3 ul.navigationContentPagination li.show_offer a").removeClass('active_offer');
		$("#navigationContent3 ul.navigationContentPagination li.show_offer a").eq(licznik).addClass('active_offer');
		
		$("#navigationContent3 .ContentImage").removeClass('selected'); 
		$("#navigationContent3 .ContentImage").eq(licznik).addClass('selected'); 
		
		$("#navigationContent3 .navigationContent1").removeClass('selected'); 
		$("#navigationContent3 .navigationContent1").eq(licznik).addClass('selected'); 
	});
	// END NOWOSCI
	
	jQuery('#newsletter h3 a').click(function () {
		if (jQuery(this).hasClass('visible')) {
			jQuery(this).parents('#newsletter').animate({ top: '64px'}, 200);
			jQuery(this).removeClass('visible');
		} else {
			jQuery(this).parents('#newsletter').animate({ top: '18px'}, 200);
			jQuery(this).addClass('visible');
		}
		return false;
	});
	jQuery('#search_toggle .show').click(function () {
		jQuery(this).parents('#search-advanced').animate({ height: '120px'}, 200);
		jQuery(this).hide();
		jQuery('#search_toggle .hide2').show();
		jQuery(this).parents('.search').addClass('search-advanced');
		jQuery('#search-advanced p').css({'left':'0px','position':'relative'});
		jQuery('#search-submit .btn_show').hide();
		jQuery('#search-submit').css('bottom', '41px');
		jQuery('#search-submit .btn_hide').show();
		return false;
	});
	jQuery('#search_toggle .hide2').click(function () {
		jQuery(this).parents('#search-advanced').animate({ height: '46px'}, 200);
		jQuery(this).hide();
		jQuery('#search_toggle .show').show();
		jQuery(this).parents('.search').removeClass('search-advanced');
		jQuery('#search-advanced p').css({'left':'-9999px','position':'absolute'});
		jQuery('#search-submit .btn_show').show();
		jQuery('#search-submit').css('bottom', '101px');
		jQuery('#search-submit .btn_hide').hide();
		return false;
	});
	jQuery(function() {
		$("#datefrom, #dateto").datepicker({
			showOn: 'button',
			buttonImage: '/travel/images/calendar.gif'
		});
	});
	//jQuery('input[type="radio"], input[type="checkbox"]').checkBox();
	//jQuery('input[type="radio"], input[type="checkbox"]').hide();
	//jQuery('input[type="radio"], input[type="checkbox"]').parents('p').css('position','relative');
	//jQuery('select').msDropDown();
	
	if ( jQuery.browser.msie ) {
		jQuery('.search button').css('margin','0 0 -1px 0');
		jQuery('.dd').css({'width':'104px'});
		jQuery('.search .fr .text').css({'margin-right':'-1px'});
		if (jQuery.browser.version == '6.0') {
			jQuery('.dd').css({'width':'103px'});
		}
		if (jQuery.browser.version == '7.0') {
			jQuery('#find-on-map').after('<div class="clear" />');
		}
	} 	
	if ( /chrome/.test( navigator.userAgent.toLowerCase() ) ) {
		jQuery('.search button').css({'width':'21px', 'margin':'-1px 0 0'});
	} 	
	if ( /safari/.test( navigator.userAgent.toLowerCase() ) ) {
		jQuery('.search button').css({'width':'21px', 'margin':'-1px 0 0'});
		jQuery('.dd').css({'width':'104px'});
	} 
	if ( jQuery.browser.opera ) {
		jQuery('.search button').css({'margin':'0'});
		jQuery('.dd').css({'width':'104px'});
	}
	
	$("#wybierz_oferte tbody tr:even").addClass("even");
	$("#wybierz_oferte tbody tr:odd").addClass("odd");
	
	jQuery('.current_gallery a img').each(function () {
	//	jQuery(this).css({'margin-top':parseInt((272-jQuery(this).height())/2),'margin-left':parseInt((272-jQuery(this).width())/2)});
	//	jQuery(this).css({'margin-top':parseInt((272-jQuery(this).height())/2)});
	//	jQuery(this).css({'margin-left':parseInt((272-jQuery(this).width())/2)});
	});
	jQuery('.current_gallery').before('<ul class="current_gallery_nav">').cycle({ 
		fx:     'fade', 
		speed:   300, 
		timeout: 3000,
		pager:  '.current_gallery_nav', 
		pagerAnchorBuilder: function(idx, slide) {
			var src = $('img',slide).attr('src');
			return '<li><a href="#" title=""><img src="' + src + '" width="34" height="34" /></a></li>'; 
		}
	});
	if (jQuery('.current_gallery_nav li').length < 9) jQuery('.nav').hide();
	$('#szczegoly-oferty .current_gallery a').lightBox();
	
	$('#cms_gallery .foto a').lightBox();
	jQuery('#cms_gallery .foto').cycle({
		fx:     'fade',
		speed:  300, 
		timeout: 0,
		prev:   '#cms_gallery .prev', 
		next:   '#cms_gallery .next'
	});
	
	var $paneTarget = $('.current_gallery_nav');
	$('#prev').click(function(){				
		$paneTarget.stop().scrollTo('-=34px', { speed: 1500, axis: 'y' });
	});
	$('#next').click(function(){				
		$paneTarget.stop().scrollTo('+=34px', { speed: 1500, axis: 'y' });
	});
	
	$('#mapa').flash({ swf: 'mapakonsorcjum.swf', height: 327, width: 665, wmode: 'transparent' });
});

function kontynent(id) {
	$('#find-countries').load('./ajax/mapa.php?kontynent='+id);
}

$(function () {
	var defaults = {
		key: "id",
		value: "label",
		data: {}
	};
	var cat = $('#categorySelect');
	var el = $('#elementSelect');
	var attr = $('#attributeSelect');
	
	el.selectChain({
		target: attr,
		url: 'ajax/city.php',
		data: { ajax: true, anotherval: "anotherAction" }            
	});
	cat.selectChain({
		target: el,
		url: 'ajax/region.php',
		data: { ajax: true }
	}).trigger('change');
	
	cat.change(function () {
        $("#categorySelect option:selected").each(function () {
            var country_guide = $(this).val();
			$("#id_co").val(country_guide);
        });
	});
	el.change(function () {
        $("#elementSelect option:selected").each(function () {
            var region_guide = $(this).val();
			$("#id_r").val(region_guide);
        });
	});
	attr.change(function () {
        $("#attributeSelect option:selected").each(function () {
            var city_guide = $(this).val();
			$("#id_ci").val(city_guide);
        });
	});
});

function show_describe_krm () {
	var id_co = $('#id_co').val();
	var id_r = $('#id_r').val();
	var id_ci = $('#id_ci').val();
	
	$('#opis_ajax').load("./ajax/opis_krm.php?opis_country="+id_co+"&opis_region="+id_r+"&opis_city="+id_ci);
}

function FillList(Id, TableName)
{
	if(document.getElementById(Id)){
		var TabIdName = document.getElementById(Id);
		var Response = ajax('/travel/service.php?TableName=' + TableName);
		var Tab = Response.split('|');
		TabIdName.length = Tab.length;
		for(i=0; i<Tab.length; i++)
		{
			var Tab1 = Tab[i].split('#');
			TabIdName.options[i].value = Tab1[0].replace(/^\s+|\s+$/g, '');
			TabIdName.options[i].text = Tab1[1];
		}
	}
}

function ChangeList()
{
	if($('#List1')){
		//$('ul.selectReplacement').remove();
		FillList("List5", "transport");
		FillList("List1", "country");
		FillList("List2", "categories");
		FillList("List3", "wyjazd");
		FillList("List4", "period");
		FillList("List6", "standard");
		FillList("List7", "maintenance");
		jQuery('#sidebar .search select').msDropDown();
		//setForm();
		//setForm2();
	}
}

// <![CDATA[
/*
function selectReplacement(n, obj) {
  obj.className += ' replaced';
  var ul = document.createElement('ul');
  ul.className = 'selectReplacement';
  if (n==0) {
	ul.onclick = function () {
		if (jQuery(this).hasClass('over')) {
			jQuery(this).removeClass('over');
		} else {
			jQuery(this).addClass('over');
		};
	};
  }
  var opts = obj.options;
  var selectedOpt = (!obj.selectedIndex) ? 0 : obj.selectedIndex;
  for (var i=0; i<opts.length; i++) {
	var li = document.createElement('li');
	var txt = document.createTextNode(opts[i].text);
	li.appendChild(txt);
	li.selIndex = i;
	li.selectID = obj.id;
	li.onclick = function() {
	  selectMe(this);
	  ChangeList();
	};
	if (i == selectedOpt) {
	  li.className = 'selected';
	  li.onclick = function() {
		this.parentNode.className += ' selectOpen';
		this.onclick = function() {
		  selectMe(this);

		};
	  };
	}
	if (window.attachEvent) {
	  li.onmouseover = function() {
		this.className += ' hover';
	  };
	  li.onmouseout = function() {
		this.className = 
		  this.className.replace(new RegExp(" hover\\b"), '');
	  };
	}
	ul.appendChild(li);
  }
  obj.parentNode.insertBefore(ul,obj);
}
function selectMe(obj) {
  var lis = obj.parentNode.getElementsByTagName('li');
  for (var i=0; i<lis.length; i++) {
	if (lis[i] != obj) {
	  lis[i].className='';
	  lis[i].onclick = function() {
		selectMe(this);
	  };
   } else {
	  setVal(obj.selectID, obj.selIndex);
	  obj.className='selected';
	  obj.parentNode.className = 
		obj.parentNode.className.replace(new RegExp(" selectOpen\\b"), '');
	  obj.onclick = function() {
		obj.parentNode.className += ' selectOpen';
		this.onclick = function() {
		  selectMe(this);
		};
	  };
	}
  }
}
function setVal(objID,val) {
  var obj = document.getElementById(objID);
  obj.selectedIndex = val;
}
function setForm() {
  //var s = document.getElementsByTagName('select');
  var s = $('select.NiceOne');
  for (var i=0; i<s.length; i++) {
	selectReplacement(i, s[i]);
  }
}


function selectReplacement2(n, obj) {
  obj.className += ' replaced';
  var ul = document.createElement('ul');
  ul.className = 'selectReplacement';
  
  var opts = obj.options;
  var selectedOpt = (!obj.selectedIndex) ? 0 : obj.selectedIndex;
  for (var i=0; i<opts.length; i++) {
	var li = document.createElement('li');
	var txt = document.createTextNode(opts[i].text);
	li.appendChild(txt);
	li.selIndex = i;
	li.selectID = obj.id;
	li.onclick = function() {
	  selectMe(this);
	};
	if (i == selectedOpt) {
	  li.className = 'selected';
	  li.onclick = function() {
		this.parentNode.className += ' selectOpen';
		this.onclick = function() {
		  selectMe(this);

		};
	  };
	}
	if (window.attachEvent) {
	  li.onmouseover = function() {
		this.className += ' hover';
	  };
	  li.onmouseout = function() {
		this.className = 
		  this.className.replace(new RegExp(" hover\\b"), '');
	  };
	}
	ul.appendChild(li);
  }
  obj.parentNode.insertBefore(ul,obj);
}

function setForm2() {
  //var s = document.getElementsByTagName('select');
  var s = $('select.NiceOne2');
  for (var i=0; i<s.length; i++) {
	selectReplacement2(i, s[i]);
  }
}
// ]]>
*/
