function openW(url,w,h,s){
	var l=Math.floor((screen.width-w)/2);
	var t=Math.floor((screen.height-h)/2);
	window.open(url,'','width='+w+',height='+h+',top='+t+',left='+l+',status=No,scrollbars='+s);
}

function showImg(img){
	openW(img,640,600,'No');
	return false;
}

function showFeatures(ids){
	ar=ids.split(', ');
	for(i=0;i<ar.length;i++){
		document.write('<img src="'+fes[ar[i]].img+'" width="24" height="24" onmouseover="shint(\''+fes[ar[i]].title+'\')" onmouseout="hhint()"> ');
	}
}

function showInfo(id){
	index='#inf'+id;
	if($(index).css('display')=='block'){
		$(index).hide();
		$('#img'+id).attr('src', '/images/arrow_more.gif');
	}
	else{
		$(index).show();
		$('#img'+id).attr('src', '/images/arrow_less.gif');
	}
}

//-------shading screen-------------
var value = 0;
function setOpacity() {
	value += .3;
	$('#shading').css('width','100%');
	$('#shading').css('height',$(document).height());
	$('#shading').show();
	$('#shading').css('opacity',value/10);
	$('#shading').css('filter','alpha(opacity=' + value*10 + ')');
	myTimeout = setTimeout("setOpacity()", 1);
	if ((value/10) >= .5)
		clearTimeout(myTimeout);
}

function removeOpacity(){
	value -= .3;
	myTimeout2 = setTimeout("removeOpacity()", 1);
	$('#shading').css('opacity',value/10);
	$('#shading').css('filter','alpha(opacity=' + value*10 + ')');
	if ((value/10) <= 0) {
		$('#shading').hide();
		clearTimeout(myTimeout2);
	}
}

//-------tool tip-------------
var offxp=-60;
var offyp=-25;
var ie=document.all;
var ns6=document.getElementById && !document.all;
var ehint=false;
var tipobj;

function ietb(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function shint(thetext){
	if (ns6||ie){
		w=thetext.length*8;
		tipobj.style.width=w+"px";
		tipobj.innerHTML=thetext;
		ehint=true;
		offxp=-1*w;
		return false;
	}
}
function phint(e){
	if (ehint){
		var obj=ietb();
		var curX=(ns6)?e.pageX : event.x+obj.scrollLeft;
		var curY=(ns6)?e.pageY : event.y+obj.scrollTop;
		var rightedge=ie&&!window.opera? obj.clientWidth-event.clientX-offxp : window.innerWidth-e.clientX-offxp-20;
		var bottomedge=ie&&!window.opera? obj.clientHeight-event.clientY-offyp : window.innerHeight-e.clientY-offyp-20;
		var leftedge=(offxp<0)? offxp*(-1) : -1000;
		if (rightedge<tipobj.offsetWidth) tipobj.style.left=ie? obj.scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px";
		else if (curX<leftedge) tipobj.style.left="5px";
			else tipobj.style.left=curX+offxp+"px";
		if (bottomedge<tipobj.offsetHeight) tipobj.style.top=ie? obj.scrollTop+event.clientY-tipobj.offsetHeight-offyp+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offyp+"px";
		else tipobj.style.top=curY+offyp+"px";
		tipobj.style.visibility="visible";
	}
}

function hhint(){
	if (ns6||ie){
		ehint=false;
		tipobj.style.visibility="hidden";
		tipobj.style.left="-1000px";
		tipobj.style.width='';
	}
}
document.onmousemove=phint;
//--------google search--------
try{ google.load('search', '1');} catch(e){}
var webSearch;
function searchPagination() {
	var cursor = webSearch.cursor;
	var curPage = cursor.currentPageIndex;
	var html = '';
	if(cursor.pages.length>1){
		for (var i = 0; i < cursor.pages.length; i++) {
			var page = cursor.pages[i];
			if (curPage == i) {
				html+='<span class="search-pager-active">['+page.label+']</span>';
			} else {
				html+='<a href="javascript:webSearch.gotoPage('+i+');" class="search-pager">['+page.label+']</a>';
			}
		}
		html='<p>Страницы: '+html+'</p>';
	}
	$('#cell-content').append(html);
}

function searchComplete() {
	document.title='Виртуальный тур по Крыму. Поиск по сайту: '+$('#search-field').val();
	$('#cell-content').html('<h1 class="subtitle">Результаты поиска</h1>');
	if (webSearch.results && webSearch.results.length > 0) {
		var results = webSearch.results;
		for (var i = 0; i < results.length; i++) {
			var result = results[i];
			var html = '<div class="search-result">'+
				'<a href="'+result.unescapedUrl+'" class="search-title">'+result.titleNoFormatting+'</a>'+
				result.content+
				'<a href="'+result.unescapedUrl+'" class="search-link">'+result.unescapedUrl+'</a>'+
				'</div>';
			$('#cell-content').append(html);
		}
		searchPagination();
	}
	else $('#cell-content').append('<div>По Вашему запросу ничего не найдено.</div>');
}

function searchStart(){
	var key=$('#search-field').val();
	if(key=='') return alert('Введите ключ поиска!');
	webSearch = new google.search.WebSearch();
	webSearch.setResultSetSize(google.search.Search.LARGE_RESULTSET);
	webSearch.setSiteRestriction(location.hostname);
	//webSearch.setSiteRestriction('www.virtual.crimea.ua');
	webSearch.setRestriction(google.search.Search.RESTRICT_SAFESEARCH, google.search.Search.SAFESEARCH_OFF);
	webSearch.setSearchCompleteCallback(this, searchComplete, null);
	webSearch.execute(key);
}
//---------addthis share----------------
var addthis_config = {"data_track_clickback":true};
function addthis_share(){
	var tracker='<div class="addthis_toolbox addthis_default_style">'+
		'<a class="addthis_button_preferred_1"></a>'+
		'<a class="addthis_button_preferred_2"></a>'+
		'<a class="addthis_button_preferred_3"></a>'+
		'<a class="addthis_button_preferred_4"></a>'+
		'<a class="addthis_button_preferred_5"></a>'+
		'<a class="addthis_button_preferred_6"></a>'+
		'<a class="addthis_button_preferred_7"></a>'+
		'<span class="addthis_separator">|</span>'+
		'<a href="http://www.addthis.com/bookmark.php?v=250&amp;username=crimean" class="addthis_button_compact">Еще</a></div>';
	return tracker;
}
//--------------------------------
function aniOver(ob){
	$(ob).animate({width:'150px',height:'60px',left:'-20px',top:'0px'}, 300);
}
function aniOut(ob){
	$(ob).animate({width:'180px',height:'72px',left:'0px',top:'-12px'}, 200);
}
//-------------------------------- блок бронирования с bookit
 function updateStartDate(value) {
	var dateArray = value.split(/\./);
	var newMinDate = new Date();
	newMinDate.setDate(dateArray[0]);
	newMinDate.setMonth(dateArray[1]-1);
	newMinDate.setFullYear(dateArray[2]);
	
	newMinDate.setDate(newMinDate.getDate() + 1);
	$('#endDate').datepicker("option", 'minDate', newMinDate);
	
	var newMaxDate = new Date(newMinDate);
	newMaxDate.setDate(newMaxDate.getDate() + 30);
	$('#endDate').datepicker("option", 'maxDate', newMaxDate);
}
			
//--------------------------------
$(document).ready(function () {
	if ($("#vk_comments").length>0)	VK.Widgets.Comments("vk_comments", {limit: 10, width: "460", attach: "photo"});
	$('img.icon').hover(function(){aniOver(this);},function(){aniOut(this);});
	$('.pi').wrap('<div class="co"><div class="fr"></div></div>');
	$('.shadow').wrap('<div class="sh-right"><div class="sh-bottom"><div class="sh-corner"></div></div></div>');
	$('.shadow').each(function(){
		w=parseInt($(this).css('width'))+8;
		h=parseInt($(this).css('height'))+8;
		$(this).parent().css('height', h+'px').parent().parent().css('width', w+'px');
	});

	//if pano page
	if($('#pano-shower').length>0){
		var qty=getCookie("panorama_qty");
		if(!qty) qty='low';
		// quality type available
		if($('#select-pano-viewer option[value="'+qty+'"]').length>0)
			$('#select-pano-viewer').val(qty);
		else qty=$("select option:selected").val();
		// show pano
		showPano(qty, p_id);
		// quality changer
		$('#select-pano-viewer').change(function(){qtyPano($(this).val())});
		// comment form load
		$('#comment-form').html('<div align="center"><img src="/images/loading.gif"></div>');
		$('#comment-form').load('/ajax/pano/form_comment.php');
	}
	// search action
	$('#search-button').click(function(){searchStart();});
	$('#search-field').keypress(function(e){if (e.which == 13) searchStart();});
	// addthis
	if($('.share').get(0)){
		$('.share').html(addthis_share());
		$('body').append('<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=malaya"></script>');
	}
	$('#cell-logo > img').click(function(){location=location.protocol+'//'+location.hostname;});
	// hint 
	tipobj=document.getElementById("hint");
	//-------------------------------- блок бронирования с bookit 
	$.datepicker.setDefaults($.extend($.datepicker.regional["ru"]));
    var minDate = new Date();
    minDate.setDate(minDate.getDate() + 1);
    var maxDate = new Date();
    maxDate.setMonth(maxDate.getMonth() + 11)

    $('#startDate').datepicker({ numberOfMonths:1, onClose: updateStartDate, minDate: minDate, defaultDate: new Date(), maxDate: maxDate, dateFormat: 'dd.mm.yy'});
    $('#endDate').datepicker({ numberOfMonths:1, minDate: minDate, defaultDate: new Date(), maxDate: maxDate, dateFormat: 'dd.mm.yy'});

    $('#beginDate').datepicker({ numberOfMonths:1, onClose: updateStartDate, minDate: minDate, defaultDate: new Date(), maxDate: maxDate, dateFormat: 'dd.mm.yy', showOn: "both", buttonImage: '/images/bg_calendar1.png', buttonImageOnly: true});
    $('#dueDate').datepicker({ numberOfMonths:1, minDate: minDate, defaultDate: new Date(), maxDate: maxDate, dateFormat: 'dd.mm.yy', showOn: "both", buttonImage: '/images/bg_calendar1.png', buttonImageOnly: true});

    var mainUrl = 'http://bookit.virtual.crimea.ua/';
    $('#search').click(function(){
		if($('#cityId').val() != '0'){
			if($('#startDate').val() != '' && $('#endDate').val() != ''){
				if($('#objectId').val() != 0){
					var startDateArray = $('#startDate').val().split(/\./);
					var startDate = startDateArray[2] + startDateArray[1] + startDateArray[0];

					var endDateArray = $('#endDate').val().split(/\./);
					var endDate = endDateArray[2] + endDateArray[1] + endDateArray[0];
					document.location.href = mainUrl + 'catalogue/hotels/objectId-' + $('#objectId').val() + '/prices/&filter[StartDate]=' + startDate + '&filter[DueDate]=' + endDate + '#down';
				}
				else if($('#cityId').val() != 0){
					document.location.href = mainUrl + 'search?p[target]=c-' + $('#cityId').val() + '&p[start]=' + $('#startDate').val() + '&p[end]=' + $('#endDate').val();
				}
			}
			else{
				alert('Пожалуйста, выберите даты');
			}
		}
		else{
			alert('Пожалуйста, выберите город');
		}
    });
    $('#bron_search').click(function(){
		if($('#targetName').val() != '0'){
			if($('#beginDate').val() != '' && $('#dueDate').val() != ''){
				if($('#objectId').val() != 0){
					var startDateArray = $('#beginDate').val().split(/\./);
					var startDate = startDateArray[2] + startDateArray[1] + startDateArray[0];

					var endDateArray = $('#dueDate').val().split(/\./);
					var endDate = endDateArray[2] + endDateArray[1] + endDateArray[0];
					document.location.href = mainUrl + 'catalogue/hotels/objectId-' + $('#objectId').val() + '/prices/&filter[StartDate]=' + startDate + '&filter[DueDate]=' + endDate + '#down';
				}
				else if($('#targetName').val() != 0){
					document.location.href = mainUrl + 'search?p[target]=c-' + $('#targetName').val() + '&p[start]=' + $('#startDate').val() + '&p[end]=' + $('#endDate').val();
				}
			}
			else{
				alert('Пожалуйста, выберите даты');
			}
		}
		else{
			alert('Пожалуйста, укажите город');
		}
    });
    /*
    */

//--------------------------------
});

