$(document).ready(function() {
//alert('Улюлю!!!');

	//$('.stage').
	$('.stage').after('<div><img src="/i/gallery-shadow.png" height="47px" height="300px" width="642px" style="position:relative;top:-10px;" ></div>');
	$('.search-submit-new').hover(function(){
		$(this).attr('src','/i/search-but_hover.png');
	},function(){
		$(this).attr('src','/i/search-but.png');
	});
	//width=$('.main .blocks').css('width');
	//alert(width);
	//alert($('.main .blocks').innerWidth);
	//alert(width);
	//Авторизация
	width=$('.main').width();
	
	
	if (width>1000) {
		
		//$('.text-slogan').css('width','250px');
		//$('.text-slogan').css('top','31px') ;
	}

	if (width>1050) {
		
		//$('.text-slogan').css('width','320px');
	//	$('.text-slogan').css('top','43px') ;
	}
	if (width>1200) {
		
		//$('.text-slogan').css('width','450px');
		//$('.text-slogan').css('top','60px') ;
	}
	//alert(width);
	$('.auth .enter a').click(function () {
		//alert('Улюлю!!!');
		$('.overlay_all').css('display','block');
		$('#auth').css('display','block');
	});
	$('.overlay_all').click(function () {
		$('#auth').css('display','none');
		$(this).css('display','none');
	});
	
	$('#auth .close').click(function() {
		$('#auth').css('display','none');
		$('.overlay_all').css('display','none');
	});
//self.resizeTo(1024,768);

	//Выравниваем главное меню
	div_width=$('.view_menu .blocks').width();
	all=0;
	$('.view_menu .blocks .view_table_menu li').each(function () {
		all=all+$(this).width();
		
	})
	delta=div_width-all-5;
	end=$('.view_menu .blocks .view_table_menu li:eq(3)').width();
	if ($.browser.opera) {
		$('.view_menu .blocks .view_table_menu li:eq(3)').width(end+delta-2);
	}
	else {
		$('.view_menu .blocks .view_table_menu li:eq(3)').width(end+delta-2);
	}

	$(window).resize(function(){
  			div_width=$('.view_menu .blocks').width();
			all=0;
			$('.view_menu .blocks .view_table_menu li').each(function () {
				all=all+$(this).width();
			})
			delta=div_width-all-5;
			end=$('.view_menu .blocks .view_table_menu li:eq(3)').width();
			if ($.browser.opera) {
				$('.view_menu .blocks .view_table_menu li:eq(3)').width(end+delta-2);
			}
			else {
				$('.view_menu .blocks .view_table_menu li:eq(3)').width(end+delta-2);
			}
  	//self.resizeTo(1024,768);
  	
  		width=$('.main').width();
	//alert(width);
	if (width>1000) {
		
		//$('.text-slogan').css('width','250px');
		//$('.text-slogan').css('top','31px') ;
	}

	if (width>1050) {
		
		//$('.text-slogan').css('width','320px');
		//$('.text-slogan').css('top','43px') ;
	}
	if (width>1200) {
		
	//	$('.text-slogan').css('width','450px');
		//$('.text-slogan').css('top','60px') ;
	}
  	
	});
	
		if ($.browser.opera) {
				$('.main .cat_main tr .catalog_on .catalog_view .blocks .view_table_menu').width('103.7%');
		};
		if ($.browser.msie) {
				
			$('.main .cat_main tr .catalog_on .catalog_view .blocks .view_table_menu ul li').css('width','24.2%');
				
		};
		
	//$('.view_menu .blocks .view_table_menu li.ender').width(end+delta-1);
	//alert(end);
	//Делаем ховер
	$('.main .catalog_table li div.second').hover( function() { 
			$(this).parent().css('background','url("/i/bgblocks_hover.png") repeat scroll 0 0 transparent');
			//$(this).parent().find('div.first').css('background','url("../i/bgblocks.png") repeat scroll 0 0 transparent');
			$(this).parent().find('div.first').css('background','#F3F7FD');
			if ($(this).parent().hasClass('running')) {
				$(this).parent().find('div.first').css('border-radius','15px 0 0px 0');
			}
		},
	function () {
		$(this).parent().find('div.first').css('background','none');
		$(this).parent().css('background','none');
	})
	
	$('.main .catalog_table li div.first').hover( function() {
		$(this).css('background','url("/i/bgblocks_hover.png") repeat scroll 0 0 transparent');
			},
	function () {	
		$(this).css('background','none');
	});
	
	//$('.main .catalog_table li div.second').parent().css('background','url("/i/bgblocks_hover.png") repeat scroll 0 0 transparent')
	//text=$('.main .catalog_table li div.second').parent().html();
	//alert(text);
	///Делаем карту
	$('#map .item').hover(
		function () {
			id=$(this).attr('id');
			len=id.length;
			div_id=id.substr(1,len-1);
			//alert(div_id);
			$('#e'+div_id).css('display','block');
			position=$(this).position();
			$('#e'+div_id).css('top',position.top-100);
			$('#e'+div_id).css('left',position.left+10);
			
			padding=$('#e'+div_id).find('.text').css('padding');			
			height=$('#e'+div_id).find('.text').css('height');
//alert(height);
			width=$('#e'+div_id).find('.text').css('width');
			width=$('#e'+div_id).find('.text').width();
			height=$('#e'+div_id).find('.text').height();
			
			$('#e'+div_id).find('.block').css('height',height);
			$('#e'+div_id).find('.block').css('width',width);
			$('#e'+div_id).find('.block').css('padding',padding);
			
			
		},function () {
			id=$(this).attr('id');
			len=id.length;
			div_id=id.substr(1,len-1);
			//alert(div_id);
			$('#e'+div_id).css('display','none');
			
		}
	);
	
	
	
	$('.catalog_on .catalog_table ul li').each(function() {

	first_height=$(this).find('div.first').css('height');
	second_height=$(this).find('div.second').css('height');
	if (first_height>second_height) {
		$(this).find('div.second').css('height',first_height);
	}
	else {
		$(this).find('div.first').css('height',second_height);
	}
	});
	$('.catalog_on .catalog_table').each( function () {
		count_li=$(this).find('ul li').length;
		//alert(count_li);
		if (count_li==1) {
			$(this).find('ul li').css('border-bottom','none !important');
			$(this).find('ul li').addClass('ender');
		}
	});
	
// top example

    $('.roundabout-example ul').roundabout({
      'easing': 'easeOutExpo',
      'duration': 500,
      'btnNext': '.next',
      'btnPrev': '.previous'
    });
    
    $('.roundabout-example a[rel="gallery"]').colorbox();
    $("a.gallery").colorbox();
    $("a[rel='gallery2']").colorbox();
    $("a[rel='gallery']").colorbox();
    /*
    $("a.gallery").fancybox({
      'titlePosition'   : 'outside',
      'overlayColor'    : '#000',
      'overlayOpacity'  : 0.5
    });
    
    $("a[rel='gallery2']").fancybox({
      'titlePosition'   : 'outside',
      'overlayColor'    : '#000',
      'overlayOpacity'  : 0.5
    });
    
    $("a[rel='gallery']").fancybox({
      'titlePosition'   : 'outside',
      'overlayColor'    : '#000',
      'overlayOpacity'  : 0.5
    });*/

   
    /*$(window).resize(function() {
        $('.roundabout-example ul').roundabout_animateToBearing($.roundabout_getBearing($('.roundabout-example ul')));
    });*/
    
    /*$('.subdir').click(function(){
      $(this).next('li.pod_menu:first').slideToggle('fast');
      return false;
    });*/


  	$('#modalOrder').click(function (e) {
  	    var params = '';
  		  modalWindow('#basic-modal-content', 'formId', '/_ajax/order.php', params, this);  
  		  return false;
  	});
  	
  	$('.search-buy').click(function(){
  	  var params = 'product='+$(this).attr('item');  	  
  	  modalWindow('#basic-modal-content', 'formId', '/_ajax/order.php', params, this);
  	  return false;
  	});
  	
  	$('#mycarousel a').click(function(){
  	  
  	  var obj = $(this);
  	  $('.stage .overlay').removeClass('hidden');
  	  $.ajax({
  	    type: "POST",
  	    url: "/_ajax/getImages.php",
  	    data: "getImage=Y&section="+$(this).attr('id'),
  	    success: function(data) {
  	      $('.stage').html(data);
          $('#mycarousel div.pipka').remove();
          $('#mycarousel a.activeDirecory').removeClass('activeDirecory');
          obj.append($('<div/>').attr({
            'class': 'pipka'            
          })).addClass('activeDirecory');
          $('.stage .overlay').addClass('hidden');
              $('.roundabout-example ul').roundabout({
                'easing': 'easeOutExpo',
                'duration': 500,
                'btnNext': '.next',
                'btnPrev': '.previous'
              });
              $('.roundabout-example a[rel="gallery"]').colorbox();
  	    }
  	  });
  	  return false;
  	});

});


function modalWindow(obj, formId, url, params, objLink) {

    $(obj).modal({onOpen: function (dialog) {
         $.ajax({
           type: "POST",
           url: url,
           data: params,
           success: function(msg){
             $(obj).html(msg);   
             dialog.overlay.fadeIn('slow', function () {
               dialog.container.slideDown('slow', function () {
                  dialog.data.fadeIn('slow', function() {

                  });
               });
             });
           }
         });         
    }
  }); 
}
