$(function(){

	$('#inStockBlock').hover(function(){
		$('#inStockPrev').animate({'margin-top':'-6px'},150);
		$('#inStockNext').animate({'margin-bottom':'-6px'},150,function(){
			$('#inStockPrev').animate({'margin-top':'0'},150);
			$('#inStockNext').animate({'margin-bottom':'0'},150);
		});
	},function(){
	});
	
	$('.accordion').accordion({
		header:'dt',
		autoHeight: false
	});
	$('#types').tabs({
		event:'mouseover'
	});
	$('#hotel_info,#resort_info,.tabs').tabs();
	if($.browser.msie){
		$('#submenu > ul').wrap('<div class="con" />');
		$('#submenu,#left').prepend('<div class="top-rounded"><div class="tl"></div><div class="tr"></div></div>');
		$('#submenu').append('<div class="bot-rounded"><div class="bl"></div><div class="br"></div></div>');
	}
	$('#left table tr:nth-child(odd)').addClass('nth');
	$('#left table.vnth td:odd').addClass('vnth');
	
	function weather(cityId,cityName){
		t = $('#weather ul');
		var className = '',output = '';
		$.get('/assets/templates/vizavi/proxy.php',	{id : cityId}, function(data){
			i = $(data).find('img').attr('title');
			switch(i){
				case 'Ясно':							className = 'w01';		break;
				case 'Малооблачно':						className = 'w02';		break;
				case 'Облачно':							className = 'w03';		break;
				case 'Пасмурно':						className = 'w04';		break;
				case 'Переменная облачность, дождь':	className = 'w05';		break;
				case 'Пасмурно, дождь':					className = 'w06';		break;
				case 'Переменная облачность, снег':		className = 'w07';		break;
				case 'Пасмурно, снег':					className = 'w08';		break;
				case 'Гроза':							className = 'w09';
			}
			output += '<li>';
			output += '<img width="50" height="50" src="/assets/snippets/weather/i/blank.gif" title="'+i+'" alt="'+i+'" class="'+className+'">';
			output += '<span class="w">'+cityName+':<span>'+$(data).find('#tgmtdtext20').text()+'</span><i class="clear"></i></span>';
			output += '</li>';
			t.append(output);
			$('#weather .load').remove();
			if($('li',t).length >= 2){
				$('#weather ul,#currency ul').innerfade({speed: 750, timeout: 5000, containerheight: '60px'});
			}
		});
	}
	
	switch($('body').attr('id')){
		case 'czech':
			weather('2952','Прага');
			weather('2948','Карловы Вары');
			break;
		case 'slovensko':
			weather('2974','Братислава');
			weather('3000','Кошице');
			break;
		case 'hungary':
			weather('3227','Будапешт');
			weather('3225','Хевиз');
	}
	
	$('#special_slider ul').innerfade({speed: 750, timeout: 5000, containerheight: '15px'});
	if($('#hot-czech ul li').length > 0){
		$('#hot-czech').show();
		$('#hot-czech ul').innerfade({speed: 350, timeout: 2500, containerheight: '65px'});
	}
	if($('#hot-slovensko ul li').length > 0){
		$('#hot-slovensko').show();
		$('#hot-slovensko ul').innerfade({speed: 350, timeout: 2500, containerheight: '65px'});
	}
	if($('#hot-hungary ul li').length > 0){
		$('#hot-hungary').show();
		$('#hot-hungary ul').innerfade({speed: 350, timeout: 2500, containerheight: '65px'});
	}
	
	var $type = 'all';
	var $raiting = 'all';
	var $prait;
	
	$('#sort_hotel_type a').click(function(){
		
		$('#sort_hotel_type a.active').removeClass('active');
		$(this).addClass('active');
			
		$type = $(this).attr('id');
		showRait($type,$raiting);
			
	});
	
	$sh = false;
	
	$('#sort_hotel_raiting img').hover(function(){
	
		$prait = $(this).parent().attr('class');
		$(this).parent().removeClass().addClass('show_'+$(this).attr('id'));
		$sh = true;
		
	}, function(){
	
		$(this).parent().removeClass().addClass($prait);
		$sh = false;
		
	});
	
	$('#sort_hotel_raiting img').click(function(){
	
		$raiting = $(this).attr('id');
	
		$prait = 'show_'+$raiting;
		$(this).parent().removeClass().addClass($prait);
	
		showRait($type,$raiting);
		
		document.location.hash = '#show_'+$raiting;
		
		$('#sort_hotel_raiting_wrap span').html('<a id="resetRait">Показать все</a>');
		$('#resetRait').click(function(){
			$raiting = 'all';
			$('#sort_hotel_raiting_wrap span').html('Выберите категорию:');
			showRait($type,$raiting);
			$('#sort_hotel_raiting').removeClass();
			document.location.hash = null;
		});
		
		return false;
		
	});
	
	function showRait($hotel_type,$rait){
	
		$('.hotel_block').hide();
	
		if($hotel_type != 'all' && $rait != 'all'){
			
			$('.hotel_block[class~="'+$rait+'"][class~="'+$hotel_type+'"]').show();
			
		} else if($hotel_type == 'all' && $rait != 'all') {
		
			$('.hotel_block[class~="'+$rait+'"]').show();
			
		} else if($rait == 'all' && $hotel_type != 'all'){
		
			$('.hotel_block[class~="'+$hotel_type+'"]').show();
		
		} else {
		
			$('.hotel_block').show();
			
		}
		
	}
	
	$('p.tnav a:first').addClass('activeTab');
	$('div.stab:not('+$("p.tnav a:first").attr("href")+')').hide();
	$('p.tnav a').click(function(){
		if($(this).attr('class') != 'activeTab'){
			$('p.tnav a.activeTab').removeClass();
			$(this).addClass('activeTab');
			$($(this).attr('href')).show();
			$('div.stab:not('+$(this).attr('href')+')').hide();
		}
		return false;
	});
	
	if(document.location.hash != '') {
		$raiting = document.location.hash.replace('#show_', '');
		if($sh == false){
			$('#sort_hotel_raiting').removeClass().addClass('show_'+$raiting);
		}
		showRait($type,$raiting);
		$('#sort_hotel_raiting_wrap span').html('<a id="resetRait">Показать все</a>');
		$('#resetRait').click(function(){
			$raiting = 'all';
			$('#sort_hotel_raiting_wrap span').html('Выберите категорию:');
			showRait($type,$raiting);
			$('#sort_hotel_raiting').removeClass();
			document.location.hash = null;
		});
	}
	
	if($('.type2').length < 1) {
		$('#type2').hide();
	}
	
	/*$('#checkin_field,#checkout_field').datepicker();*/
	
	$('#transport_field_s').change(function(){
		$val = $(this).val();
		if($val == 'Другой'){
			$('#transport_field').show().focus().val('');
		} else {
			$('#transport_field').hide().val($(this).val());
		}
	});
	
	$('input[name=eattype]').change(function(){
		$val = $(this).val();
		if($val == 'другое'){
			$('#eattype_field').show().focus().val('');
		} else {
			$('#eattype_field').hide().val($val);
		}
	});
	
	var $q = $('#q');
	
	if($.cookie('showBtn') != 'hide'){
		getWait();
		$.cookie('showBtn', 'hide');
	}
	if($.cookie('showBtn') == 'hide' && $('html').attr('class') == 'mainpage'){
		setTimeout(getWait,20000);
	}
	
	function getWait(){
		$q.animate({'width':'202px'},500,function(){
			setTimeout(function(){
				$q.animate({'width':'42px'},500);
				if($('html').attr('class') == 'mainpage'){
					setTimeout(getWait,20000);
				}
			}, 5000);
		});
	}
	
	$q.hover(function(){
		$(this).stop(true,false);
		$(this).animate({'width':'202px'},500);
	}, function(){
		$(this).stop(true,false);
		$(this).animate({'width':'42px'},500);
	});
	
	$('.price-block .tours').hide();
	$('.price-block h3 a').toggle(function(){
		$(this).parent().next().show();
		$(this).addClass('active');
	}, function(){
		$(this).parent().next().hide();
		$(this).removeClass('active');
	});
	
	$('.price-block2.tours').hide();
	$('.price-block2 h3 a').toggle(function(){
		$(this).parent().next().show();
		$(this).addClass('active');
	}, function(){
		$(this).parent().next().hide();
		$(this).removeClass('active');
	});

	
	Shadowbox.init({},function(){
		Shadowbox.setup('a[rel=shadowbox]');
		Shadowbox.setup('.gallery_big', {
			gallery:        'Gallery',
			continuous:     true,
			counterType:    'skip'
		});
	});
	
	if($('#resort_photo #tmbs_gallery li').length > 3){
		$('#resort_photo .next,#resort_photo .prev').show();
		$('#resort_photo #tmbs_gallery').jCarouselLite({
			btnNext: 	'.next',
			btnPrev: 	'.prev',
			circular:	false
		});
	}
	
	if($('#hotel_photo #tmbs_gallery li').length > 3){
		$('#hotel_photo .next,#hotel_photo .prev').show();
		$('#hotel_photo #tmbs_gallery').jCarouselLite({
			btnNext: 	'.next',
			btnPrev: 	'.prev',
			vertical:	true,
			circular:	false
		});
	}
	
	$('#inStockContent .instock_block:last').addClass('last');
	$('#inStockContent .instock_block:first').addClass('first');
	$('#inStockNext').click(function(){
		old = $('#inStockContent .instock_block.active');
		old.removeClass('active');
		if(old.is('.last')){
			$('#inStockContent .instock_block.first').addClass('active');
		} else {
			old.next().addClass('active');
		}
		return false;
	});
	$('#inStockPrev').click(function(){
		old = $('#inStockContent .instock_block.active');
		old.removeClass('active');
		if(old.is('.first')){
			$('#inStockContent .instock_block.last').addClass('active');
		} else {
			old.prev().addClass('active');
		}
		return false;
	});
	
});
