$(document).ready(function(){
    setTimeout("rotate_services()",5000);
    if($("#service_menu")){
        setTimeout("show_service_menu()",500);
    }

    if($("#project_menu")){
        setTimeout("show_project_menu()",500);
    }

    if($(window).scrollTop()>0){
        var scroll_top = $(window).scrollTop()+30;
        //$("#left_menu").css("marginTop", scroll_top);
    }

    $(window).scroll(function(){
        var scroll_top = $(window).scrollTop()+30;
        //$("#left_menu").css("marginTop", scroll_top);
    });
});

function rotate_services(){
    if($(".service").length>3){
        $(".service").first().next().next().next().css({opacity: "0"});
        $(".service").first().next().next().next().animate({opacity: "1"}, 1000);
        $(".service").first().animate({marginLeft: "-233px", opacity: "toggle" }, 1000, "linear", function(){
            $(".service").first().next().animate({marginTop: "10px"});
            $(".service").first().next().next().animate({marginTop: "0px"});
            $("#services").append('<div class="service">'+$(".service").first().html()+'</div>');
            $(".service").last().css("background-image",$(".service").first().css("background-image"));
            $(".service").last().css("background-repeat","no-reapeat");
            $(".service").last().css("margin-top","10px");
            $(".service").first().remove();

            setTimeout("rotate_services()",5000);
        });
    }
}

function rotate_contact_pictures(){
    if($(".contact_picture").length>1){
        $(".contact_picture").first().next().hide();
        $(".contact_picture").first().fadeOut(1000, function(){
            $(".contact_picture").first().next().fadeIn(1000, function(){
                $("#contact_pictures").append('<div class="contact_picture">'+$(".contact_picture").first().html()+'</div>');
                $(".contact_picture").first().remove();

                setTimeout("rotate_contact_pictures()",5000);
            });
        });
    }
}

function show_service_menu(){
    $("#service_menu").slideDown("slow");
}

function show_project_menu(){
    $("#project_menu").slideDown("slow");
}

$(function() {
$("#footer_images img").css("opacity","0.4");

$("#footer_images img").hover(function () {

$(this).stop().animate({
opacity: 1.0
}, "fast");
},

function () {

$(this).stop().animate({
opacity: 0.4
}, "slow");
});
});

function validateForm()
{
var is_valid = true;
var your_name_value=document.getElementById('your_name').value;
	if (your_name_value.length<3 || your_name_value=="Your Name")
	  {
	  is_valid = false;
	  document.getElementById('your_name').style.color = '#ff9900';
	  }
	  else{
	  document.getElementById('your_name').style.color = '#7b7b7b';
	  }
var your_email_value=document.getElementById('your_email').value;
var atpos=your_email_value.indexOf("@");
var dotpos=your_email_value.lastIndexOf(".");
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=your_email_value.length)
	  {
	  is_valid = false;
	  document.getElementById('your_email').style.color = '#ff9900';
	  }
	  else{
	  document.getElementById('your_email').style.color = '#7b7b7b';
	  }
var message_value=document.getElementById('message').value;
	if (message_value.length<10 || message_value=="Message")
	  {
	  is_valid = false;
	  document.getElementById('message').style.color = '#ff9900';
	  }
	  else{
	  document.getElementById('message').style.color = '#7b7b7b';
	  }
var security_code_value=document.getElementById('security_code').value;
	if (security_code_value.length<4 || security_code_value.length>4 || security_code_value=="Security Code")
	  {
	  is_valid = false;
      document.getElementById('security_code').style.color = '#ff9900';
	  }
	  else{
	  document.getElementById('security_code').style.color = '#7b7b7b';
	  }
	  if(is_valid){
	  return true;
	  }
	  else{
	  return false;
	  }
}

function theRotator() {
	// Устанавливаем прозрачность всех картинок в 0
	$('div#contact_rotator ul li').css({opacity: 0.0});

	// Берем первую картинку и показываем ее (по пути включаем полную видимость)
	$('div#contact_rotator ul li:first').css({opacity: 1.0});

	// Вызываем функцию rotate для запуска слайдшоу, 5000 = смена картинок происходит раз в 5 секунд
	setInterval('rotate()',5000);
}

function rotate() {

	var current = ($('div#contact_rotator ul li.show')?  $('div#contact_rotator ul li.show') : $('div#contact_rotator ul li:first'));

	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#contact_rotator ul li:first') :current.next()) : $('div#contact_rotator ul li:first'));

	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};

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

var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
 return false;
}
function mousehandler(e){
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
  if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;

function preventSelection(element){
  var preventSelection = false;

  function addHandler(element, event, handler){
    if (element.attachEvent)
      element.attachEvent('on' + event, handler);
    else
      if (element.addEventListener)
        element.addEventListener(event, handler, false);
  }
  function removeSelection(){
    if (window.getSelection) { window.getSelection().removeAllRanges(); }
    else if (document.selection && document.selection.clear)
      document.selection.clear();
  }
  function killCtrlA(event){
    var event = event || window.event;
    var sender = event.target || event.srcElement;

    if (sender.tagName.match(/INPUT|TEXTAREA/i))
      return;

    var key = event.keyCode || event.which;
    if (event.ctrlKey && key == 'A'.charCodeAt(0))  // 'A'.charCodeAt(0) можно заменить на 65
    {
      removeSelection();

      if (event.preventDefault)
        event.preventDefault();
      else
        event.returnValue = false;
    }
  }
  addHandler(element, 'mousemove', function(){
    if(preventSelection)
      removeSelection();
  });
  addHandler(element, 'mousedown', function(event){
    var event = event || window.event;
    var sender = event.target || event.srcElement;
    preventSelection = !sender.tagName.match(/INPUT|TEXTAREA/i);
  });
  addHandler(element, 'mouseup', function(){
    if (preventSelection)
      removeSelection();
    preventSelection = false;
  });
  addHandler(element, 'keydown', killCtrlA);
  addHandler(element, 'keyup', killCtrlA);
}

preventSelection(document);
