$(window).load(function() {
    $('#slider').nivoSlider( );
});






/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

// Ride the carousel...
jQuery(document).ready(function() {

    jQuery('ul.nav > li').hover(function(){
        if(!$(this).hasClass('active'))
        jQuery('ul.nav li.active ul').css('display','none');
    },
    function(){
        jQuery('ul.nav li.active ul').css('display','block');
    });
	
    /*jQuery("#mycarousel").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });*/		$('#mycarousel ul').css({width: 310*$('#mycarousel li').length + "px", height:"130px"});	$('#mycarousel').jScrollPane({scrollbarWidth:28, showArrows:true, animateStep:309, arrowButtonSpeed:309});

    //Если картинок в карусели меньше 3 то мы прячем панель управления
    jQuery("li.jcarousel-list").ready(function(){
        if($(this).find('li.jcarousel-item').length <4){
            $('.jcarousel-scroll').css('visibility','hidden');
        }
    });

    $('.pluses').ready(function(){
      //$('.pluses li').corner('round 4px');
    });
    $('.people_img').ready(function(){
		//$('.people li img').corner('round 50px');
    });


});
$(document).ready(function() {

	$('.vac_title').click( function (){
		$(this).toggleClass('close');
		$(this).next('.vac_text').toggleClass('close');
	});
	
	$('.opt_title').click( function (){
		$(this).toggleClass('close');
		$(this).next('.opt_text').toggleClass('close');
	});

	$('input').each( function() {
		if ($(this).val() != "") $(this).addClass('focus');
	});
	$('input').focus( function() {
		$(this).addClass('focus');
	});
	$('input').blur( function() {
		if ($(this).val() == "") $(this).removeClass('focus');
	});
	$('.input_f').change( function() {
		$(this).parents('.line').find('input[type="text"]').val($(this).val()).addClass('focus');
	});
	
	/*
	$('#sl_img .prev').click( function() {
		var prev = $('#sl_i img:visible').prev('img');
		if ( prev.length <=0 ) prev = $('#sl_i img:last');
		prev.removeClass('hide').siblings('img').addClass('hide');
		$('#sl_name').text( prev.attr('alt') );
	});
	
	$('#sl_img .next').click( function() {
		var next = $('#sl_i img:visible').next('img');
		if ( next.length <=0 ) next = $('#sl_i img:first');
		next.removeClass('hide').siblings('img').addClass('hide');
		$('#sl_name').text( next.attr('alt') );
	});
	*/
	
	
	var sl = $('#sl_img');
	var len = $('#sl_i .sl_i_cont a').length;
	var ul = $('#sl_i .sl_i_cont');

	if ( len>1 ) {
		sl.find('span').show();
		var s_left = sl.find('span.prev');
		var s_right = sl.find('span.next');
		
		s_left.bind('click', function() {
			var a = ul.find('a:eq(0)');
			var tit = a.find('img').attr('alt');
			a
				.animate({ marginLeft:"-390px"}, 300, function() {
					a.appendTo(ul).css('marginLeft','0');
				});
			$('#sl_name').text(tit);
		});

		s_right.bind('click', function() {
			var a = ul.find('a:last');
			var tit = a.find('img').attr('alt');
			a.prependTo(ul).css('marginLeft','-390px');
			a.animate({ marginLeft:'0'}, 300);
			$('#sl_name').text(tit);
		});
	} else {
		sl.find('span').hide();
		}							$('.more_btn a').live('click', function() {		var hr = $(this).attr('href');		var th = $(this);		th.css('visibility', 'hidden');		$.ajax({			url: hr,			success: function(data){				var html = $(data).find('.portf').html();				var more = $(data).find('.more_btn');				$(html).appendTo('.portf');				$(more).insertAfter('.portf');				th.parent().remove();			},			error: function() {				document.location = hr;			}		});		return false;	});
	
	$('#works ul, #works .more').hide();
	$('#works h2').css('cursor', 'pointer');
	
	scr_el();
	$(window).scroll(function () {
		scr_el();
	});
	
	$('#works h2').click( function() {
		var th = $(this);
		th.hasClass('open')?$('#works ul, #works .more').slideUp(500, function(){ th.removeClass('open');}) : $('#works ul, #works .more').slideDown(500, function(){ th.addClass('open');});
	});
});

function scr_el() {
	var el = document.getElementById('works');
	var el2 = document.getElementById('content');
	var scrollPos = document.documentElement.scrollTop;
	if (scrollPos == 0) { scrollPos = document.body.scrollTop; }
	if ( scrollPos >= 189 ) { //el2.offsetTop
		el.className = "works_s fixed";
	} else {
		el.className = "works_s";
	}
}
