﻿// Функция определения IE6
function detectIE6(){
  var browser = navigator.appName;
  if (browser == "Microsoft Internet Explorer"){
    var b_version = navigator.appVersion;
    var re = /\MSIE\s+(\d\.\d\b)/;
    var res = b_version.match(re);
    if (res[1] <= 6){
      return true;
    }
  }
  return false;
}

var imgs = 'apia/template/visual/imgs';
var i = 0;

$(document).ready(function(){
 // Визуальная составляющая
  // Меню   
  $("#menu_p_1")
	.mouseenter(function(){	$("#p_1").stop(true, true).fadeOut("slow"); })
	.mouseleave(function(){	$("#p_1").stop(true, true).fadeIn("slow"); })
	.click(function(){	window.location.href = document.links[0].href; });
  $("#menu_p_2")
	.mouseenter(function(){	$("#p_2").stop(true, true).fadeOut("slow"); })
	.mouseleave(function(){	$("#p_2").stop(true, true).fadeIn("slow"); })
	.click(function(){	window.location.href = document.links[1].href; });
  $("#menu_p_3")
	.mouseenter(function(){	$("#p_3").stop(true, true).fadeOut("slow"); })
	.mouseleave(function(){	$("#p_3").stop(true, true).fadeIn("slow"); })
	.click(function(){	window.location.href = document.links[2].href; });
  $("#menu_p_4")
	.mouseenter(function(){	$("#p_4").stop(true, true).fadeOut("slow"); })
	.mouseleave(function(){	$("#p_4").stop(true, true).fadeIn("slow"); })
	.click(function(){	window.location.href = document.links[3].href; });
  $("#menu_p_5")
	.mouseenter(function(){	$("#p_5").stop(true, true).fadeOut("slow"); })
	.mouseleave(function(){	$("#p_5").stop(true, true).fadeIn("slow"); })
	.click(function(){	window.location.href = document.links[4].href; });
  $("#menu_p_6")
	.mouseenter(function(){	$("#p_6").stop(true, true).fadeOut("slow"); })
	.mouseleave(function(){	$("#p_6").stop(true, true).fadeIn("slow"); })
	.click(function(){	window.location.href = document.links[5].href; });
  
  // Эй DJ! Крути свое д...о
  function carouselfunc() {
	  $("#carousel").animate({ marginLeft: -$("#carousel :first").width()-10+'px' }, ($('#carousel :first').width() + parseInt($('#carousel').css('marginLeft'), 10))*20, 'linear',
		function() {
			$('#carousel li:first').clone().appendTo('#carousel');
			$('#carousel li:first').remove();
			$('#carousel').css('marginLeft', '0');
			carouselfunc();
		}
	  );
  }
  $("#carousel")
	.mouseenter(function(){ $("#carousel").stop(); })
	.mouseleave(function(){ carouselfunc(); });
	
	function showCarousel() {
		$('#hide_carousel').click(function() {
		  $('#hide_carousel').fadeOut();
		 $('#made_us').stop(true, true).slideDown('slow', function() {
		  carouselfunc();
		 });
		});	
	}
	function hideCarousel() {
		$('#hide_carousel').click(function() {
		  $('#hide_carousel').fadeOut();
		 $('#made_us').stop(true, true).slideUp('slow', function() {
		  $("#carousel").stop();
		 });
		});	
	}
	
  // Пряталки с каруселью
  if ($('#hide_carousel').text() == 'Показать блок') { showCarousel(); } else { carouselfunc(); hideCarousel(); }
});
