//jQuery.noConflict();	
var loading_flag = false;	
var booking_url = false;

jQuery(document).ready(
	function(){
		//	var is_fav = jQuery.cookie('hotel');
		//	if(is_fav!="1")
		//		jQuery(".csc-subheader").after("<a class=\"add_to_fav\" href=\"#\">Добавить в избранные отели</a>");
		//	else
		//		jQuery(".csc-subheader").after("<a class=\"add_to_fav\" href=\"#\">Убрать из избранного</a>");
		//	
		//	jQuery(".add_to_fav").click(function(event){
		//		event.preventDefault();
		//		if(is_fav=="1")
		//			jQuery.cookie('hotel','0');
		//		else
		//			jQuery.cookie('hotel','1');
		//	});
		//



		if(jQuery("#price").length){
			var min_price = 10000000;
			jQuery(".row_price .price").each(function(index, value){
				if(value.innerText)
					var value_num = Number(value.innerText);
				else
					var value_num = 10000000;
				if(value_num == 0 )
					alert("t");
				if(value_num < min_price){
					min_price = value_num;
				}
			});
			if(min_price!=10000000)
				var price_from = 'Цены от <span class="price">'+min_price+'</span> €';
			else 
				var price_from = 'Просмотреть цены';
			jQuery("h1.csc-subheader-0").after('<p class="toPrice" class="result8419275" onmouseover = "this.style.backgroundImage = \'/typo3conf/ext/site_nw/Resources/Public/Images/price_down.png\'" onmouseout =  "this.style.backgroundImage = \'/typo3conf/ext/site_nw/Resources/Public/Images/price_up.png\'" style="background:url(\'/typo3conf/ext/site_nw/Resources/Public/Images/price_up.png\') no-repeat; text-align:center; width:220px; height:33px; padding-top:3px;"><a style="color:white;" href="'+window.location.protocol + "//" + window.location.host+window.location.pathname+'#price">'+price_from+'</a></p>');
		
		}
	
		
		

		if (screen.width>=1210) {
			jQuery("body").css('width','1262px');
			jQuery(".menu_right").css('left','1020px');
		} else if (screen.width>=1010) { 
			jQuery("body").css('width','1007px');
			jQuery(".menu_right").css('left','764px');
		}
		jQuery(".menu_top_ctrs li").slice(0,5).css('font-weight','bold');
		jQuery(".csc-textpic-imagewrap").ceebox({
			borderColor:'#517a8c',
			boxColor:"#fff",
			html:false,
			image:true,
			video:false,
			modal:false
		});
		jQuery("table.table-header").after('<div class="legend"><img style="vertical-align:middle;padding-right:5px;" src="/typo3conf/ext/mvc_tours/legend_icon.png" alt="Справочник"/> <a class="ceebox" href="/legend.html" title="Справочник туристических обозначений">Справочник туристических обозначений</a></div>');
		jQuery(".ceebox").ceebox({
			htmlWidth:980,
			borderWidth:"0px",
			borderColor:'#fff',
			boxColor:"#fff",
			html:true,
			image:false,
			video:false,
			modal:false
		});
	

		//jQuery("strong").parent().addClass('collapse_closed').before("<a style='display:block' class='sh'>(+/-)</a>");
	
		/* 	jQuery(".collapse_open").parent().prepend("<a class='sh_open'>(+/-)</a>");
	jQuery(".sh_open").click(function(){
		jQuery(this).next().slideToggle("slow");
	});
	
	jQuery(".collapse_closed").hide();
	jQuery(".collapse_closed").parent().prepend("<a class='sh_closed'>(+/-)</a>");
	jQuery(".sh_closed").click(function(){
		jQuery(this).next().slideToggle("slow");
	}); */
	
		// jQuery(".subSectionAndTours").each(
		// function(index){
		//	jQuery(this).appendTo(jQuery(".subSectionAndToursContainer").eq(index/4));
		// }
		// );
	

		jQuery(".sectionLink").click(function(){
			var id = jQuery(this).attr("id");
			if(loading_flag)
				window.location.hash = id.substring(1);
			///////////////////
			var id = "#i"+jQuery(this).attr("id");
			var selected = jQuery(this).hasClass("selected");
			jQuery(".subSectionAndTours").slideUp("slow",function(){
				clear_children();
			});
			if(!selected){
				jQuery(this).parents("ul.section").next().find(id).slideDown("slow",function(){
					clear_children();
				});
			}
		
			jQuery(".sectionLink").removeClass("notSelected");
		
			jQuery(this).not(".selected").addClass("notSelected");
			jQuery(".sectionLink").removeClass("selected");
			jQuery(this).filter(".notSelected").addClass("selected");
		
		}
		);
		jQuery(".subSectionLink").click(function(){
			var id = jQuery(this).attr("id");
			window.location.hash = id;
		
		}
		);
	
		jQuery(".section p").click(function(){
			jQuery(".section p").removeClass("selected");
			jQuery(this).addClass("selected");
		//tb_init('a.thickbox, area.thickbox, input.thickbox');
		});


		jQuery("table.table-header tr:first-child td").each(function() {
			var col = jQuery(this).attr("colspan");
			if (col) {
				colspan=' colspan="'+col+'"';
			}else{
				colspan='';
			}
			var row = jQuery(this).attr("rowspan");
			if (row) {
				rowspan=' rowspan="'+row+'"';
			}else{
				rowspan='';
			}
			//alert(colspan);
			jQuery(this).replaceWith("<th" + colspan + rowspan + ">" + jQuery(this).html() + "</th>");

		});
		jQuery("table.table-header tr:first-child th")
		// jQuery("table.table-header tr td:first-child").each(function() {
		// jQuery(this).replaceWith("<th>" + jQuery(this).text() + "</th>");
		// });
		jQuery("table.table-header tr:first-child th").addClass("topHeader");
		//jQuery("table.table-header tr th:first-child").addClass("leftHeader");
		//jQuery("table.table-header th:first").addClass("empty");

	
		/*var htmlStr = jQuery(".maintext").html();
	jQuery(".maintext").html(htmlStr.substring(0,1000)).append("<a class='readon'>Читать далее</a>");
	

	jQuery(".readon").toggle(
	  function(){
	  jQuery(".maintext").html(htmlStr).append("<a class='readon'>Меньше текста</a>");
	  },
	  function(){
      jQuery(".maintext").html(htmlStr.substring(0,1000)).append("<a class='readon'>Читать далее</a>");
	  }
	);
	  */
	  if(window.location.hash){
		  var hash = window.location.hash.substring(1);
		  hashs = hash.split('/');
		  jQuery("#d"+hashs['0']).trigger('click');
		  tx_mvctoursajaxGetToursAction(hashs['1'],hashs['0'],true);
	  }
	  loading_flag = true;
		clear_children();
	}
	);


