jQuery(document).ready(
	function () {


	    /* global
	    --------------------------------------------------------------------------------------------------------------------*/

	    /* left navigation title hover
	    --------------------------------------------------*/
	    if (jQuery("#left-nav li.title a").length) {
	        jQuery("#left-nav li.title a").hover(
			  function () {
			      if (jQuery(this).parents("li.title").hasClass("current")) { // do nothing 
			      }
			      else {
			          jQuery(this).parents("li.title").addClass("active");
			      }
			  },
			  function () {
			      if (jQuery(this).parents("li.title").hasClass("current")) { // do nothing 
			      }
			      else {
			          jQuery(this).parents("li.title").removeClass("active");
			      }
			  }
			);
	    }


	    /*  general content forms
	    --------------------------------------------------*/
	    if (jQuery("#content-form").length) {
	        jQuery("#general_form").validate({
	            rules: {
	                firstname: "required",
	                lastname: "required",
	                studentid: "required"
	            },
	            messages: {
	                firstname: "Enter your First Name.",
	                lastname: "Enter your Last Name.",
	                studentid: "Enter your Student ID"
	            }
	        });
	        jQuery("#general_form").find('input.regular').focus(function () {
	            jQuery(this).addClass("active");
	        });
	        jQuery("#general_form").find('input.regular').blur(function () {
	            jQuery(this).removeClass("active");
	        });
	        jQuery("#general_form").find('textarea.regular').focus(function () {
	            jQuery(this).addClass("active");
	        });
	        jQuery("#general_form").find('textarea.regular').blur(function () {
	            jQuery(this).removeClass("active");
	        });
	    }

	    /*  content-drawer
	    --------------------------------------------------*/
	    if (jQuery(".content-drawer").length) {
	        jQuery('.content-drawer').each(function () {

	            jQuery(this).find('a.arrow-closed').click(function () {

	                if (jQuery(this).hasClass('arrow-opened')) {
	                    jQuery(this).parents('.content-drawer').find('.content').hide();
	                    jQuery(this).removeClass('arrow-opened');
	                }
	                else {
	                    jQuery(this).parents('.content-drawer').find('.content').show();
	                    jQuery(this).addClass('arrow-opened');
	                }
	            });
	        });
	    }

	    /* content drawer
	    -----------------------------------------------------------------------------*/

	    if (jQuery(".content-drawer-more").length) {
	        jQuery('.content-drawer-more').each(function () {

	            jQuery(this).find('a.btn-cd-more').click(function () {
	                jQuery(this).closest('.content-drawer-more').find('.extra').show();
	                jQuery(this).closest('.content-drawer-more').find('a.btn-cd-more').hide();
	            });

	            jQuery(this).find('a.btn-cd-less').click(function () {
	                jQuery(this).closest('.content-drawer-more').find('.extra').hide();
	                jQuery(this).closest('.content-drawer-more').find('a.btn-cd-more').show();
	            });
	        });
	    }

	    /*  overlays
	    --------------------------------------------------*/

	    // customized title display		
	    if (jQuery(".overlay-video").length || jQuery(".overlay-image-gallery").length) {
	        function formatOverlayTitle(title, currentArray, currentIndex, currentOpts) {
	            return '<div id="overlay-title">' + title + '</div>';
	        }
	    }

	    // video overlay
	    if (jQuery(".overlay-video").length) {
	        jQuery(".overlay-video").fancybox({
	            'height': 400,
	            'width': 600,
	            'autoScale': false,
	            'transitionIn': 'none',
	            'transitionOut': 'none',
	            'padding': '20',
	            'type': 'iframe',
	            'overlayColor': '#fff',
	            'overlayOpacity': '0.7',
	            'titleFormat': formatOverlayTitle
	        });
	    }

	    // image gallery overlay
	    if (jQuery(".overlay-image-gallery").length) {
	        jQuery(".overlay-image-gallery").fancybox({
	            'scrolling': false,
	            'height': 500,
	            'width': 600,
	            'autoScale': false,
	            'transitionIn': 'none',
	            'transitionOut': 'none',
	            'padding': '20',
	            'type': 'iframe',
	            'overlayColor': '#fff',
	            'overlayOpacity': '0.7',
	            'titleFormat': formatOverlayTitle
	        });
	    }

	    // customized title display		
	    if (jQuery(".overlay-course").length) {
	        function formatOverlayTitle(title, currentArray, currentIndex, currentOpts) {
	            return '<div id="overlay-title">' + title + '</div>';
	        }
	    }

	    // course overlay
	    if (jQuery(".overlay-course").length) {
	        jQuery(".overlay-course").fancybox({
	            'scrolling': false,
	            'height': 300,
	            'width': 600,
	            'autoScale': false,
	            'transitionIn': 'none',
	            'transitionOut': 'none',
	            'padding': '20',
	            'type': 'iframe',
	            'overlayColor': '#fff',
	            'overlayOpacity': '0.7',
	            'titleFormat': formatOverlayTitle
	        });
	    }

	    /* validator add-on
	    -----------------------------------------------------------------------------*/
	    jQuery.validator.addMethod("valueNotEquals", function (value, element, arg) {
	        return arg != value;
	    }, "Value must not equal arg.");


	    /* dropdown login validation
	    -----------------------------------------------------------------------------*/
	    // validate login form
	    jQuery("#dropdown_login_form_employee").validate({
	        rules: {
	            username: "required",
	            password: "required"
	        },
	        messages: {
	            username: "Enter your username.",
	            password: "Enter your password."
	        }
	    });
	    jQuery("#dropdown_login_form_student").validate({
	        rules: {
	            username: "required",
	            password: "required"
	        },
	        messages: {
	            username: "Enter your username.",
	            password: "Enter your password."
	        }
	    });


	    /* announcement
	    --------------------------------------------------*/
	    jQuery('#announcement-container').delay(2000).slideDown("fast").delay(2000).animate({ backgroundColor: 'black' }, 1000);
	    jQuery('#announcement .right a').click(function () {
	        jQuery('#announcement-container').slideUp("fast");
	    });


	    /* search go button - hover
	    --------------------------------------------------*/
	    jQuery("input.submit").hover(
		  function () {
		      jQuery(this).addClass("submit-over");
		  },
		  function () {
		      jQuery(this).removeClass("submit-over")
		  }
		);


	    /* login dropdown - open 
	    --------------------------------------------------*/
	    jQuery("li.students a.login").hover(
		  function () {
		      jQuery("li.students ul").show();
		      jQuery("li.students ul").find("input#student-username").focus();
		      jQuery("li.employees ul").hide();
		  }
		);

	    jQuery("li.employees a.login").hover(
		  function () {
		      jQuery("li.students ul").hide();
		      jQuery("li.employees ul").find("input#employee-username").focus();
		      jQuery("li.employees ul").show();
		  }
		);

	    // for chrome -- have to hover on the input boxes, too
	    jQuery("li.students .login-area input").hover(
		  function () {
		      jQuery("li.students ul").show();
		      jQuery("li.employees ul").hide();
		  }
		);
	    jQuery("li.employees .login-area input").hover(
		  function () {
		      jQuery("li.students ul").hide();
		      jQuery("li.employees ul").show();
		  }
		);

	    jQuery("li.students ul").hover(
		  function () {
		      // do nothing
		  },
		  function () {
		      jQuery(this).hide();
		  }
		);

	    jQuery("li.employees ul").hover(
		  function () {
		      // do nothing
		  },
		  function () {
		      jQuery(this).hide();
		  }
		);
	    jQuery(".special-close").hover(
		  function () {
		      jQuery('li.employees ul').hide();
		  },
		  function () {

		  }
		);

	    /* login dropdown close
	    --------------------------------------------------*/
	    jQuery('li.students a.btn-close').click(function () {
	        jQuery("li.students ul").hide();
	    });
	    jQuery('li.employees a.btn-close').click(function () {
	        jQuery("li.employees ul").hide();
	    });

	    // show main nav when sub-nav item selected
	    jQuery("ul.dropdown").hover(
		  function () {
		      jQuery(this).parent().find("a.main").addClass("active");
		  },
		  function () {
		      jQuery(this).parent().find("a.main").removeClass("active");
		  }
		);


	    /*  content images -- alt text caption
	    --------------------------------------------------*/
	    jQuery('img.caption').each(function () {

	        // wrap image (or linked image) with a container div
	        if (jQuery(this).parent()[0].tagName == "P") {
	            jQuery(this).wrap("<div class='caption-container'>");
	            jQuery(this).after("<div class='caption-text'>" + jQuery(this).attr("alt") + "</div>");

	            // set width
	            jQuerycontainer = jQuery(this).parent();
	            jQuerycontainer.width(jQuery(this).width() + 14);
	        }
	        else if (jQuery(this).parent()[0].tagName == "A") {
	            jQuery(this).parent().wrap("<div class='caption-container'>");
	            jQuery(this).parent().after("<div class='caption-text'>" + jQuery(this).attr("alt") + "</div>");

	            // set width
	            jQuerycontainer = jQuery(this).parent().parent();
	            jQuerycontainer.width(jQuery(this).width() + 14);
	        }

	        // align properly
	        if (jQuery(this).hasClass("image-right-border"))
	            jQuerycontainer.addClass("caption-right");
	        else if (jQuery(this).hasClass("image-left-border"))
	            jQuerycontainer.addClass("caption-left");
	    });



	    /*  content linked media thumb image 
	    --------------------------------------------------*/
	    jQuery('a.media-play').append("<div class='play'>");


	    /* right box - testimonial
	    -----------------------------------------------------------------------------*/
	    // add curves on voices images
	    jQuery('#testimonial .image a').after("<div class='curves-left'>").after("<div class='curves-right'>");


	    /* home template only 
	    --------------------------------------------------------------------------------------------------------------------*/
	    if (jQuery('body').hasClass('home')) {
	        /* pathways
	        -----------------------------------------------------------------------------*/
	        // create cycle animation
	        jQuery('#pathways-gallery .item').hide();
	        jQuery('#pathways-gallery').before('<div id="pathways-nav">').cycle({
	            fx: 'fade',
	            speed: 1000,
	            timeout: 8000,
	            pause: 1,
	            pager: '#pathways-nav',
	            allowPagerClickBubble: true,
	            pagerEvent: 'mouseover.cycle',
	            prevNextEvent: 'mouseover.cycle',
	            pagerAnchorBuilder: function (idx, slide) {
	                return '<a href="' + jQuery(slide).children(".cta").children("a").eq(0).attr('href') + '">' + idx + '</a>';
	            }
	        });

	        // allow changing of items on rollover
	        jQuery("#pathways-nav a").each(function (index) {
	            jQuery(this).hover(
				  function () {
				      jQuery('#pathways-gallery').cycle(index);
				      return false;
				  }
				);
	        });


	        /* news teasers
	        -----------------------------------------------------------------------------*/
	        // carousel variables			
	        jQuerynewsteasertotal = jQuery("#news-teasers-items li").size();
	        jQuerycurrentset = 1;
	        jQuerytotalsets = Math.floor(jQuerynewsteasertotal / 4);

	        // show dots -- allows for 16 spots			
	        if (jQuerynewsteasertotal > 0) jQuery('#news-teasers-nav li').eq(1).show().find('a');
	        if (jQuerynewsteasertotal > 4) jQuery('#news-teasers-nav li').eq(2).show().find('a');
	        if (jQuerynewsteasertotal > 8) jQuery('#news-teasers-nav li').eq(3).show().find('a');
	        if (jQuerynewsteasertotal > 12) jQuery('#news-teasers-nav li').eq(4).show().find('a');

	        // show/hide dots based on prev/next clicks
	        function updateDots(updateAmt) {
	            // update current set -- can be changed by arrows or click to dots			
	            jQuery("#news-teasers-nav a.dot").each(
					function (intIndex) {
					    if (jQuery(this).hasClass("current"))
					        jQuerycurrentset = intIndex + 1;
					}
				);
	            // make sure you can't keep clicking infinitely right or left
	            if ((updateAmt > 0 && (jQuerycurrentset >= 1 && jQuerycurrentset < jQuerytotalsets)) || (updateAmt < 0 && (jQuerycurrentset > 1 && jQuerycurrentset <= jQuerytotalsets))) {
	                jQuerycurrentset = jQuerycurrentset + updateAmt;
	                jQuery('#news-teasers-nav a').removeClass("current");
	                jQuery('#news-teasers-nav a.dot' + jQuerycurrentset).addClass("current");
	            }
	        }

	        // set custom prev/next functions
	        function mycarousel_initCallback(carousel) {

	            jQuery("#news-teasers-nav a.dot").each(
					function (intIndex) {

					    jQuery(this).bind('click', function () {

					        jQuerynextItem = (intIndex * 4) + 1;
					        carousel.scroll(jQuery.jcarousel.intval(jQuerynextItem));

					        jQuery('#news-teasers-nav a').removeClass("current");
					        jQuery(this).addClass("current");

					        return false;
					    });
					}
				);

	            jQuery('a.news-teasers-next').bind('click', function () {
	                carousel.next();
	                updateDots(1);
	                return false;
	            });

	            jQuery('a.news-teasers-prev').bind('click', function () {
	                carousel.prev();
	                updateDots(-1);
	                return false;
	            });
	        };

	        // initial carousel call			
	        jQuery('#news-teasers-items').jcarousel({
	            scroll: 4,
	            initCallback: mycarousel_initCallback,
	            // This tells jCarousel NOT to autobuild prev/next buttons
	            buttonNextHTML: null,
	            buttonPrevHTML: null
	        });

	        // create rollover over whole news item
	        jQuery("#news-teasers-items li").hover(
			  function () {
			      jQuery(this).addClass("item-hover");
			      jQuery(this).find("p.title").addClass("title-hover");
			  },
			  function () {
			      jQuery(this).removeClass("item-hover");
			      jQuery(this).find("p.title").removeClass("title-hover");
			  }
			);

	        // allow whole area to be linked based on read more href
	        jQuery('#news-teasers-items .item').click(function () {
	            window.location.href = jQuery(this).find("a.arrow-right").attr("href");
	        });


	        /* our voices
	        -----------------------------------------------------------------------------*/
	        // add curves on voices images
	        jQuery('#voices-list .item-image a').after("<div class='curves-left'>").after("<div class='curves-right'>");


	        /* quick links
	        -----------------------------------------------------------------------------*/
	        // show extra links
	        jQuery('#quick-links-buttons a.btn-ql-more').click(function () {
	            jQuery(this).hide();
	            jQuery('#quick-links-buttons a.btn-ql-less').show();
	            jQuery('#quick-links table.extra').show();
	        });
	        // hide extra links
	        jQuery('#quick-links-buttons a.btn-ql-less').click(function () {
	            jQuery(this).hide();
	            jQuery('#quick-links-buttons a.btn-ql-more').show();
	            jQuery('#quick-links table.extra').hide();
	        });

	    }


	    /* three feature landing page template only 
	    --------------------------------------------------------------------------------------------------------------------*/

	    if (jQuery('body').hasClass('three-features')) {
	        // add curves on voices images
	        jQuery('#three-features .item-image a').after("<div class='curves-left'>").after("<div class='curves-right'>");

	    }


	    /* login template only 
	    --------------------------------------------------------------------------------------------------------------------*/

	    if (jQuery('body').hasClass('login')) {
	        /* search go button - hover
	        -----------------------------------------------------------------------------*/
	        jQuery(".login .landing-photo .right .submit input").hover(
			  function () {
			      jQuery(this).addClass("submit-over");
			  },
			  function () {
			      jQuery(this).removeClass("submit-over")
			  }
			);


	        /* search box - remove text on focus
	        -----------------------------------------------------------------------------*/
	        //jQuery('.login_form input#username').val('MyMCTC ID');
	        jQuery('.login_form input#username').each(function () {
	            var default_value = this.value;
	            jQuery(this).focus(function () {
	                if (this.value == default_value) {
	                    this.value = '';
	                }
	            });
	            jQuery(this).blur(function () {
	                if (this.value == '') {
	                    this.value = default_value;
	                }
	            });
	        });
	        //jQuery('.login_form input#password').val('Password');
	        jQuery('.login_form input#password').each(function () {
	            var default_value = this.value;
	            jQuery(this).focus(function () {
	                if (this.value == default_value) {
	                    this.value = '';
	                }
	            });
	            jQuery(this).blur(function () {
	                if (this.value == '') {
	                    this.value = default_value;
	                }
	            });
	        });

	        /* login validation
	        -----------------------------------------------------------------------------*/
	        // validator add-on
	        jQuery.validator.addMethod("valueNotEquals", function (value, element, arg) {
	            return arg != value;
	        }, "Value must not equal arg.");


	        // validate login form
	        jQuery("#login_form_employee").validate({
	            rules: {
	                username: {
	                    required: true,
	                    valueNotEquals: 'MyMCTC ID'
	                },
	                password: {
	                    required: true,
	                    valueNotEquals: 'Password'
	                }
	            },
	            messages: {
	                username: "Enter your username.",
	                password: "Enter your password."
	            }
	        });
	        jQuery("#login_form_student").validate({
	            rules: {
	                username: {
	                    required: true,
	                    valueNotEquals: 'MyMCTC ID'
	                },
	                password: {
	                    required: true,
	                    valueNotEquals: 'Password'
	                }
	            },
	            messages: {
	                username: "Enter your username.",
	                password: "Enter your password."
	            }
	        });

	        // show / hide different logins
	        jQuery('#student a.switch-login').bind('click', function () {
	            jQuery('#student').hide();
	            jQuery('#employee').show();
	            return false;
	        });
	        jQuery('#employee a.switch-login').bind('click', function () {
	            jQuery('#employee').hide();
	            jQuery('#student').show();
	            return false;
	        });


	    }

	    /* courses table only
	    --------------------------------------------------------------------------------------------------------------------*/
	    if (jQuery('table.courses').length) {
	        // reveal course details on arrow link click
	        jQuery('td.courseinfo').each(function () {

	            jQuery(this).hover(
				  function () {
				      if (jQuery(this).hasClass('courseinfo-opened')) { }
				      else {
				          jQuery(this).addClass('courseinfo-hover');
				      }
				  },
				  function () {
				      if (jQuery(this).hasClass('courseinfo-opened')) { }
				      else {
				          jQuery(this).removeClass('courseinfo-hover');
				      }
				  }
				);

	            jQuery(this).find('a.arrow-closed').click(function () {

	                jQuery('.course-details').hide();
	                jQuery("td.courseinfo").removeClass('courseinfo-opened');
	                jQuery("td.courseinfo").removeClass('courseinfo-hover');

	                // already opened
	                if (jQuery(this).hasClass('arrow-opened')) {
	                    jQuery(this).removeClass('arrow-opened').addClass('arrow-closed');
	                }
	                else // default, closed
	                {
	                    jQuery('.course-abbrv a.arrow-opened').addClass('arrow-closed').removeClass('arrow-opened');
	                    jQuery(this).parents("td.courseinfo").find('.course-details').show();
	                    jQuery(this).removeClass('arrow-closed').addClass('arrow-opened');
	                    jQuery(this).parents("td.courseinfo").addClass('courseinfo-opened');
	                }
	            });
	        });

	    }
	    /* programs table only
	    --------------------------------------------------------------------------------------------------------------------*/
	    if (jQuery('table.programs').length) {

	        function resetTable() {
	            jQuery('table.programs tr.items').hide();
	            jQuery('table.programs td.main a').removeClass('arrow-opened');
	            jQuery('table.programs td.main').removeClass('bg0-over')
	            jQuery('table.programs tr.area td.dot-check').removeClass('bg1-over').removeClass('bg2-over').removeClass('bg3-over');

	        }

	        // reveal course details on arrow link click
	        jQuery('table.programs tr.area').each(function () {

	            // main row link click function																				
	            jQuery(this).find('a.arrow-closed').click(function () {
	                var jQueryrowID = jQuery(this).attr('class').replace('arrow-opened', '').replace('arrow-closed', '').replace(' ', '');

	                resetTable();

	                if (jQuery(this).hasClass('arrow-opened')) {
	                    jQuery('table.programs tr.' + jQueryrowID).hide();
	                    jQuery(this).removeClass('arrow-opened');

	                    jQuery(this).parents('tr.area').find('td.main').removeClass("bg0-over");
	                    jQuery(this).parents('tr.area').find('td.bg1').removeClass("bg1-over");
	                    jQuery(this).parents('tr.area').find('td.bg2').removeClass("bg2-over");
	                    jQuery(this).parents('tr.area').find('td.bg3').removeClass("bg3-over");
	                }
	                else {
	                    jQuery('table.programs tr.' + jQueryrowID).show();
	                    jQuery(this).addClass('arrow-opened');

	                    jQuery(this).parents('tr.area').find('td.main').addClass("bg0-over");
	                    jQuery(this).parents('tr.area').find('td.bg1').addClass("bg1-over");
	                    jQuery(this).parents('tr.area').find('td.bg2').addClass("bg2-over");
	                    jQuery(this).parents('tr.area').find('td.bg3').addClass("bg3-over");
	                }
	            });

	            // row hover state
	            jQuery(this).hover(
				  function () {
				      if (jQuery(this).find('a.arrow-closed').hasClass('arrow-opened')) { // do nothing	
				      }
				      else {
				          jQuery(this).find('td.main').addClass("bg0-over");
				          jQuery(this).find('td.bg1').addClass("bg1-over");
				          jQuery(this).find('td.bg2').addClass("bg2-over");
				          jQuery(this).find('td.bg3').addClass("bg3-over");
				      }
				  },
				  function () {
				      if (jQuery(this).find('a.arrow-closed').hasClass('arrow-opened')) { // do nothing	
				      }
				      else {
				          jQuery(this).find('td.main').removeClass("bg0-over");
				          jQuery(this).find('td.bg1').removeClass("bg1-over");
				          jQuery(this).find('td.bg2').removeClass("bg2-over");
				          jQuery(this).find('td.bg3').removeClass("bg3-over");
				      }
				  }
				);

	        });

	        // anchor in content					
	        jQuery('a.special-anchor').click(function () {

	            jQueryprogram_anchor = jQuery(this).attr("href").replace("#", "");

	            jQuery.scrollTo('a.' + jQueryprogram_anchor)

	            resetTable();

	            jQuery('table.programs tr.' + jQueryprogram_anchor).show();
	            jQuery('a.' + jQueryprogram_anchor).addClass('arrow-opened');

	            jQuery('a.' + jQueryprogram_anchor).parents('tr.area').find('td.main').addClass("bg0-over");
	            jQuery('a.' + jQueryprogram_anchor).parents('tr.area').find('td.bg1').addClass("bg1-over");
	            jQuery('a.' + jQueryprogram_anchor).parents('tr.area').find('td.bg2').addClass("bg2-over");
	            jQuery('a.' + jQueryprogram_anchor).parents('tr.area').find('td.bg3').addClass("bg3-over");
	        });

	        // if anchor in URL
	        jQueryprogram_anchor = window.location.hash.replace("#", "");

	        if (jQueryprogram_anchor.length > 0) {
	            jQuery.scrollTo('a.' + jQueryprogram_anchor)

	            jQuery('table.programs tr.' + jQueryprogram_anchor).show();
	            jQuery('a.' + jQueryprogram_anchor).addClass('arrow-opened');

	            jQuery('a.' + jQueryprogram_anchor).parents('tr.area').find('td.main').addClass("bg0-over");
	            jQuery('a.' + jQueryprogram_anchor).parents('tr.area').find('td.bg1').addClass("bg1-over");
	            jQuery('a.' + jQueryprogram_anchor).parents('tr.area').find('td.bg2').addClass("bg2-over");
	            jQuery('a.' + jQueryprogram_anchor).parents('tr.area').find('td.bg3').addClass("bg3-over");
	        }

	        /*  add tooltip rollover
	        --------------------------------------------------*/
	        jQuery('img.dot').each(function () {

	            jQuery(this).wrap("<div class='tooltip-small-area'>");
	            jQuery(this).after("<div class='tooltip-small'><div class='tooltip-small-mid'>" + jQuery(this).attr("alt") + "</div><div class='tooltip-small-bot'></div></div>");
	        });

	        // small tooltip
	        jQuery(".tooltip-small-area").hover(
			  function () {
			      jQuery(this).find('.tooltip-small').show();
			  },
			  function () {
			      jQuery(this).find('.tooltip-small').hide();
			  }
			);


	        // large tooltip
	        jQuery(".tooltip-big-area").hover(
			  function () {
			      jQuery(this).parent().find('.tooltip-big').show();
			  },
			  function () {
			      jQuery(this).parent().find('.tooltip-big').hide();
			  }
			);

	        // ie6 png fix
	        jQuery("td.dot-check").pngFix();

	    }

	});
