   if ($.browser.mozilla) {
  		
  		$('.intro img').load(function() {
  			
  			var inroHeight = $('.intro').height();
  			$('.intro').height(inroHeight);
  		});
  	}
	
$(document).ready(function() {
	
	function setElementValue(element,text){
		
		checkValue();
		
		element.focus(function() {
			$(this).val('');
		});
		
		element.blur(function() {
			checkValue();
		});
		
		function checkValue(){
			if(element.val() == ''){
				element.val(text);
			}
		}
		
	}
	
	setElementValue($('#nc_search_query'),'Поиск');
	

	 $("a.gallery").fancybox({
	 	'autoscale' : true,
	 	//'width': 	640,
	 	//'height': 415,
	 	'transitionIn'  : 'elastic',
        'transitionOut' : 'elastic'

	 });
	
	

	

	
	$('a.load').live('click',function(event) {
		event.preventDefault();
		var url = $(this).attr('href');
        var title = $(this).attr('title');
		$.ajax({
			type    : "GET"
			,cache	: false
			,url	: url
			,success: function(data) {
				var text = $(data).find('#videoplayer').html();
				$.fancybox({
					content:text,
                    'title': title


				});
			}
		});
	});
	
	$('.it').hide();
	
	$('.switch a').click(function(event){
		event.preventDefault();
		//$(this).parents('.coda-slider').removeAttr('style');
		var coda = $(this).parents('.coda-slider');
		var it = $(this).parent().next('.it');
		
		if(it.css('display')=='block'){
				coda.animate({height:coda.height()-it.height()},"slow");
				it.clearQueue().slideUp("slow", function () {
				});
				
			}else{
				coda.animate({height:coda.height()+it.height()},"slow");
				it.clearQueue().slideDown("slow", function () {
				});
			}
		


		}
	);


	$("#slideshow").loopedSlider({
	    autoStart:true,
        containerClick: false, // Click container for next slide
        autoStart: 6000, // Set to positive number for auto interval and interval time
        slidespeed: 800, // Speed of slide animation
        fadespeed: 600
	});
	
	$("#slideshow").hover(function() {
    	$("ul#nav").fadeIn();
  	},
  		function() {
    	$("ul#nav").fadeOut();
  	});
  	
  	$('.announce').css({'opacity':'0'});
  	//.mouseover(function() {

  	$('.item').live('mouseover',function () {
  	    $(this).children('.announce').clearQueue().animate({opacity:1},600);
  	});
  		
  	$('.item').live('mouseout',function () {
  	    $(this).children('.announce').clearQueue().animate({opacity:0},600);
  	});
  	
  	/*coda-slider*/
  	$('#coda-slider-1').codaSlider({
  		dynamicArrows: false,
  		dynamicTabsAlign: 'justify'
  	});

	$('h2.title').hide();
	
	/*sub_menu*/
	$('#sub_menu a').click(function() {
		$(this).parent().addClass('current')
		.siblings().removeClass('current');		
	});
	

	$('#verticalscroll').css({
		'position':'absolute'
	});
	$('#sub_menu a').click(function(event) {
		event.preventDefault();
		var name = $(this).attr('href').replace('#','');
		$('#verticalscroll .slide').removeClass('active');
		$('a[name="'+name+'"]').parents('.slide').addClass('active');
		var top = -($('#verticalscroll .active').position().top);
		$('#verticalscroll').animate({
			top: top+'px'
		}, 
		1000);
		
		$('#scrollouter').css({
			'overflow': 'hidden'//,'height': $('#verticalscroll .active').height()
			});
		$('#scrollouter').clearQueue().animate({
			height: $('#verticalscroll .active').height()
		}, 
		1000);	
	});
	
	
	/*sub_menu*/
	$('#sub_menu3 a').click(function() {
		$(this).parent().addClass('current')
		.siblings().removeClass('current');		
	});
	//$('#sub_menu3 a:first').parent().addClass('current');
	
	$('#sub_menu3 a').click(function(e) {
		e.preventDefault();
		var url = $(this).attr('href') ;
		$('#news').load(url + ' #news', function() {
			  	$('.announce').css({'opacity':'0'});
			  	$(this).parents('.coda-slider').removeAttr('style');

		});
		
	});
	
	var names = disp($("#verticalscroll a[name]"));
	
	//rebuildCatalog(names);
	

    
    $('#sub_menu a:first').trigger('click');
    //setTimeout(function(){ $('#sub_menu a:first').trigger('click') }, 1000);

	function rebuildCatalog(names){
		if($('div').is('.cat')){
		for (var i = 0; i < names.length; i++) {
			var slide = $('<div class="slide clearfix"></div>').appendTo('#verticalscroll');
    		var name = names[i];

    	$('a[name="'+name+'"]').each(function() {
    		$(this).parent().appendTo(slide);
    		$(this).parent().removeClass('last');
    		slide.children('.product:odd').addClass('last');
    	});
      }
    }
   }
		

    function disp(targets) {
      var a = [];
      $(targets).each(function(index) {
      	a.push($(targets[index]).attr('name'));
      });
      a = removeDuplicates(a);
      return a;
    }
 

    
	function removeDuplicates(inputArray) {
            var i;
            var len = inputArray.length;
            var outputArray = [];
            var temp = {};

            for (i = 0; i < len; i++) {
                temp[inputArray[i]] = 0;
            }
            for (i in temp) {
                outputArray.push(i);
            }
            return outputArray;
    }



		
	$('#adminForm').live('submit', function(event) {
		event.preventDefault();
		var action = $(this).attr('action') ;
		var data = $(this).serializeArray();
		$('#loadform').load(action + ' #loadform',data, function() {
			$('a.current').trigger('click');
			$('#loadform').children().unwrap();
			$(".warnText").blink("#EE192F");
		});
  		return false;
	}); 
  	

  	
  	
	
});


  	$.fn.blink = function (bgColor){
  			var thisBgColor = $(this).css('backgroundColor');
  			return this
  			.animate({backgroundColor: bgColor},600)
  			.animate({backgroundColor: thisBgColor},600);	
  	};
  	
 
 
  	
$(function(){
	if( $('div').is('.coda-nav') ) {


    var $el, leftPos, newWidth,
        $mainNav = $(".coda-nav ul");

    $mainNav.append("<li id='magic-line'>&nbsp;</li>");

    var $magicLine = $("#magic-line");
    $magicLine
        .width($(".current").parent().width())
        .height($('.coda-nav').height())
        .css("left", $(".current").position().left)
        .data("origLeft", $magicLine.position().left)
        .data("origWidth", $magicLine.width());




$(".coda-nav li").find("a").click(function() {

        $el = $(this);
        leftPos = $el.position().left;
        newWidth = $el.parent().width();

        $magicLine.stop().animate({
            left: leftPos,
            width: newWidth
        });

        $(".coda-nav li a").not('.current').animate({
            color: "#2a2a2a"
        }, 600 );

        $(this).animate({
            color: "#F11931"
        }, 600 );

    }, function() {
        $magicLine.stop().animate({
            left: $magicLine.data("origLeft"),
            width: $magicLine.data("origWidth")
        }, 1000);


    });


}
});




