jQuery(document).ready(function(){

// ---------------------------------------------------------------------------------------------------------------------------
	//Sidebar Accordion Menu:
	jQuery(".sub-level-0 ul").hide(); // Hide all sub menus
	jQuery("ul#nav-sub li.here").parent().show(); // Slide down the current menu item's sub menu
	jQuery("ul#nav-sub li.here ul").show(); // Slide down the current menu item's sub menu if its a parent

	jQuery(".sub-level-0 ul").parent().find(":first").click( // When a top menu item that has a sub-nav is clicked...
		function () {
			jQuery(this).parent().siblings().find("ul").slideUp("normal"); // Slide up all sub menus except the one clicked
			jQuery(this).next().slideToggle("normal"); // Slide down the clicked sub menu

			if (jQuery(this).attr("href") == 'http://www.qatar.vcu.edu/programs-courses/bfa-interior-design/'){
				// let the box expand
			} else {
				// dont allow box to expand
				return false;
			}
		}
	);

// ---------------------------------------------------------------------------------------------------------------------------
    // Alternating table rows:
	jQuery('tbody tr:even').addClass("alt-row"); // Add class "alt-row" to even table rows

// ---------------------------------------------------------------------------------------------------------------------------
	// FancyBox IFrame
	jQuery("a.fancyboxIframe").fancybox({
		autoScale		: false,
		'width'			: '70%',
		'height'		: '85%',
		'type'			: 'iframe',
		centerOnScroll : true
	});

	// FancyBox
	jQuery("a.fancyboxImage").fancybox({
		autoScale		: false,
		titlePosition	: 'outside'
	});


// ---------------------------------------------------------------------------------------------------------------------------
   // Greyscale swap
   jQuery("img.grey-swap")
        .mouseover(function() {
            var src = jQuery(this).attr("src").replace("-greyscale", "");
            jQuery(this).attr("src", src);
			jQuery(this).parent().parent().parent().find("h2 a").addClass("hover");
        })
        .mouseout(function() {
            var src = jQuery(this).attr("src").replace(".", "-greyscale.");
            jQuery(this).attr("src", src);
			jQuery(this).parent().parent().parent().find("h2 a").removeClass("hover");
        });

	jQuery(".grid_4_half h2")
        .mouseover(function() {
            var src = jQuery(this).parent().find(".grey-swap").attr("src").replace("-greyscale", "");
            jQuery(this).parent().find(".grey-swap").attr("src", src);
        })
        .mouseout(function() {
            var src = jQuery(this).parent().find(".grey-swap").attr("src").replace(".", "-greyscale.");
            jQuery(this).parent().find(".grey-swap").attr("src", src);
        });

// ---------------------------------------------------------------------------------------------------------------------------
	jQuery('.fadeSlider').cycle({
		speed: 'slow',
		timeout: 0,
		next: '#nextSlide',
		prev: '#prevSlide',
		before: getHeight
	});
	jQuery('.autoFadeSlider').cycle({
		speed: 'slow',
		before: getHeight
	});
	function getHeight() {
		$(this).parent().css("height", $(this).height());
	};

	jQuery('.fadeSlideShow').cycle({
		speed: 'slow',
		timeout: 0,
		next: '#next2',
		prev: '#prev2',
		before: getHeightTitleDownload
	});
	// gets height of image and makes the slideshow container the same size
	function getHeightTitleDownload() {
		jQuery('.fadeSlideShow').css("height",this.height); // adjust height of container to prevent clipping
		jQuery('#image-caption').html(this.alt); // set the caption of the picture
		if (this.id != "") { // setup the hi-res download link
			jQuery('#image-download').html('<a target="_blank" href="' + this.id + '">Download this image in high resolution</a>');
		} else {
			jQuery('#image-download').html("");
		}
	};

	jQuery('.homepageSlideShow').cycle({
		speed: 'slow',
		timeout: 6000,
		next: '#next2',
		prev: '#prev2'
	});


// ---------------------------------------------------------------------------------------------------------------------------
	jQuery().ready(function() {
		jQuery('.kwicks').kwicks({
			min : 65,
			spacing : 1,
			isVertical : true,
			duration : 500
		});
	});


// ---------------------------------------------------------------------------------------------------------------------------
	var inputBoxDefault = "";
	jQuery(".input-field").focus(function(){
		inputBoxDefault = jQuery(this).attr("title");
		if(jQuery(this).attr("value") == inputBoxDefault) jQuery(this).attr("value", "");
		jQuery(this).addClass("input-field-active");
	});
	jQuery(".input-field").blur(function(){
		if(jQuery(this).attr("value") == "") jQuery(this).attr("value", inputBoxDefault);
		jQuery(this).removeClass("input-field-active");
	});


// ---------------------------------------------------------------------------------------------------------------------------
	// trigger SMALL tooltip
	jQuery(".tooltip-trigger").tooltip({
		position: 'bottom center'
	});

	// trigger for BIG tooltip
	jQuery(".big-tooltip-trigger").tooltip({
		position: 'bottom center',
		tipClass: 'big-tooltip'
	});

	// trigger for FLEXIBLE tooltip
	$(".flex-tooltip-trigger").tooltip({
		position: "center right",
		offset: [-2, 10],
		tipClass: 'flex-tooltip'
	});


// ---------------------------------------------------------------------------------------------------------------------------
	// TABS ... When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn('fast'); //Fade in the active ID content
		return false;
	});
	
});
