$(document).ready(function(){
	initTargetBlanks();
	initSearch();
	initTest();
	initSlider();

  $(".signup").click(function(){
    $(".super_popup").fadeIn(400)
    $(".super_popup .popup_inner").css("margin-top",(-1)*parseInt($(".super_popup_"+sbt_id+" .popup_inner").height()/2));
    return false;
  });
  $(".close").live('click',function(){
    $(".super_popup").fadeOut(400);
  });

  $(".first-level").each(function(){
    if($(this).next().find("li span").hasClass("selected")){
      $(this).children().addClass("active");
    }
  });

  $('.icon-clock').parent().hover(
    function(){
      $('.bg_clock').fadeIn(10);
    },function(){
      $('.bg_clock').fadeOut(10);
  });

  $("a.gallery").fancybox();

  $("#main_menu ul li").hover(
    function(){
      $(this).children(".first-level").addClass("active");
      $(this).children(".second-level").css("display","block");
    },function(){
      $(this).children(".first-level").removeClass("active");
      $(this).children(".second-level").css("display","none");
  });

  $(".second-level ul li").hover(
    function(){
      if(!$(this).children("span").hasClass("selected")){
        $(this).addClass("active");
      }
    },function(){
      $(this).removeClass("active");
  });

    $(".tabs li").hover(
      function(){
        if (!$(this).hasClass("active")){
        $(this).addClass("hover");
      }},function(){
        $(this).removeClass("hover");
    });

    $(".tabs li").click(function(){
		if (!($(this).hasClass("active"))){
			var i = $(".tabs li").index($(this));

			$(".tabs li").removeClass("active");
			$(this).addClass("active").removeClass("hover");

			$(".tabs_wrap .tab").removeClass("active");
			$(".tabs_wrap .tab").eq(i).addClass("active");
	   }
     });
    $(".tabs li:first-child").click();

    $(".click").click(function(){
      if (!$(this).hasClass("active")){
        $(".click").removeClass("active");
        $(".none").hide();
        $(this).addClass("active");
        $(this).next(".none").slideDown(500);
      } else {
        $(this).removeClass("active");
        $(this).next(".none").slideUp(500);
      }
    });

    $(".up").click(function(){
      $("html,body").stop().animate({scrollTop: 420},600);
      return false;
    });
    
    $(".slide_down").click(function(){
      $(this).parent().next(".invisible").slideDown(500);
      $(this).css("display","none");
    });
    $(".turn_up").click(function(){
      $(this).parent().slideUp(500);
      $(".slide_down").css("display","inline");
    });

    $(".table table tr:nth-child(2n)").css("background","#f6f6f6");
    $(".table table tr:first-child").css("border-top","none");
    $(".table table tr td:first-child").css({textAlign: "left", border: "none"});
    $(".second-level ul li:last-child").css("border","none");
    $(".second-level ul li.active:last-child").css("padding-bottom","0");

    $("p.slide_me").click(function() {
        if (!$(this).hasClass("active")) {
            $(this).next().slideDown(600);
            $(this).addClass("active");
        } else {
            $(this).next().slideUp(600);
            $(this).removeClass("active");
        }
    });
  
});

initTargetBlanks = function(){
	$(".target_blank").click(function(){
		window.open($(this).attr("href"));
		return false;
	});
}

initSearch = function(){
	$(".search input.input").focus(function(){
		if ( $(this).attr("title") == $(this).attr("value") ){
			$(this).attr({"value": ""});
		}
	});
	$(".search input.input").blur(function(){
		 if ( !$(this).attr("value")){
			var defText = $(this).attr("title");
			$(this).attr({"value": defText});
			}
	});
	$(".search input.submit").click(function(){
		if ( $(".search input.input").attr("title") == $(".search input.input").attr("value") ){
			return false;
		} else {
            $(".search").submit();
        }
	});
}

initTest = function(){
// Anything slider
var animate1;
	GoToNextPage = function(el){
		$(el).find(".arrow.forward").click();
		animate1 = setTimeout("GoToNextPage('.anythingSlider')", 6200);
	}
	function formatText(index, panel) {
		return index + "";
	}
	$(function () {
		$('.anythingSlider').anythingSlider({
			easing: "easeInOutExpo", // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true, // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 4000, // How long between slide transitions in AutoPlay mode
			startStopped: false, // If autoPlay is on, this can force it to start stopped
			animationTime: 800, // How long the slide transition takes
			hashTags: true, // Should links change the hashtag in the URL?
			buildNavigation: true, // If true, builds and list of anchor links to link to each slide
			pauseOnHover: true, // If true, and autoPlay is enabled, the show will pause on hover
			navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
		});
	});
}

initSlider = function(){
	$(".anythingSlider").hover(
		function(){
	$("#start-stop").click();
		},function(){
		$("#start-stop").click();
	});
}

