var largeMenu = 25, smallMenu = 25;
var resizeTimer, timerTransform = null;
$(window).bind('resize', function() {
    if (resizeTimer) clearTimeout(resizeTimer);

    resizeTimer = setTimeout( function() { DoResize() }, 30 );
});

function krpano() {
	var krp = document.getElementById("krpanoSWFObject");
	return krp?krp:self;
}

$(document).ready(function () {
	setTimeout( function() {
		self.focus();
		krpano().focus();
	}, 600 );

	hiConfig = {
		sensitivity: 5,
		interval: 300,
		timeout: 600,
		over: function() { menuLarge(largeMenu) },
		out: function() { menuSmall(smallMenu) }
	}
	$('#topLine').hoverIntent(hiConfig);
	$('#bottomLine').hoverIntent(hiConfig);
	$('#topLine').dblclick(function() {
		window.open(document.location.href);
	});

    $('tt.fb_like').each(function() {
      var fbml_stuff_html = $(this).html();
      var fbml_stuff_html = fbml_stuff_html.replace(/<!-- FBML /g, "");
      var fbml_stuff_html = fbml_stuff_html.replace(/ FBML -->/g, "");
      $(this).html(fbml_stuff_html);
    });


	var maxW = $('a', '#blockLeft').width() + $('h1', '#blockLeft').width() + 280;
    $('#blockLeft').width(maxW);

});


function rotateStop() { krpano().call("copy(rotate,autorotate.enabled);set(autorotate.enabled,false);"); }

function fullScreen() { krpano().call("enterFullscreen();"); }

function rotateRestore() { krpano().call("set(autorotate.enabled,get(rotate));"); }

function DoResize() {
	var newH = $(window).height()-$("#topLine").height()-$("#bottomLine").height();
	if (newH > 200) $('#panotour').height(newH);
}

function Resize(w, h) { $('#panotour').height(h).width(w); }

function menuLarge(size)	{
	$('#topLine').animate({height: size}, { duration: 600, step: DoResize });
	$('#bottomLine').animate({height: 3}, 600, rotateStop);
	if (timerTransform) clearTimeout(timerTransform);
}

function menuSmall(size)	{
	timerTransform = setTimeout(function() {
		$('#topLine').animate({height: size}, { duration: 800, step: DoResize });
		$('#bottomLine').animate({height: 2}, 800, rotateRestore);
		self.focus();
		krpano().focus();
	}, 1000);
}

function toggleSize(small, large)	{

	if ($("#topLine").height() < large) // is_small?
	{
			rotateStop();
	//	$('#bottomLine').animate({height: 20});
		$('#topLine').animate({height: large},
			function() { DoResize(); });
	} else {
	//	$('#bottomLine').animate({height: 3});
		$('#topLine').animate({height: small},
			function() { DoResize(); });
		rotateRestore();
	}
}


