// JavaScript Document
var tab = 0;
var addMenu = true;
var showTimer;
var iText;
$(document).ready(function () {
	/*if(document.location.pathname == '/'){
	  $('#imagebox, #shadow').fadeIn(300)
	$("#imagenext, #imageprev").css({display: 'none'})
	
$("#imageborder img").attr({src: '/Content/userimages/image/new-year.jpg'}).bind("load", function(){
			var img_w = $(this).width();
			var img_h = $(this).height();
			$("#imageborder").animate({height:img_h+24+"px", marginTop: -1*img_h/2+"px"}, 500, function(){
				$("#imageborder").animate({width:img_w+"px", marginLeft: -1*img_w/2+"px"}, 500, function(){
					$("#imageborder img, #imageclose").fadeIn();
					$("#imagepanel").slideDown(200);
				});
			});
		});
	}*/

	if(document.location.pathname == '/uk/spa.html' || document.location.pathname == '/ru/spa.html'){
	  $('#imagebox, #shadow').fadeIn(300)
	$("#imagenext, #imageprev").css({display: 'none'})
	$("#imageborder img").attr({src: '/Content/images/spa-new.jpg'}).bind("load", function(){
			var img_w = $(this).width();
			var img_h = $(this).height();
			$("#imageborder").animate({height:img_h+24+"px", marginTop: -1*img_h/2+"px"}, 500, function(){
				$("#imageborder").animate({width:img_w+"px", marginLeft: -1*img_w/2+"px"}, 500, function(){
					$("#imageborder img, #imageclose").fadeIn();
					$("#imagepanel").slideDown(200);
				});
			});
		});
	}
    $('div.photo, div.thumb').each(function () {
        $(this).append('<div class="ctl"></div><div class="ctr"></div><div class="cbl"></div><div class="cbr"></div>')
    })
    var index = $('#tabs li.active').index();
    $('#slider div.item').eq(index).fadeIn(300).siblings('div.item').fadeOut(300)
    $('#tabs li a').click(function () {
        index = $('#tabs li a').index(this);
        $(this).parent('li').addClass('active').siblings('li').removeClass('active')
        $('#slider div.item').eq(index).fadeIn(300).siblings('div.item').fadeOut(300)
        return false;
    })
    $('input, textarea, select').focus(function () {
        $(this).addClass('focused')
    })
    $('input, textarea, select').blur(function () {
        $(this).removeClass('focused')
    })
    $('#close').hover(function () {
        $(this).text($(this).attr('title'))
    }, function () {
        $(this).text('')
    })
    $('div.tab:first').fadeIn(0)
    $('div.tab-control a:first').addClass('active')
    $('div.tab-control a').click(function () {
        tab = $(this).index()
        showTab(tab)
    })
	$('#admin-menu li.has-sub').hover(function(){
		callTimer($(this))
	}, function(){
		stopTimer()
		$(this).removeClass('open').children('ul').slideUp(300)
	})
	$('div.thumb').hover(function(){
		$(this).children('div.delete').slideDown(300)
	}, function(){
		$(this).children('div.delete').slideUp(300)
	})
	$('input.button').click(function(){
		setTimeout(function(){
			$('div.editor-field > span:visible').removeClass('field-validation-error').addClass('field-validation-valid').html('')
		}, 3000)
	})
	$('div.editor-field > span').each(function(){
		$(this).css({left: $(this).prev('input, textarea').width()+'px'})
	})
});
function showTab(tab, type) {
    $('#order').fadeIn(500)
	$('#RoomType option').removeAttr('selected')
    $('#RoomType option').eq(type).attr('selected', true)
    //console.log($('#room option').eq(type).val())
    $('div.tab-control a').eq(tab).addClass('active').siblings('a').removeClass('active')
    $('div.tab').eq(tab).fadeIn(0).siblings('div.tab').fadeOut(0)
	$('div.editor-field > span').each(function(){
		$(this).css({left: $(this).prev('input, textarea').width()+'px'})
	})
}
function closeOrder() {
    $('#order').fadeOut(500)
}
function showMenu(iText) { 
	var iClose;
	if($('div.lang a:eq(0)').hasClass('current')){
		iClose = 'Завершити перегляд'
	}
	if($('div.lang a:eq(1)').hasClass('current')){
		iClose = 'Завершить просмотр'
	}
	if($('div.lang a:eq(2)').hasClass('current')){
		iClose = 'Complete a review'
	}
    if (addMenu == true) {
        $('body').append('<div id="iframe"><span>'+iText+'</span><a href="javascript:hideMenu()">'+iClose+'</a><iframe frameborder="0" width="100%" height="100%" src="/flip/index.html"></iframe></div>')
        addMenu = false;
    }
    $('#iframe').fadeIn(300)
}
function hideMenu() {
    $('#iframe').fadeOut(300)
}
function callTimer(li){
	showTimer = setTimeout(function(){
		showSub(li)
	}, 300)
}
function showSub(li){
	li.addClass('open').children('ul').slideDown(300)
}
function stopTimer(){
	clearTimeout(showTimer)
}
