
function doc_scroll_top(){

    if ( window.pageYOffset ) { return window.pageYOffset; }

    if ( document.documentElement && document.documentElement.scrollTop ) {return document.documentElement.scrollTop;}
    if ( document.body ) { return document.body.scrollTop; }

    return 0;
}

function doc_height() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function doc_width() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
        Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
        Math.max(D.body.clientWidth, D.documentElement.clientWidth)
    );
}

function popup_show(popup_id)
{
	$(popup_id).css('top', doc_scroll_top() + 100 + 'px');

	$('#shadow').css('height', doc_height() + 'px');
	$('#shadow').css('width', doc_width() + 'px');
	$('#shadow').css('display', '');

	if ('#popup-media' == popup_id)
	{
		$(popup_id).css('left', parseInt((doc_width() - 910)/2) + 'px');
	}
	else
		$(popup_id).css('left', parseInt((doc_width() - 310)/2) + 'px');

	$('.body select').css('display', 'none');

	$(popup_id).css('display', '');
	$('#shadow').css('display', '');

	return false;
}

function popup_close(popup_id)
{
	$('.body select').css('display', '');

	$(popup_id).css('display', 'none');
	$('#shadow').css('display', 'none');
}

$(document).ready(function()
{
	// init search open
	$('.show-expanded').click(function()
	{
		if ($('.search').hasClass('open'))
		{
			$('.search').removeClass('open');
		}
		else
		{
			$('.search').addClass('open');
		}
	});

	// init search selectors
	$('.select-service').click(function()
	{
		popup_show('#popup-service');
	});

	$('.select-params').click(function()
	{
		popup_show('#popup-params');
	});

	$('.warning').click(function()
	{
		popup_show('#popup-warning');
	});

	// tab switcher
	$('.info-left .tabs a').bind('click',
		function(event)
		{

			var a = $(this);

			if (!a.hasClass('selected'))
			{
				$('.info-left .tabs a').removeClass('selected');
				$('.info-left .tab-data').css('display', 'none');
				a.addClass('selected');
				$('#' + a.attr('id') + '-data').css('display', '');

				return false;
			}
		}
	);
});


