﻿jQuery(document).ready(function() {

  /////////////////////
  // MEGA NAVIGATION
  function addMega(){
    $(this).addClass("hovering");
    }
  function removeMega(){
    $(this).removeClass("hovering");
    }
  var megaConfig = {
    interval: 5,
    sensitivity: 15,
    over: addMega,
    timeout: 50,
    out: removeMega
  };
  $("li.mega").hoverIntent(megaConfig)
  
  /////////////////////
  // VIEW
  $(".view_content").hide();
	$("ul.views li.button:first").addClass("active").show();
	$(".view_content:first").show();
  
	$("ul.views li.button").click(function() {
    $("ul.views li.button").removeClass("active");
    $(this).addClass("active");
    $(".view_content").hide();
    var activeView = $(this).find("a").attr("href"); 
    $(activeView).fadeIn();
    return false;
	});
  
  /////////////////////
  // HIGHLIGHTS
    
  function imgResize(w, h,img) {
		var maxWidth = w;
		var maxHeight = h;
		var ratio;
		var width = $(img).width();
		var height = $(img).height();
		
		if(width > maxWidth) {
			ratio = maxWidth/width;
			$(img).css("width", maxWidth);
			$(img).css("height", height * ratio);
			height = height * ratio;
			width = width * ratio;
		}
		if(height > maxHeight) {
			ratio = maxHeight/height;
			$(img).css("height", maxHeight);
			$(img).css("width", width * ratio);
			width = width * ratio;
		}
	}
  
  $('.overview .small img').each(function() {
    imgResize(100,75, this)
  });
  
  $("div.overview:first").addClass("extended");
  
  $('.overview').click(function(){
    $(".overview").removeClass("extended");
    $(this).addClass("extended");
	});
  
});
