$(document).ready(function() {
	
	$('#l_tog').click(function(){
		$('.tog_links').slideToggle();
	});
	
    $("#subscribeform").ajaxForm({
        complete: function(xhr){
			if(xhr.status == 200){
				$.fancybox({
					'content' : xhr.responseText,
					'autoDimensions' : false,
					'width' : 500,
					'height' : 400
				});
			}
        }
    }); 
						   
  var animationSpeed = 200;
  var sceneDelay = 5000;

  /* HOME ANIMATION */
  function contentRotate(feature) {
    if (doAnimate) {
      feature.fadeOut(animationSpeed, function (feature) {
        return function () {
          $(".feature_content div").hide();

          /* HIGHLIGHT RELEVANT CONTROL */
		  $(".feature_nav .on").removeClass("on");
		  var selector = '.feature_nav a[href*="#' + $(this).attr("id") + '"]';
		  $(selector).addClass('on');
          /*if ($(this).attr("id") == "feature_one") {
            $(".feature_nav .on").removeClass("on");
            $(".home_one").addClass("on");
          }
          else if ($(this).attr("id") == "feature_two") {
            $(".feature_nav .on").removeClass("on");
            $(".home_two").addClass("on");
          }
          else if ($(this).attr("id") == "feature_three") {
            $(".feature_nav .on").removeClass("on");
            $(".home_three").addClass("on");
          }*/

          /* FADE IN NEXT ITEM OR GO BACK TO FIRST */
          feature.fadeIn("fast", function () {
            if ($(this).attr("id") == $(".a_feature:last").attr("id")){
              setTimeout(function () {
                contentRotate($(".feature_content div:first"));
              }, sceneDelay);
            }
            else {
              setTimeout(function () {
                contentRotate($(feature.next()));
              }, sceneDelay);
            }
          });
        };
      }(feature));
    }
  }

  /* HOME FEATURES */
  $(".feature_nav a").hover(function() {
	if (allowSwitch && !$($(this).attr('href')).is(':visible')) {
		var current = $(this).attr("title");
		$(".feature_nav .on").removeClass("on");
		$(this).addClass("on");
		doAnimate = false;
		allowSwitch = false;
		$('.feature_content div').hide();
		$($(this).attr('href')).fadeIn(animationSpeed, function(){
												    allowSwitch = true;
												  });
	}
  });

  $(".feature_nav a").click(function() {
    return false;
  });

  var doAnimate = true;
  var allowSwitch = true;

  contentRotate($(".feature_content div:first"));
/*
  $(".home_one").hover(function() {
	if (allowSwitch) {
		doAnimate = false;
		allowSwitch = false;
		$("#feature_two").hide();
		$("#feature_three").hide();
		$("#feature_one").fadeIn(animationSpeed, function(){
												    allowSwitch = true;
												  });
	}
  });
  
  $(".home_two").hover(function() {
	if (allowSwitch) {
		doAnimate = false;
		allowSwitch = false;
		$("#feature_one").hide();
		$("#feature_three").hide();
		$("#feature_two").fadeIn(animationSpeed, function(){
												    allowSwitch = true;
												  });
	}
  });
  
  $(".home_three").hover(function() {
	if (allowSwitch) {
		doAnimate = false;
		allowSwitch = false;
		$("#feature_two").hide();
		$("#feature_one").hide();
		$("#feature_three").fadeIn(animationSpeed, function(){
												    allowSwitch = true;
												  });
	}
  });
  */
  /*$(".feature_nav a").hover(function() {
	if (allowSwitch) {
		doAnimate = false;
		//allowSwitch = false;
		$(".feature_content div").hide();
		$(this.attr("href")).fadeIn(animationSpeed, function(){
												    allowSwitch = true;
												  });
	}
  });*/

});

function popUp(URL,width,height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height=" + height + "');");
}

function emptybox(what,which){
	if (what.value == which){
		what.value = '';
	}
}

