function getWindowHeight()
{
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number')
	{
		windowHeight = window.innerHeight;
	}
	else
	{
		if (document.documentElement && document.documentElement.clientHeight)
		{
			windowHeight = document.documentElement.clientHeight;
		}
		else
		{
			if (document.body && document.body.clientHeight)
			{
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setFooter()
{
	if (document.getElementById)
	{
		var windowHeight = getWindowHeight();
		if (windowHeight > 0)
		{
			var contentHeight = document.getElementById('top').offsetHeight + document.getElementById('catalog_uinfo').offsetHeight + document.getElementById('main_content').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0)
			{
				footerElement.style.position = 'relative';
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight) - 40) + 'px';
			}
			else
			{
				footerElement.style.position = 'static';
			}
		}
	}
}

var current_catalog_is = [];

function initCurrentCatalogId( )
{
	current_catalog_is = [];
}

function setCurrentCatalogId( id )
{
	current_catalog_is.push( id );
}

function getCurrentCatalogId()
{
	return current_catalog_is[current_catalog_is.length - 1];
}

function unsetCurrentCatalogId()
{
	current_catalog_is.pop();
}


function showMenuCatalogDesc( id )
{
	var desc_divs = document.getElementById( 'menu_catalog_desc' ).childNodes;

	for ( var i = 0; i < desc_divs.length; i++ )
	{
//	alert( desc_divs[i].nodeType );
		//if ( desc_divs[i] instanceof Text )
		//	continue;
		if ( 3 == desc_divs[i].nodeType )
		{
			continue;
		}
		desc_divs[i].style.display = ( desc_divs[i].id == id ? 'block' : 'none' );
	}
}

var curvyCSSClasses = [];

$(document).ready(
	function()
	{
		$("a.group").fancybox(
			{
				'hideOnContentClick': false
			}
		);

		settings =
		{
			tl: { radius: 10 },
			tr: { radius: 10 },
			bl: { radius: 10 },
			br: { radius: 10 },
			antiAlias: true,
			autoPad: true,
			validTags: ["div"]
		};

	
		for ( var i = 0; i < curvyCSSClasses.length; i++ )
		{
			$('.' + curvyCSSClasses[i] ).corner( settings );
		}
		
		setFooter();
	}
);

function sendMailer()
{
	var request_data =
	{
		email :	$( '#mailer_email' ).val(),
		contact_man : $( '#mailer_contact_man' ).val(),
		message : $( '#mailer_message' ).val(),
		save : 1
	};

	$.fn.fancybox.showLoading();
	$.get(
		'/mailer/'+ $( '#mailer_place' ).val(),
		request_data,
		function( data )
		{
			$("#fancy_content").hide().empty().append('<div id="fancy_ajax">' + data + '</div>').show();
			$( '#fancy_loading' ).hide();
		}
	);
}


window.onresize = function()
{
	setFooter();
}

