$(function(){
  $(".hover").hover(function(){$(this).addClass("mouseover");},function(){$(this).removeClass("mouseover")});
});

$(function(){
  $(".hidden_list_tab").click(function(){$(this).siblings(".hidden_list").show();$(this).hide()});
});

$(function(){
	h = $("ul#dropdown_tabs > li").css("height");
	$("ul#dropdown_tabs > li").mouseenter(function(){
		$(this).stop(true,true).animate({height:'50px'},100,"swing",function(){$(this).children("ul").stop(true,true).slideDown(200)});
		$(this).children("a.tab").stop(true,true).animate({top:'10px'},100,"swing");
		$(this).css("background-color","#1d75bc");
		$(this).children("a.tab").css("color","#eee");
		
	});
	$("ul#dropdown_tabs > li").mouseleave(function(){
		$(this).stop(true,true).animate({height:h},200,"swing",function(){$(this).children("ul").stop(true,true).hide()});
		$(this).children("a.tab").stop(true,true).animate({top:'0px'},100,"swing");
		$(this).css("background-color","transparent");
		$(this).children("a.tab").css("color","#1d75bc");
	});
});

//slider
$(document).ready(function(){
  var currentPosition = 0;
  var slideWidth = 800;
  var slides = $('.slide');
  var numberOfSlides = slides.length;
  var autoProgressInterval = 5000;
  var autoProgressRestartInterval = 15000;

  // Remove scrollbar in JS
  $('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
  .wrapAll('<div id="slideInner"></div>')
  // Float left to display horizontally, readjust .slides width
  .css({
    'float' : 'left',
    'width' : slideWidth
  });

  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert left and right arrow controls in the DOM
  $('#slideshow')
    .prepend('<span class="control" id="leftControl">Move left</span>')
    .append('<span class="control" id="rightControl">Move right</span>');

  restartAutoProgress=0;
  autoProgress = setInterval(function(){
    currentPosition+=1;
    if(currentPosition > numberOfSlides-1) {currentPosition = 0;}
    if(currentPosition < 0) {currentPosition = numberOfSlides-1;}
    // Move slideInner using margin-left
    $('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
  }, autoProgressInterval );

  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){
    // Determine new position
      currentPosition = ($(this).attr('id')=='rightControl')
    ? currentPosition+1 : currentPosition-1;

  if(currentPosition > numberOfSlides-1) {currentPosition = 0;}
  if(currentPosition < 0) {currentPosition = numberOfSlides-1;}
  clearInterval(autoProgress);
  if(restartAutoProgress){clearInterval(restartAutoProgress);}
  restartAutoProgress = setInterval(function(){clearInterval(restartAutoProgress);
    autoProgress = setInterval(function(){
    currentPosition+=1;
    if(currentPosition > numberOfSlides-1) {currentPosition = 0;}
    if(currentPosition < 0) {currentPosition = numberOfSlides-1;}
    // Move slideInner using margin-left
    $('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
    }, autoProgressInterval );
  },autoProgressRestartInterval );

      // Move slideInner using margin-left
      $('#slideInner').animate({
        'marginLeft' : slideWidth*(-currentPosition)
      });
    });

  });

//tabs
$(document).ready(function(){
	$("#tab-area > .tabs > .tab").hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});
	$("#tab-area > .tab-content > div").hide();
	$("#tab-area > .tabs > .tab").each(
		function(){
			$(this).click(function(){
				$("#tab-area > .tab-content > div").hide();
				$($(this).attr("href")).show();
				$("#tab-area > .tabs > .tab").removeClass("selected");
				$(this).addClass("selected");
			});
		}
	);
	$("#tab-area > .tabs > .tab").first().click();	
});
