/******* pupup faders *******/
function faderResize(){
    var height = $('.all').height();
    if ($('#gal').length) {
        var galheight = $('#gal').offset().top + $('#gal').height() + 20;
        if (galheight > height)
            height = galheight;
    } 
    $('#fader').height(height).width($('.all').width());
};

function popup_show()
{
    $('body').append('<div id="fader"></div>');
    faderResize();
    $('#fader').css({
        opacity: '0'
    }).animate({
        opacity: '0.8'
    }, 100).attr('title', 'Закрыть').click(function(){
        popup_hide();
    });
    $(window).bind('resize', faderResize);
}

function popup_hide()
{
    $('#fader').animate({
        opacity: '0'
    }, 100, function(){
        $(this).remove();
        $('#gal').remove();
        $('#callback').hide().find('p').remove().end().find('form').show();
    });
    
    $(window).unbind('resize', faderResize);
    return false;
}
/******* / pupup faders *******/


function applyHandler(o, e, f) {
	e = (e instanceof Array) ? (arguments.callee(o, e[1], f), e[0]) : e;
	return (o.attachEvent) ? o.attachEvent(e, f) : (o.addEventListener) ? o.addEventListener(e.substr(2), f, false) : false;
} 




function getwidth() {
	var x = document.getElementById('srch');
	if(x) create_label(x,'Поиск по сайту');

	var w = document.documentElement.clientWidth;
	var p = '0.5%';
	if (w > 1024 && w <= 1200) p = '1%';
	else if (w > 1200 && w <= 1600) p = '1.5%';
	else if (w > 1600) p = '2%';
	var m = document.getElementById("menu");
	if (!m) return;
	else {
		var mnum = m.childNodes;
		for (var i = 0; i < mnum.length; i++) {
			if (mnum[i].tagName == "LI") {
				mnum[i].style.paddingRight = p;
			}
		}
	}

	var g = document.getElementById('gallery');
	var c = document.getElementById('control');
	var s = document.getElementById('slideshow');
	var sc = document.getElementById('scroller');
	if (!s) return;
	else {
		if (s.offsetWidth >= sc.offsetWidth) {
			g.style.padding = '0';
			g.style.marginLeft = '-5px';
			c.style.display = 'none';
			c.style.visibility = 'hidden';
			sc.style.left = '0';
		} else {
			g.style.padding = '0 20px';
			g.style.marginLeft = '0';
			c.style.display = 'block';
			c.style.visibility = 'visible';
			sc.style.left = '0';
		}
	}
}


applyHandler(window, ['onload', 'onresize'], getwidth);






function pmenu (id) {
	var h = document.getElementById("popupmenu" + id);
	if (!h) return;
	else {
		if (h.style.display == "block") h.style.display = "none";	
		else h.style.display = "block";
	}
}





function popup (id, w, h, p) {
	var a = p + id + '.jpg';
	var x = (document.body.clientWidth - w) / 2;
	var y = (document.body.clientHeight - h) / 2;
	picWin = open('','','width=' + w + ',height=' + h + ',left=' + x + ',top=' + y + ',screenX=' + x + ',screenY=' + y +  ',toolbar=no,location=no,directories=no,copyhistory=no,scrollbars=no,menubar=no,resizable=no,status=no');
	picWin.document.write('<html><head><title>KR Properties</title></head><body style="margin:0;padding:0;"><img src="' + a + '" width="' + w + '" height="' + h + '" alt="" onclick="window.close();" title="Закрыть" style="cursor:pointer;" /></body></html>');
}






function movie (n, w, h) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + w + '" height="' + h + '"><param name="allowFullScreen" value="false" /><param name="movie" value="' + n + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="autoStart" value="-1" /><embed src="' + n + '" quality="high" wmode="transparent" width="' + w + '" height="' + h + '" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
}






function input_over (obj, text) {
	if (obj.value == text) {
		obj.style.color = '#000';
		obj.value = '';
	}
}

function input_out (obj, text) {
	if (obj.value == '' || obj.value == text) {
		obj.style.color = '#b3b3b3';
		obj.value = text;
	}
}

function create_label (obj, text) {
	obj.onfocus = function () { input_over (this, text); };
	obj.onblur = function () { input_out (this, text); };
	input_out (obj, text);
}






