$(function(){

    
    $('div.company-list').each(function(){
        var timeBig = 150; // �������� � ������� ������������� �������
       
	   var companyList = $(this);

        var left = 0;
        for (var i=0; companyList.find('.company-item:eq('+i+')').length; i++) {
            companyList.find('.company-item:eq('+i+')').css('left', left+'px');
            companyList.find('.company-item:eq('+i+')').css('position', 'absolute');
            left += 109;
        }
        
        
        companyList.find('.company-item').each(function(){
            var timeout = null;
            var big = 0.26; // �� ������� ��������� ����������� �������            
            var leftSmall = $(this).position().left;
            var topSmall = $(this).position().top;
            var heightSmall = $(this).height();
            //var heightSmall = 55;
            var widthSmall = $(this).width();
            var fontSmall =  parseInt($(this).find('.title a').css('font-size'))+'px';
            //console.log(fontSmall);
            var heightBig = heightSmall+(heightSmall*big);
            var widthBig = widthSmall+(widthSmall*big);
            var fontBig =  parseInt(fontSmall)+2+'px';
            var leftBig = leftSmall-(widthBig-widthSmall)/2;
            var topBig = topSmall-(heightBig-heightSmall)/2;
            
            
            $(this).click(function(){
                var url = $(this).find('a').attr('href');
                window.location=url;
            });
            
            $(this).mouseover(function(){
                if (timeout) {
                    clearTimeout(timeout);
                }
                if ($(this).is('.big')) {
                    return true;
                }
                $(this).addClass('big');
                $(this).stop();
                $(this).animate({
                    'left':leftBig, 
                    'top':topBig,
                    'height':heightBig,
                    'width':widthBig
                },  timeBig); 
                $(this).find('.title a').animate({
                    'font-size':fontBig
                },  timeBig);
            });
            
            $(this).mouseout(function(){
                var mouse = $(this);
                timeout = setTimeout(function(){
                    mouse.removeClass('big');
                    mouse.stop();
                    mouse.animate({
                        'left':leftSmall, 
                        'top':topSmall,
                        'height':heightSmall,
                        'width':widthSmall,
                        'font-size':fontSmall
                    }, timeBig); 
                    mouse.find('.title a').animate({
                        'font-size':fontSmall
                    },  timeBig);
                }, 150);
            })
        }); //items.children('div.company-item').each(function(){        
    }); // $('div.company-list').each(function(){
    
    $('#search_field').bind('focus focusout', function(){
    	var t = $(this);
    	if (t.val() == t.attr('title'))
    		t.val('');
    	else if (t.val() == '')
    		t.val(t.attr('title'));
    		
    });
	
	
	/*gallery*/
	$('.gallery_list li .picture_link').click(function(){
		var img_src = $(this).attr('href');
		var img_text = $(this).next('.picture_text').html();	
	
		var window = $('#window');
		var window_picture  = $('#picture', window);	
		var window_text  = $('#gallery_one_description', window);	
		
		//alert('!');
		
		window_picture.attr('src', img_src);
		window_text.html(img_text);
		$("a.vote_button", window_text).click(function () {
			clickVote(this);
			$('#window').hide();
			window_picture.attr('src','');
		});
		
		/*IE6*/
		if (typeof document.body.style.maxHeight === "undefined") {
			var scroll = document.documentElement.scrollTop;
			window.css('top', scroll);
		}
		window.show();		
		window_picture.load(function(){
			var windowHeight = window.height();
			windowHeight = -windowHeight/2;
			window.css({'marginTop':windowHeight});
		})
		
		
		return false;	
	})	
	
	$('#window #exit').click(function(){
		$('#window').hide();
		$('#window img').attr('src','');
		return false;
	});
	
	
	
	
})
