$(document).ready(function() {
		
	//hotelInfoext gallery tabs
	$('div#thumb-navigation img').each(function() {
		var thisImgLink = $(this).attr('src');
		$(this).click(function() {
			$('div.stack div.hotelTab a img').attr('src' , thisImgLink.replace('/prev',''));
			$('div.stack div.hotelTab a').attr('href' , thisImgLink.replace('/prev',''));
		})
	})
	
	//searchPrice Tabs
	$('ul.radioPrice li:first').addClass('radioP_Active')
	$('div.sideBarBoxIn form:first').show();
	$('ul.radioPrice li').click(function() {
		$('ul.radioPrice li').removeClass('radioP_Active')		
		$('div.sideBarBoxIn form').hide();
		if ($(this).hasClass('radionofesh')) {
			$('div.sideBarBoxIn form.radionofesh').show();
			$('ul.radioPrice li.radionofesh').addClass('radioP_Active')
		}
		else if ($(this).hasClass('radiocharters')) {
			$('div.sideBarBoxIn form.radiocharters').show();
			$('ul.radioPrice li.radiocharters').addClass('radioP_Active')
		}
	});
	
	$('select.SelectBox').val('AMS');
	
$_GET = {};
	document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
	function decode(s) {
	    return decodeURIComponent(unescape(s).split("+").join(" "));
	}
	$_GET[decode(arguments[1])] = decode(arguments[2]);
	});
	function select_city(tab, value) {
		$(tab).find('select[name="searchCityFrom"]:eq(0)').val(value);
	}	
	
	function select_tab() {
		var mode = $_GET["mode"];
		var city = $_GET["searchCityFrom"];
		var destination_name = $_GET["destination_name"];
		$("#searchCityFrom_charter, #searchCityFrom_nofshons, #searchCityFrom_hotel, #searchCityFrom_rentcar , #searchCityFrom_domflight , #searchCityFrom_domhotel , #searchCityFrom_domflight , #searchCityFrom_dompackage").val(city);
		
		if (mode == "searchit") {
//			$('#searchCityFrom_schedule').val(city);
//			$('#searchCityFrom_value').val(city);
//			$('#searchCityFrom_schedule').val(destination_name);
		}
		
		if (mode == "newsearch") {
			$('ul.maintabs li a').removeClass('active');
			$('#wrapper-inner div.tab').hide();
			var dealtype = $_GET["dealtype"];		
			if (dealtype == "TOURS") {
				$('ul.maintabs li a:eq(4)').addClass('active');			    
				$("#tours").show();
				$('#searchCityFrom_tours').val(city);
			}
			if (dealtype == "NOFSHON") {
				$('ul.maintabs li a:eq(1)').addClass('active');
				$("#nofshons").show();
				$('#searchCityFrom_nofshons').val(city);
			}
			if (dealtype == "HOTEL") {
				$('ul.maintabs li a:eq(2)').addClass('active');
				$("#hotel").show();
				$('#searchCityFrom_hotel').val(city);
			}
			if (dealtype == "RENTACAR") {
				$('ul.maintabs li a:eq(3)').addClass('active');
				$("#rentcar").show();
				$('#searchCityFrom_rentcar').val(city);
			}
			if (dealtype == "DOMESTIC") {
				$('ul.maintabs li a:eq(5)').addClass('active');
				$("#israel").show();
			}			
			if (dealtype == "CHARTER") {
				$('ul.maintabs li a:eq(0)').addClass('active');
				$("#flights").show().children('div.subtab').hide();
				$('#flights ul.flights li').children('a').removeClass('active');
				$('#flights ul.flights li:eq(1)').children('a').addClass('active');
				$("#flights").children('#charters').show();
				$('#searchCityFrom_charter').val(city);
			}
		}
		
		var slg = $_GET["slg"];
		if (mode == "package" && (slg=="domestic" || slg=="nofshon" || slg=="tour" || slg=="charter")) {
			$('ul.maintabs li a').removeClass('active');
			$('#wrapper-inner div.tab').hide();
			
			if (slg == "domestic") {
			    $('ul.maintabs li a:eq(5)').addClass('active');
			    $("#israel").show();
			    $('#dealtype').val('DOMESTIC');
			    $('#searchCityFrom').val('ETH');
			}
			if (slg == "nofshon") {
			    $('ul.maintabs li a:eq(1)').addClass('active');
			    $("#nofshons").show();
			    $('#dealtype').val('NOFSHON');
			    $('#searchCityFrom').val($('#searchCityFrom_nofshons').val());
			}
			if (slg == "tour") {
			    $('ul.maintabs li a:eq(4)').addClass('active');			    
			    $("#tours").show();
			    $('#dealtype').val('TOURS');
			    $('#searchCityFrom').val($('#searchCityFrom_tours').val());
			}
			if (slg == "charter") {
			    	$('ul.maintabs li a:eq(0)').addClass('active');
				$("#flights").show().children('div.subtab').hide();
				$('#flights ul.flights li').children('a').removeClass('active');
				$('#flights ul.flights li:eq(1)').children('a').addClass('active');
				$("#flights").children('#charters').show();
			}				
		}
		
		if (mode == "hotelscategories") {
			$('ul.maintabs li a').removeClass('active');
			$('#wrapper-inner div.tab').hide();		    
			$('ul.maintabs li a:eq(2)').addClass('active');
			$("#hotel").show();
			$('#dealtype').val('HOTEL');
			$('#searchCityFrom').val($('#searchCityFrom_hotel').val());
		}
	}
	select_tab();

	$('.getMoreDest').click(function() {
		if($('.togDate3').css("display") == "none") $('.getMoreDest').text("הורד נתיב");
		else $('.getMoreDest').text("הוסף נתיב");
	    $('.togDate3').slideToggle();
	});
    
	$("#searchCity_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#searchCity_value").val(item[2]); })
	$("#searchCityFrom_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#searchCityFrom_value").val(item[2]); })
	$("#from2_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#from2_value").val(item[2]); })
	$("#to2_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#to2_value").val(item[2]); })
	$("#from3_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#from3_value").val(item[2]); })
	$("#to3_schedule").autocomplete("/cities.php",{ mustMatch:false, minChars:3, matchSubset:1, cacheLength:10, autoFill:true, selectFirst:true, selectOnly:true, formatItem:formatItem, width:330, scroll:false, scrollHeight:220 }).result(function(event,item) { $("#to3_value").val(item[2]); })

	$("#searchCityFrom_schedule, #from2_schedule, #to2_schedule, #from3_schedule, #to3_schedule").css("color", ($(this).val()=='שדה תעופה או עיר (בעברית)' ? "silver" : "black") );
	$("#searchCityFrom_schedule, #from2_schedule, #to2_schedule, #from3_schedule, #to3_schedule").focus(function() { if ($(this).val()=='שדה תעופה או עיר (בעברית)') $(this).val("").css("color", "black"); });
	$("#searchCityFrom_schedule, #from2_schedule, #to2_schedule, #from3_schedule, #to3_schedule").blur(function() { if ($(this).val()=='') $(this).val("שדה תעופה או עיר (בעברית)").css("color", "silver"); });
});

function formatItem(row) {
	return '<table border="0" width="300" cellpadding="0" cellspacing="0"><tr><td width="130">' + row[0] + '</td><td width="130" align="left">' + row[1] + '</td><td width="40" align="left">' + row[2] + '</td></tr></table>';
}

function addBookmark(title, url) {	
	 if( document.all ) { //MSIE
		window.external.AddFavorite(url, title);
	} else {
		window.sidebar.addPanel(title, url,"");
	}
}


