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

	/* Drop Down Menu */
	$menu = jQuery("#mainmenu li");
	$menu.each(function() {
		$menuitem = jQuery(this);
		$menuitem.mouseenter( function() {
			jQuery(this).children("ul").fadeIn(200);
		}).mouseleave( function() {
			jQuery(this).children("ul").fadeOut(200);
		});
	});
	
	/* Homepage Slider */
	jQuery("#slideshow").wenSlider({
		newsWidth: 617,
		effect: 'fade',
		autoStart: 10000
	});
	
	
	/* Quotes Slider */
	jQuery("#quotes_slider").wenSlider({
		newsWidth: 300,
		effect: 'slide',
		autoStart: 0,
		container: '.quotes-container',
		nextbutton: '.next-quote',
		prevbutton: '.prev-quote'
	});
	
	
	/* Class Accordion */
	jQuery(".accordion-show").click(function() {
		$d = jQuery(".accordion-details", jQuery(this).closest("div, li"));
		if($d.css("display") == "none") $d.slideDown(400);
		else $d.slideUp(400);
		return false;
	});
	
	
	/* Class Accordion */
	jQuery(".showdetails").click(function() {
		$d = jQuery(".class-details", jQuery(this).closest("li"));
		if($d.css("display") == "none") $d.slideDown(400);
		else $d.slideUp(400);
		return false;
	});
	
	
	
	
	/**
	 * FancyBox
	 */
	jQuery.fn.getTitle = function() {
		var arr = jQuery("a.fancybox");
		jQuery.each(arr, function() {
			var title = jQuery(this).children("img").attr("title");
			jQuery(this).attr('title',title);
		})
	}

	// Supported file extensions
	var thumbnails = 'a:has(img)[href$=".bmp"],a:has(img)[href$=".gif"],a:has(img)[href$=".jpg"],a:has(img)[href$=".jpeg"],a:has(img)[href$=".png"],a:has(img)[href$=".BMP"],a:has(img)[href$=".GIF"],a:has(img)[href$=".JPG"],a:has(img)[href$=".JPEG"],a:has(img)[href$=".PNG"]';


	jQuery(thumbnails).addClass("fancybox").attr("rel","fancybox").getTitle();

	jQuery("a.fancybox").fancybox({
		'imageScale': true,
		'padding': 10,
		'zoomOpacity': true,
		'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		'zoomSpeedChange': 300,
		'overlayShow': true,
		'overlayColor': "#666666",
		'overlayOpacity': 0.3,
		'enableEscapeButton': true,
		'showCloseButton': true,
		'hideOnOverlayClick': true,
		'hideOnContentClick': false,
		'frameWidth':  560,
		'frameHeight':  340,
		'centerOnScroll': true
	});
 
	
	jQuery("a.show-teacher-profile").attr('rel', 'gallery').fancybox({
		'imageScale': true,
		'padding': 10,
		'overlayShow': true,
		'overlayColor': "#666666",
		'overlayOpacity': 0.3,
		'enableEscapeButton': true,
		'showCloseButton': true,
		'hideOnOverlayClick': true,
		'hideOnContentClick': false,
		'frameWidth':  800,
		'frameHeight':  500,
		'callbackOnStart': null,
		'callbackOnShow': null,
		'callbackOnClose': null,
		'centerOnScroll': true
	});
	
	jQuery(".overlink, .maplink").fancybox({
		'type' : 'iframe',
		'imageScale': true,
		'padding': 10,
		'overlayShow': true,
		'overlayColor': "#666666",
		'overlayOpacity': 0.3,
		'enableEscapeButton': true,
		'showCloseButton': true,
		'hideOnOverlayClick': false,
		'hideOnContentClick': false,
		'width':  720,
		'height':  480,
		'callbackOnStart': null,
		'callbackOnShow': null,
		'callbackOnClose': null,
		'centerOnScroll': true
		
	});
	
	
	
	
	
	/**
	 * Show Division 
	 */
	jQuery(".showdivision").click(function() {
		$d = jQuery(".teacherslist", jQuery(this).parent());
		if($d.css("display") == "none") $d.slideDown(500);
		else $d.slideUp(500);
		return false;
	});

	
	
	/* CSS Hacks */
	jQuery(".biggreen").each(function(){
		$offsetLeft = jQuery(this).width(); 
		console.log($offsetLeft); 
	}); 
	jQuery("div.menu ul li:last-child").css("border-right", "none");
	jQuery("#mainmenu li:last-child").addClass("last-menu-item");
	jQuery("#topmenu li:last-child a, #splashtabs li:last-child").css("border-right", "none");	
	jQuery(".splash-up").slideUp(500);
	
	$("#mainmenu li li.active").closest("li.parent").addClass("current_page_item"); 
		
});



function switchTabs($tab, $banner) {
	$active = jQuery("#splash div.active");
	
	$next = jQuery("#"+$banner);
	
	
	/* Switch Tab */
	jQuery("#splashtabs li").removeClass("active");
	jQuery($tab).closest("li").addClass("active");
	
	
	/* Switch Banner */
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 500, function() {
			if(!$next.hasClass("last-active")) {
				$active.removeClass('active last-active').css("opacity", 0);
			}
	});
	
}
