$(document).ready(function(){
	var call_top = parseInt($(window).height()/2-67); 
	$('#call').css({'top':call_top+'px'});

	$('div.nav-wrap').stickyit({
		gap: 0,
			stickyclass: "docked"
	});

jQuery.preloadImages = function() {
   jQuery.each (arguments,function (e) {
       jQuery("<img>").attr("src", this);
   });
   return true;
}
$.preloadImages("/images/header.png");

$("span.akcii").click(function(){
$("div.allakcii").slideToggle("slow");
return false;
});

$("div[hrf]").each(function(){
$(this).wrap('<a href="'+$(this).attr("hrf")+'"></a>');
});
$("span[hrf]").each(function(){
$(this).wrap('<a href="'+$(this).attr("hrf")+'"></a>');
});
$("img[hrf].portf").each(function(){
$(this).wrap('<a href="'+$(this).attr("hrf")+'" class="fancyclass" rel="portfolio"></a>');
});
$("img[hrf].lnk").each(function(){
$(this).wrap('<a href="'+$(this).attr("hrf")+'" class="fancyclass" title="'+$(this).attr("alt")+'"></a>');
});

if ( $("li.current_page_item_two").length ) {
var cl = $("li.current_page_item_two a").attr('rel');
$("#head_phone").css('color',cl);
}


 var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
   if (badBrowser) {
     $('#example-two li').css({'display': 'inline', 'zoom': '1'});
   }
   
    var $el, leftPos, newWidth,
        $mainNav2 = $("#example-two");

    /*
        EXAMPLE TWO
    */
    $mainNav2.append("<li id='magic-line-two'></li>");
    
    var $magicLineTwo = $("#magic-line-two");
    if ( $("li.current_page_item_two").length ) {
    $magicLineTwo
        .width($("li.current_page_item_two").width())
        .height('30')
        .css("left", $("li.current_page_item_two a").position().left)
        .data("origLeft", $("li.current_page_item_two a").position().left)
        .data("origWidth", $magicLineTwo.width())
        .data("origColor", $("li.current_page_item_two a").attr("rel"));
		$("#example-two #magic-line-two").css('background-color',$magicLineTwo.data("origColor"));
    }else{
    $magicLineTwo
        .width('0')
        .height('30') 
        .css("left", '214')  
        .data("origLeft", '214')
        .data("origWidth", $magicLineTwo.width())
        .data("origColor", "#303030");    
    }     
    $("#example-two li").find("a").hover(function() {
        $el = $(this);
        leftPos = $el.position().left;
        newWidth = $el.parent().width();
        $magicLineTwo.stop().animate({
            left: leftPos,
            width: newWidth,
            backgroundColor: $el.attr("rel")
        })
    }, function() {
        $magicLineTwo.stop().animate({
            left: $magicLineTwo.data("origLeft"),
            width: $magicLineTwo.data("origWidth"),
            backgroundColor: $magicLineTwo.data("origColor")
        });    
    });

  $("a:has(img)").css("border","0");
   
  $.localScroll();  
  $.localScroll.hash();
  
$('table.price2 td,table.price2 th').hover(function() {
var n = $(this).attr('class');
$('.'+n).addClass('hover_price2');
}, function() {
$('.hover_price2').removeClass('hover_price2');
});  

$('div.clients img').hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});

if ( $("a.fancyclass").length ) {$("a.fancyclass").fancybox({
 		'zoomSpeedIn'			: 600,
 		'zoomSpeedOut'			: 500,
 		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
 		'overlayShow': true,
 		'overlayColor'		: '#000',
    'titlePosition'	: 'inside',
    'overlayOpacity': 0.7,
 		'imageScale': true,
 		'centerOnScroll':true
});}

$.get("/js/callform_html.txt", function(data){
$("body").prepend(data);
$("#call_form").livequery();
});

if ( $("#need_call").length ) {
	
$("#need_call").fancybox({
	'scrolling'		: 'no',
	'titleShow'		: false
});

	$("#call_form").livequery(function() {
		$(this).validate({
			rules: {		
				call_name: {
					required: true,
					minlength: 3
				},				
				call_phone: {
					required: true,
					minlength: 7
				}
			}
		});
	
		$(this).bind("submit", function() {
			if ($("#call_form").valid()) {
			$.fancybox.showActivity();
			$.ajax({
				type: "GET",
				cache: false,
				url: "/js/callform.php",
				data: $(this).serializeArray(),
				success: function(data) {
					$.fancybox(data);
				}
			});
			}
			return false;
		});	
	});
}

if ( $("div#makeMeScrollable").length ) {
$("div#makeMeScrollable").smoothDivScroll({ autoScroll: "onstart", 
														autoScrollDirection: "backandforth",
														autoScrollStep: 1,
														autoScrollInterval: 15,  
														visibleHotSpots: "always" });

}

	$('#sertifikat').panelGallery({
		viewDuration: 3000,
		transitionDuration: 500,
		boxSize: 30,
		boxFadeDuration: 500,
		boxTransitionDuration: 50,
		pauseOnHover:false
	}); 


	if ( $('div.clients img').length ) {
		$('div.clients img').tipTip({maxWidth: '600px', edgeOffset: 10, delay: 100, attribute: 'alt'});
	}	

	if ( $('#head_phone').length ) {
		$('#head_phone').tipTip({maxWidth: '290px', edgeOffset: 5, delay: 10, content: '<center><span style="text-align:center;font-size:1.1em;">Менеджер готов ответить на Ваши вопросы.<br>Звоните!</span></center>'});
	}
	$("a.faq").click(function(){
		var yakor = $(this).attr('href').split('#');
		$("#"+yakor[1]).animate(
		{backgroundColor: '#99ff99'}, 1200, function()
			{$(this).animate(
			{backgroundColor: '#ffffff'}, 100, function()
			{$(this).animate(
			{backgroundColor: '#99ff99'}, 600, function()
			{$(this).animate(
			{backgroundColor: '#ffffff'}, 100, function()
			{$(this).animate(
			{backgroundColor: '#99ff99'}, 300, function()
			{$(this).animate(
			{backgroundColor: '#ffffff'}, 100) 
			})})})})});
	});
});
