//************************
//Tree Menu
//***********************

;(function($) {

	$.extend($.fn, {
		swapClass: function(c1, c2) {
			var c1Elements = this.filter('.' + c1);
			this.filter('.' + c2).removeClass(c2).addClass(c1);
			c1Elements.removeClass(c1).addClass(c2);
			return this;
		},
		replaceClass: function(c1, c2) {
			return this.filter('.' + c1).removeClass(c1).addClass(c2).end();
		},
		hoverClass: function(className) {
			className = className || "hover";
			return this.hover(function() {
				$(this).addClass(className);
			}, function() {
				$(this).removeClass(className);
			});
		},
		heightToggle: function(animated, callback) {
			animated ?
				this.animate({ height: "toggle" }, animated, callback) :
				this.each(function(){
					jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]();
					if(callback)
						callback.apply(this, arguments);
				});
		},
		heightHide: function(animated, callback) {
			if (animated) {
				this.animate({ height: "hide" }, animated, callback);
			} else {
				this.hide();
				if (callback)
					this.each(callback);				
			}
		},
		prepareBranches: function(settings) {
			if (!settings.prerendered) {
				// mark last tree items
				this.filter(":last-child:not(ul)").addClass(CLASSES.last);
				// collapse whole tree, or only those marked as closed, anyway except those marked as open
				this.filter((settings.collapsed ? "" : "." + CLASSES.closed) + ":not(." + CLASSES.open + ")").find(">ul").hide();
			}
			// return all items with sublists
			return this.filter(":has(>ul)");
		},
		applyClasses: function(settings, toggler) {
			this.filter(":has(>ul):not(:has(>a))").find(">span").click(function(event) {
				toggler.apply($(this).next());
			}).add( $("a", this) ).hoverClass();
			
			if (!settings.prerendered) {
				// handle closed ones first
				this.filter(":has(>ul:hidden)")
						.addClass(CLASSES.expandable)
						.replaceClass(CLASSES.last, CLASSES.lastExpandable);
						
				// handle open ones
				this.not(":has(>ul:hidden)")
						.addClass(CLASSES.collapsable)
						.replaceClass(CLASSES.last, CLASSES.lastCollapsable);
						
	            // create hitarea
				this.find("span").prepend("<div class=\"" + CLASSES.hitarea + "\"/>").find("div." + CLASSES.hitarea).each(function() {
					var classes = "";
					$.each($(this).parent().attr("class").split(" "), function() {
						classes += this + "-hitarea ";
					});
					$(this).addClass( classes );
					
				});
				
			}
			
			// apply event to hitarea
			this.find("div." + CLASSES.hitarea).click( toggler );
		},
		treeview: function(settings) {
			
			settings = $.extend({
				cookieId: "treeview"
			}, settings);
			
			if (settings.add) {
				return this.trigger("add", [settings.add]);
			}
			
			if ( settings.toggle ) {
				var callback = settings.toggle;
				settings.toggle = function() {
					return callback.apply($(this).parent()[0], arguments);
				};
			}
		
			// factory for treecontroller
			function treeController(tree, control) {
				// factory for click handlers
				function handler(filter) {
					return function() {
						// reuse toggle event handler, applying the elements to toggle
						// start searching for all hitareas
						toggler.apply( $("div." + CLASSES.hitarea, tree).filter(function() {
							// for plain toggle, no filter is provided, otherwise we need to check the parent element
							return filter ? $(this).parent("." + filter).length : true;
						}) );
						return false;
					};
				}
				// click on first element to collapse tree
				$("a:eq(0)", control).click( handler(CLASSES.collapsable) );
				// click on second to expand tree
				$("a:eq(1)", control).click( handler(CLASSES.expandable) );
				// click on third to toggle tree
				$("a:eq(2)", control).click( handler() ); 
			}
		
			// handle toggle event
			function toggler() {
				$(this)
					.parent()
					// swap classes for hitarea
					.find(">.hitarea")
						.swapClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
						.swapClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea )
					.end()
					// swap classes for parent li
					.swapClass( CLASSES.collapsable, CLASSES.expandable )
					.swapClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
					// find child lists
					.find( ">ul" )
					// toggle them
					.heightToggle( settings.animated, settings.toggle );
				if ( settings.unique ) {
					$(this).parent()
						.siblings()
						// swap classes for hitarea
						.find(">.hitarea")
							.replaceClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
							.replaceClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea )
						.end()
						.replaceClass( CLASSES.collapsable, CLASSES.expandable )
						.replaceClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
						.find( ">ul" )
						.heightHide( settings.animated, settings.toggle );
				}
			}
			
			function serialize() {
				function binary(arg) {
					return arg ? 1 : 0;
				}
				var data = [];
				branches.each(function(i, e) {
					data[i] = $(e).is(":has(>ul:visible)") ? 1 : 0;
				});
				$.cookie(settings.cookieId, data.join("") );
			}
			
			function deserialize() {
				var stored = $.cookie(settings.cookieId);
				if ( stored ) {
					var data = stored.split("");
					branches.each(function(i, e) {
						$(e).find(">ul")[ parseInt(data[i]) ? "show" : "hide" ]();
					});
				}
			}
			
			// add treeview class to activate styles
			this.addClass("treeview");
			
			// prepare branches and find all tree items with child lists
			var branches = this.find("li").prepareBranches(settings);
			
			switch(settings.persist) {
			case "cookie":
				var toggleCallback = settings.toggle;
				settings.toggle = function() {
					serialize();
					if (toggleCallback) {
						toggleCallback.apply(this, arguments);
					}
				};
				deserialize();
				break;
			case "location":
				var current = this.find("a").filter(function() { return this.href.toLowerCase() == location.href.toLowerCase(); });
				if ( current.length ) {
					current.addClass("selected").parents("ul, li").add( current.next() ).show();
				}
				break;
			}
			
			branches.applyClasses(settings, toggler);
				
			// if control option is set, create the treecontroller and show it
			if ( settings.control ) {
				treeController(this, settings.control);
				$(settings.control).show();
			}
			
			return this.bind("add", function(event, branches) {
				$(branches).prev()
					.removeClass(CLASSES.last)
					.removeClass(CLASSES.lastCollapsable)
					.removeClass(CLASSES.lastExpandable)
				.find(">.hitarea")
					.removeClass(CLASSES.lastCollapsableHitarea)
					.removeClass(CLASSES.lastExpandableHitarea);
				$(branches).find("li").andSelf().prepareBranches(settings).applyClasses(settings, toggler);
			});
		}
	});
	
	// classes used by the plugin
	// need to be styled via external stylesheet, see first example
	var CLASSES = $.fn.treeview.classes = {
		open: "open",
		closed: "closed",
		expandable: "expandable",
		expandableHitarea: "expandable-hitarea",
		lastExpandableHitarea: "lastExpandable-hitarea",
		collapsable: "collapsable",
		collapsableHitarea: "collapsable-hitarea",
		lastCollapsableHitarea: "lastCollapsable-hitarea",
		lastCollapsable: "lastCollapsable",
		lastExpandable: "lastExpandable",
		last: "last",
		hitarea: "hitarea"
	};
	
	// provide backwards compability
	$.fn.Treeview = $.fn.treeview;
	
})(jQuery);




//************************
//Standard sfHover Function
//***********************
sfHover = function() {
	var sfEls = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfHover";
		}
		sfEls[i].onmouseout=function() {
			$(this).removeClass("sfHover");
		}
	}
}



//************************
//Accordion Function
//***********************
;(function($) {
	
// If the UI scope is not available, add it
$.ui = $.ui || {};

$.fn.extend({
	accordion: function(options, data) {
		var args = Array.prototype.slice.call(arguments, 1);

		return this.each(function() {
			if (typeof options == "string") {
				var accordion = $.data(this, "ui-accordion");
				accordion[options].apply(accordion, args);
			// INIT with optional options
			} else if (!$(this).is(".ui-accordion"))
				$.data(this, "ui-accordion", new $.ui.accordion(this, options));
		});
	},
	// deprecated, use accordion("activate", index) instead
	activate: function(index) {
		return this.accordion("activate", index);
	}
});

$.ui.accordion = function(container, options) {
	
	// setup configuration
	this.options = options = $.extend({}, $.ui.accordion.defaults, options);
	this.element = container;
	
	$(container).addClass("ui-accordion");
	
	if ( options.navigation ) {
		var current = $(container).find("a").filter(options.navigationFilter);
		if ( current.length ) {
			if ( current.filter(options.header).length ) {
				options.active = current;
			} else {
				options.active = current.parent().parent().prev();
				current.addClass("current");
			}
		}
	}
	
	// calculate active if not specified, using the first header
	options.headers = $(container).find(options.header);
	options.active = findActive(options.headers, options.active);

	if ( options.fillSpace ) {
		var maxHeight = $(container).parent().height();
		options.headers.each(function() {
			maxHeight -= $(this).outerHeight();
		});
		var maxPadding = 0;
		options.headers.next().each(function() {
			maxPadding = Math.max(maxPadding, $(this).innerHeight() - $(this).height());
		}).height(maxHeight - maxPadding);
	} else if ( options.autoheight ) {
		var maxHeight = 0;
		options.headers.next().each(function() {
			maxHeight = Math.max(maxHeight, $(this).outerHeight());
		}).height(maxHeight);
	}

	options.headers
		.not(options.active || "")
		.next()
		.hide();
	options.active.parent().andSelf().addClass(options.selectedClass);
	
	if (options.event)
		$(container).bind((options.event) + ".ui-accordion", clickHandler);
};

$.ui.accordion.prototype = {
	activate: function(index) {
		// call clickHandler with custom event
		clickHandler.call(this.element, {
			target: findActive( this.options.headers, index )[0]
		});
	},
	
	enable: function() {
		this.options.disabled = false;
	},
	disable: function() {
		this.options.disabled = true;
	},
	destroy: function() {
		this.options.headers.next().css("display", "");
		if ( this.options.fillSpace || this.options.autoheight ) {
			this.options.headers.next().css("height", "");
		}
		$.removeData(this.element, "ui-accordion");
		$(this.element).removeClass("ui-accordion").unbind(".ui-accordion");
	}
}

function scopeCallback(callback, scope) {
	return function() {
		return callback.apply(scope, arguments);
	};
}

function completed(cancel) {
	// if removed while animated data can be empty
	if (!$.data(this, "ui-accordion"))
		return;
	var instance = $.data(this, "ui-accordion");
	var options = instance.options;
	options.running = cancel ? 0 : --options.running;
	if ( options.running )
		return;
	if ( options.clearStyle ) {
		options.toShow.add(options.toHide).css({
			height: "",
			overflow: ""
		});
	}
	$(this).triggerHandler("change.ui-accordion", [options.data], options.change);
}

function toggle(toShow, toHide, data, clickedActive, down) {
	var options = $.data(this, "ui-accordion").options;
	options.toShow = toShow;
	options.toHide = toHide;
	options.data = data;
	var complete = scopeCallback(completed, this);
	
	// count elements to animate
	options.running = toHide.size() == 0 ? toShow.size() : toHide.size();
	
	if ( options.animated ) {
		if ( !options.alwaysOpen && clickedActive ) {
			$.ui.accordion.animations[options.animated]({
				toShow: jQuery([]),
				toHide: toHide,
				complete: complete,
				down: down,
				autoheight: options.autoheight
			});
		} else {
			$.ui.accordion.animations[options.animated]({
				toShow: toShow,
				toHide: toHide,
				complete: complete,
				down: down,
				autoheight: options.autoheight
			});
		}
	} else {
		if ( !options.alwaysOpen && clickedActive ) {
			toShow.toggle();
		} else {
			toHide.hide();
			toShow.show();
		}
		complete(true);
	}
}

function clickHandler(event) {
	var options = $.data(this, "ui-accordion").options;
	if (options.disabled)
		return false;
	
	// called only when using activate(false) to close all parts programmatically
	if ( !event.target && !options.alwaysOpen ) {
		options.active.parent().andSelf().toggleClass(options.selectedClass);
		var toHide = options.active.next(),
			data = {
				instance: this,
				options: options,
				newHeader: jQuery([]),
				oldHeader: options.active,
				newContent: jQuery([]),
				oldContent: toHide
			},
			toShow = options.active = $([]);
		toggle.call(this, toShow, toHide, data );
		return false;
	}
	// get the click target
	var clicked = $(event.target);
	
	// due to the event delegation model, we have to check if one
	// of the parent elements is our actual header, and find that
	if ( clicked.parents(options.header).length )
		while ( !clicked.is(options.header) )
			clicked = clicked.parent();
	
	var clickedActive = clicked[0] == options.active[0];
	
	// if animations are still active, or the active header is the target, ignore click
	if (options.running || (options.alwaysOpen && clickedActive))
		return false;
	if (!clicked.is(options.header))
		return;

	// switch classes
	options.active.parent().andSelf().toggleClass(options.selectedClass);
	if ( !clickedActive ) {
		clicked.parent().andSelf().addClass(options.selectedClass);
	}

	// find elements to show and hide
	var toShow = clicked.next(),
		toHide = options.active.next(),
		//data = [clicked, options.active, toShow, toHide],
		data = {
			instance: this,
			options: options,
			newHeader: clicked,
			oldHeader: options.active,
			newContent: toShow,
			oldContent: toHide
		},
		down = options.headers.index( options.active[0] ) > options.headers.index( clicked[0] );
	
	options.active = clickedActive ? $([]) : clicked;
	toggle.call(this, toShow, toHide, data, clickedActive, down );

	return false;
};

function findActive(headers, selector) {
	return selector != undefined
		? typeof selector == "number"
			? headers.filter(":eq(" + selector + ")")
			: headers.not(headers.not(selector))
		: selector === false
			? $([])
			: headers.filter(":eq(0)");
}

$.extend($.ui.accordion, {
	defaults: {
		selectedClass: "selected",
		alwaysOpen: true,
		animated: 'slide',
		event: "click",
		header: "a",
		autoheight: true,
		running: 0,
		navigationFilter: function() {
			return this.href.toLowerCase() == location.href.toLowerCase();
		}
	},
	animations: {
		slide: function(options, additions) {
			options = $.extend({
				easing: "swing",
				duration: 300
			}, options, additions);
			if ( !options.toHide.size() ) {
				options.toShow.animate({height: "show"}, options);
				return;
			}
			var hideHeight = options.toHide.height(),
				showHeight = options.toShow.height(),
				difference = showHeight / hideHeight;
			options.toShow.css({ height: 0, overflow: 'hidden' }).show();
			options.toHide.filter(":hidden").each(options.complete).end().filter(":visible").animate({height:"hide"},{
				step: function(now) {
					var current = (hideHeight - now) * difference;
					if ($.browser.msie || $.browser.opera) {
						current = Math.ceil(current);
					}
					options.toShow.height( current );
				},
				duration: options.duration,
				easing: options.easing,
				complete: function() {
					if ( !options.autoheight ) {
						options.toShow.css("height", "auto");
					}
					options.complete();
				}
			});
		},
		bounceslide: function(options) {
			this.slide(options, {
				easing: options.down ? "bounceout" : "swing",
				duration: options.down ? 1000 : 200
			});
		},
		easeslide: function(options) {
			this.slide(options, {
				easing: "easeinout",
				duration: 700
			})
		}
	}
});

})(jQuery);



//****************************
//Create Tabs
//****************************
(function($){
 	$.fn.extend({ 
 		tabify: function() {
 			
    		return this.each(function() {
		
		    	//Creating a reference to the object
				var obj = $(this);
		
				//Create a reference for all headings and it's content using .next()
				//Remember to pass the object reference "obj" into the identifier.
				var headings = $('h1', obj);
				var tabContent = $('h1', obj).next();
			
				//We wan't to hide the headings and the content
				headings.addClass("hide");
				tabContent.addClass("hide");
				//But we want to show content of the first tab since it's selected by default. 
				tabContent.eq(0).removeClass("hide");;
				
				//Prepend the object with the tab container (ul).
				obj.prepend('<ul class="tabs"><\/ul>');
				
				//For every heading create an item (<li>)
				for(var i=0;i<headings.length;i++) {
					
					var sel;
					//The first object is selected by default so add class="sel" to it
					if(i == 0){
						sel = 'sel';
					}
					//Else set it to empty
					else {
						sel ="";
					}
					//the label for the tab should equal the text of the heading
					var label = headings.eq(i).text();
					//grab the id of the h2 tag in order to use as class for the li
					var tabId = headings.eq(i).attr("id");
					$("ul.tabs", obj).append('<li id="'+tabId+'-tab" class="'+sel+'">' + label + '<\/li>');
				}
				
				//Create a reference to the tabs for each obj
				var tabs = $("ul.tabs li", obj);
				
				tabs.click(function() {
					
					//When a tab is clicked "de-activate" the old one
					$("ul.tabs li.sel", obj).removeClass("sel");
					tabContent.addClass("hide");
					$(this).addClass("sel");
					
					//And display the clicked tab
					var current = tabs.index($(this));
					tabContent.eq(current).removeClass("hide");
				});
    		});
    	}
	});
})(jQuery);



//*******************************
//text resize function
//*******************************
function textresize() {
	
	//create cookie		
	var $cookie_name = "NMIT_FontResize";
	//stored cookied
	var getBodyClass = $.cookie($cookie_name);
	
	//if cookie is created check the following
	if($.cookie($cookie_name)) {
		//if the cookie saved is large then add classes to the elements
		if(getBodyClass=="large") {
			$('body').addClass('large');
			$('#resizeFont').addClass('selected');
		} 		
	}
	
	
	//button function
	$("#resizeFont").click(function(){
		//reset font
		if ($("#resizeFont").hasClass("selected")) {
			$('body').removeClass();
			$(this).removeClass();
			//store cookie
			var bodyClass = ""
			$.cookie($cookie_name, bodyClass);
		//increase font size	
		} else {
			$(this).addClass("selected");
			$('body').addClass('large');
			//store cookie
			var bodyClass = "large";
			$.cookie($cookie_name, bodyClass);
		}
		//disable click through on button
		return false;
	});
}


//*******************************
//modal function
//*******************************
$(function() {
	//$.fn.nyroModal.settings.debug = true;
	$.fn.nyroModal.settings.type = 'swf';
	$.fn.nyroModal.settings.bgColor = '#777777';
	$.fn.nyroModal.settings.width = 620;
	$.fn.nyroModal.settings.height = 430;
});


//**********************************
//Gallery Image
//**********************************
function gallery() {	   
	
	//Creating a reference to the object 	
	var obj = $("#gallery");

	//Create a reference for all images and it's content using .parent()
	//Remember to pass the object reference "obj" into the identifier.
	var image = $('img', obj);
	var imageContainer = $('img', obj).parent();

	//We wan't to hide the both images and content
	imageContainer.hide();
	//But we want to show content of the first image since it's selected by default. 
	imageContainer.eq(0).show();
	
	//append the object with the tab container (ul).
	obj.append('<div class="image_list"><div class="image_list_inner"><ul><\/ul><\/div><\/div>');
	
	//For every image create an item (<li>)
	for(var i=0;i<image.length;i++) {
		
		var sel;
		
		//The first object is selected by default so add class="sel" to it
		if(i == 0){
			sel = 'sel';
		}
		//Else set it to empty
		else {
			sel ="";
		}
		//grab the image path from main image
		var imagePath = image.eq(i).attr("src");
		//create image nav list and insert the image in that list. Please note css controls the dimensions
		$(".image_list ul", obj).append('<li class="'+sel+'"><img src="'+imagePath+'"\/><\/li>');
	}
	
	//Create a reference to the thumbnail for each obj
	var imageNav = $(".image_list ul li", obj);
				
	imageNav.click(function() {
		
		//When a thumbnail image is clicked "de-activate" the old one
		$(".image_list li.sel", obj).removeClass("sel");
		imageContainer.hide();
		$(this).addClass("sel");
		
		//And display the clicked thumbnail image
		var current = imageNav.index($(this));
		imageContainer.eq(current).show();
	});			
	
}


//**********************************
//Course Enquiry Form Validation
//**********************************
function validateEnquiry() {	

	$(".enquiry button").click(function(){	
									
	$(".enquiry .error").hide();
	
	var hasError = false;
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	
	var emailFromVal = $("#Email").val();
	if(emailFromVal == '') {
		$("#Email").parent().after('<span class="error">You forgot to enter your email address.</span>');
		hasError = true;
	} else if(!emailReg.test(emailFromVal)) {	
		$("#Email").parent().after('<span class="error">Enter a valid email address.</span>');
		hasError = true;
	}
			
	var nameVal = $("#Name").val();
	if(nameVal == '') {
		$("#Name").parent().after('<span class="error">You forgot to enter your name.</span>');
		hasError = true;
	}
	
	var commentsVal = $("#Comments").val();
	if(commentsVal == '') {
		$("#Comments").parent().after('<span class="error">Please enter a comment.</span>');
		hasError = true;
	}
	
	if(hasError == false) {
		return true;
	}
	
	return false;
	
	});
	
}

//Print Function
function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}




//**********************************
//Load Functions
//**********************************
$(document).ready( function() {
	
		
	$('ul.tabs li').mouseover( function() {
		$(this).addClass('active');
	});
	$('ul.tabs li').mouseout( function() {
		$(this).removeClass('active');
	});
	
	//activate accordian
	jQuery('.accordion').accordion({ 
		autoheight: false,
		header: 'h2',
		selectedClass: 'active',
		animated: 'easeslide',
		event: 'click'
	});		
	
	//hide image for flash replacement
	$('.flash img').hide();

	//activate drop downs
	sfHover();
	$('#menu ul').bgIframe({opacity:true});
	
	//external link
	$("a.newwindow").click( function() {
        this.target = "_blank";
    });

	$(function() {	
		$('#utilities').append('<li><a href="" class="sendFriend" title="Send to a Friend">Send to a Friend</a></li><li><a href="" id="resizeFont" title="Increase Font Size">Font Increase</a></li>');
	});	
	

	
	//Home Section
	$(function() {
		if($('.content').hasClass('home')) {	   
			$('.content').removeClass('home');
			$('.content').addClass('home_jsActive');
			var subcontent_height = $('.sub_content').height();
			var banner_height = $('.banner').height();
			var content_height = subcontent_height + banner_height;
			$('.home_jsActive').css('min-height',content_height+25);
			if ($.browser.msie) {
				$('.home_jsActive').css('height',content_height+75);
				$('#header').css('position', 'relative');
				$('#header').css('z-index', '9999');
			}
			
		}
	});
	
	$(function() {
		if($(".map_content")) {
		$(".map_content").eq(0).prepend('<div id="themap"></div>');
		}
	 });
	
	
	
	//Campuses Section
	//resize height according to map section height
	function checkHeight() {
		
		var content =$('.main_content').height();
		var subcontent = $('.sub_content').height();
		var banner = $('.banner').height();
		
		if ( content < subcontent ) {
			var totalContent = subcontent + banner;
			$('.campuses_jsActive').css('min-height',totalContent);
			if ($.browser.msie) {
				$('.campuses_jsActive').css('height',totalContent);
			}	
		} else {
			$('.campuses_jsActive').css('min-height',content);
			var totalContent = content + banner;
			if ($.browser.msie) {
				$('.campuses_jsActive').css('height',totalContent);
			}
			}
	}	
	
	//switch styles
	$(function() {
		if($('.content').hasClass('campuses')) {	
			$('.content').removeClass('campuses');
			$('.content').addClass('campuses_jsActive');
			checkHeight();
		}
	});
		

	//resize height when tab is clicked.
	$('.tabs li').click( function() {
	    if($('.content').hasClass('campuses_jsActive'))
		checkHeight();
	});
	
	
	//Gallery Slideshow
	$(function() {
	 	if($('.slideshow')) {
			$('.slideshow').addClass('slideshow_jsActive');
			$('.slideshow').removeClass('slideshow');
			
			$('.image_holder') 
			.after('<div class="pagination">') 
			.cycle({ 
			fx:     'scrollLeft', 
			speed:  'fast', 
			timeout: 0, 
			pager:  '.pagination' 
			});	
		}
	});
	
	//Print Button
	$(".print").click( function() {
		if (window.print) window.print();
		else if (VBS) printIt();
		else alert('This script does not work in your browser');
		return false;

	});
	
	$(".print-course").attr({
		href: window.location+"?format=print"
	});
	
	
//	$("a.print").toggle(
//	  function () {
//		setActiveStyleSheet('print preview');
//		$(this).addClass("active");
//		return false;
//	
//	  },
//	  function () {
//		setActiveStyleSheet('default');
//		$(this).removeClass("active");
//		return false;
//	  }
//	);
	
	
	
	//Text Resize Button
	textresize();	

	//Launch Gallery Script if #gallery is available
	$(function() {
		if($('#gallery')) {
			gallery();
		}
	 });
	
	//Send to friend
	$(function() {
		var SubjectLine='I thought you might be interested in this page from NMIT, '+top.document.title; 
		var BodyText='You can see this page at: '+top.location.href;
		$('.sendFriend').attr({
			href:'mailto:?SUBJECT='+escape(SubjectLine)+'&BODY='+escape(BodyText)
		});
	 });
	
	
	//Search Forms
	$(function() {
		$("#courseType").change(function() {
			if ($(this).val() == "short_courses") {
				$('#hidden_fields').hide();
				$('#qualification').attr('selectedIndex',0);
				$('#internationalCourse').attr('checked',false);				
			} else {
				$('#hidden_fields').show();
			}
		});
	});

	
	//Application form
	
	$('form#application #second_pref').hide();
	$('form#application #third_pref').hide();
	$('form#application #referral_otherpanel').hide();
	$('form#application #influence_otherpanel').hide();
	$('form#application #disability').hide();
	$('form#application .hiddenField').hide();
	
	
	$('#DisabilityAssistYes').click( function() {
											  
			$('form#application #disability').slideDown("slow");
	});
	$('#DisabilityAssistNo').click( function() {
		$('form#application #disability').slideUp("slow");
			  
	});
	
	
	$('#InfluenceOther').click( function() {
										  
		if ( $("#InfluenceOther").is(":checked") ) {
				$('form#application #influence_otherpanel').slideDown("slow");
		} else {
			$('form#application #influence_otherpanel').slideUp("slow");
		}
	
	});
	

	$('#ReferralOther').click( function() {
										  
		if ( $("#ReferralOther").is(":checked") ) {
				$('form#application #referral_otherpanel').slideDown("slow");
		} else {
			$('form#application #referral_otherpanel').slideUp("slow");
		}
	
	});	
	
/*
	$(function() {
		$("#first_pref").append('<div class="row required block"><div class="label"><p><label>Course*</label></p></div><div class="field"><p><select name="Course1" id="Course1"><option value="">Please Select</option><option value="A1">Advanced Diploma of Children Services</option><option value="A2">Certificate III in Aged Care Work</option><option value="A3">Certificate III in Children Services</option><option value="A4">Certificate III in Health Support Assistance</option><option value="A5">Certificate III in Home and Community Care (HACC)</option><option value="A6">Certificate IV in Community Service Work</option></select></p></div></div><div class="row required block"><div class="label"><p><label>Campus*</label></p></div><div class="field"><p><select name="Campus1" id="Campus1"><option>Please Select</option><option value="1">Collingwood</option><option value="2">Heidelberg</option></select> </p></div></div>');
	});

	$(function() {
		$("#second_pref").append('<div class="row required block"><div class="label"><p><label>Course*</label></p></div><div class="field"><p><select name="Course2" id="Course2"><option value="">Please Select</option><option value="A1">Advanced Diploma of Children Services</option><option value="A2">Certificate III in Aged Care Work</option><option value="A3">Certificate III in Children Services</option><option value="A4">Certificate III in Health Support Assistance</option><option value="A5">Certificate III in Home and Community Care (HACC)</option><option value="A6">Certificate IV in Community Service Work</option></select></p></div></div><div class="row required block"><div class="label"><p><label>Campus*</label></p></div><div class="field"><p><select name="Campus2" id="Campus2"><option>Please Select</option><option value="1">Collingwood</option><option value="2">Heidelberg</option></select> </p></div></div>');
	});

	$(function() {
		$("#third_pref").append('<div class="row required block"><div class="label"><p><label>Course*</label></p></div><div class="field"><p><select name="Course3" id="Course3"><option value="">Please Select</option><option value="A1">Advanced Diploma of Children Services</option><option value="A2">Certificate III in Aged Care Work</option><option value="A3">Certificate III in Children Services</option><option value="A4">Certificate III in Health Support Assistance</option><option value="A5">Certificate III in Home and Community Care (HACC)</option><option value="A6">Certificate IV in Community Service Work</option></select></p></div></div><div class="row required block"><div class="label"><p><label>Campus*</label></p></div><div class="field"><p><select name="Campus3" id="Campus3"><option>Please Select</option><option value="1">Collingwood</option><option value="2">Heidelberg</option></select> </p></div></div>');
	});
*/	
	 $("form#application #Course1").change(function () {
			if ($(this).val() == "") { 	
				$('form#application #second_pref').slideUp("slow");
				$('form#application #third_pref').slideUp("slow");
			} else {
	   			$('form#application #second_pref').slideDown("slow");
			}
     })

	 $("form#application #Course2").change(function () {
			if ($(this).val() == "") { 	
				$('form#application #third_pref').slideUp("slow");
			} else {
	   			$('form#application #third_pref').slideDown("slow");
			}
     })
	 
	 
	 $('#studyarea_courses').addClass('tabify');
	 $('#department_courses').addClass('tabify');

	//subsection tabs
	$('.tabify').tabify();


});