﻿jQuery(document).ready(function (){
		
	$('.isJurMain').click(function (){
	    var box = $('.remember-me .simple-reg');
		box.slideUp();
		box.is(':hidden') ? box.slideDown() : box.slideUp();
	});
	
	$('.isJurCB').click(function (){
		var box = $('.ur');
		box.slideUp();
		box.is(':hidden') ? box.slideDown() : box.slideUp();	
	});
																 
	$('.isRegCB').click(function (){
		var box = $('.remember-me .simple-reg');
		box.slideUp();
		box.is(':hidden') ? box.slideDown() : box.slideUp();
		var b = 1;
		box.is(':hidden') ? $('.isJurCB').attr("checked","") : b = 0;
	});


	
	/**/
		    var box = $('.simple-reg .ur');
		$('.isJurMain').attr("checked","");
		box.slideUp();
		
	    var box = $('.simple-reg .ur');
		$('.isJurCB').attr("checked","");
		box.slideUp();
	
	    var box = $('.remember-me .simple-reg');
		$('.isRegCB').attr("checked","");
		box.slideUp();
	    


	/**/
	

	
	$('.nav-bar-add input').each(function (){
		var input = $(this);
		if(input.attr('value') == '') input.addClass('emptySearchStr');
		
	}).focus(function (){
		var input = $(this);
		if(input.attr('value') == '') input.removeClass('emptySearchStr');
		
	}).blur(function (){
		var input = $(this);
		if(input.attr('value') == '') input.addClass('emptySearchStr');
		
	});
	
	// changed by wdk 20090319
	$('.global-search .advanced-search').click(function (){
		var ths = $(this);
		var box = $('.global-search .more-details');
		var hf = $('.global-search .search-mode');
		
		if(box.is(':hidden')){
			box.slideDown();
			ths.html('Обычный поиск');
			hf.val('Advanced');
		
		}else{
			box.slideUp();
			ths.html('Расширенный поиск');
			hf.val('Simple');
		}
		
		return false;
    });

    $('.loginwobg a.ajquery').click(function() {
        LB_overlay.show().animate({ opacity: 0.7 }, 100);
        if ($.browser.msie && $.browser.version < 7) $('select').css({ 'visibility': 'hidden' });
        $('.login-box').fadeIn(100);
        return false;
    });
    $('.get-pic-box').click(function() {
        LB_overlay.show().animate({ opacity: 0.7 }, 100);
        if ($.browser.msie && $.browser.version < 7) $('select').css({ 'visibility': 'hidden' });
        LB_box.addClass('loading').fadeIn(100);

        var image = $('<img src="' + this.href + '" alt="' + this.title + '"/>');
        var txt = this.title;

        while (txt.indexOf(' ') != -1) {
            txt = txt.replace(' ', '&nbsp;');
        }
        LB_box.find('h2').html(txt);

        image.appendTo(LB_box);
        image.load(function() {
            var imageWidth = image.width();
            var imageHeight = image.height();

            if (imageWidth > 800) {
                var delta = 800 / imageWidth;
                imageWidth = 800;
                imageHeight = imageHeight * delta;

                image.width(imageWidth);
                image.height(imageHeight);
            }

            if (imageHeight > 600) {
                var delta = 600 / imageHeight;
                imageHeight = 600;
                imageWidth = imageWidth * delta;

                image.width(imageWidth);
                image.height(imageHeight);
            }

            var textWidth = LB_box.find('h2').width() + 40;
            imageWidth = imageWidth > textWidth ? imageWidth : textWidth;
            imageHeight = image.height() + LB_box.height() / 2;

            scrollTop = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
            LB_box.removeClass('loading').animate({
                width: imageWidth,
                marginLeft: -imageWidth / 2,
                height: imageHeight,
                marginTop: -imageHeight / 2 + scrollTop
            }, 100);
        });
        return false;
    });

    var LB_box = $('<div class="pic-box"><div class="close_LB"></div><h2>Вход для клиентов:</h2></div>').appendTo('body').hide();
    var LB_overlay = $('<div id="overlay"></div>').appendTo('body').height($(document).height()+1000).hide().animate({ opacity: 0 }).click(close_LB);
    $('.close_LB').click(close_LB);

    $(document).keydown(function(e) {
        if (e.which == 27) close_LB();
    });

    function close_LB() {
        LB_box.css({ 'margin': '-50px 0 0 -50px', 'width': '100px', 'height': '100px' }).hide().find('img').remove();
        $('.login-box').hide();
        LB_overlay.hide();
    }
	
});
