// ** Navigation **
// **            **
$(function(){ // (executes when the dom is ready)
	
	$("#navigation>li").hover(function(){
		$(this).addClass("active");
	}, function(){
		$(this).removeClass("active");
	});
	
});

// ** Home Image Rotation **
// **                     **
$(function(){ // (executes when the dom is ready)
	
	var bannersEnglish = [], bannersEnglishText = [];
	bannersEnglish.push("header-home-get-the-facts"); // add appropriate classnames
	bannersEnglishText.push("Get the facts, plan, apply"); // add appropriate headline text
	bannersEnglish.push("header-home-make-college-happen");
	bannersEnglishText.push("Make college happen");
	bannersEnglish.push("header-home-your-future");
	bannersEnglishText.push("Your future starts here");
	
	var bannersSpanish = [], bannersSpanishText = [];
	bannersSpanish.push("header-home-informate-planea"); // add appropriate classnames
	bannersSpanishText.push("Infórmate, planea, aplica"); // add appropriate headline text
	bannersSpanish.push("header-home-college-hazlo");
	bannersSpanishText.push("College: Házlo tuyo.¡Yá!");
	bannersSpanish.push("header-home-tu-futuro");
	bannersSpanishText.push("Tu futuro comienza aquí");

	var randomNumberEnglish = Math.floor(Math.random() * bannersEnglish.length);
	var randomNumberSpanish = Math.floor(Math.random() * bannersSpanish.length);
	
	// will display a random classname taken from the lists above
	// which will display a random home page banner
	$("#header-home").removeClass(); // remove hardcoded class name
	if ($("body").hasClass("spanish")) {
		$("#header-home").addClass(bannersSpanish[randomNumberSpanish]);
		$("#header-home").parent().find("h2").text(bannersSpanishText[randomNumberSpanish]);
	} else {
		$("#header-home").addClass(bannersEnglish[randomNumberEnglish]);
		$("#header-home").parent().find("h2").text(bannersEnglishText[randomNumberEnglish]);
	};
	
});

// ** Popup windows **
// **               **
$(function(){ // (executes when the dom is ready)
	
	
	$.popupWindowOverlay = function(showPage,overlayTitle,iconType) {
		// get height of html content
		var htmlHeight = $(document).height();
		// remove existing overlay
		$("#blackout,#overlay-window").remove();
		// add overlay code
		$("body").append('<div id="blackout"></div><div id="overlay-window"><div id="overlay-inside"><div id="overlay-inside2"><div id="overlay-title"></div><div id="overlay-close"></div><div id="overlay-content"><iframe id="overlay-iframe" src="about:blank" width="100%" height="100%" frameborder="0" scrolling="auto"></iframe></div></div></div></div>');
		// set blackout to height of html
		$("#blackout").css("height",htmlHeight+"px");
		// fix overlay window height for ie6-
		if ($.browser.msie && ($.browser.version <= 6)) {
			$("#overlay-window").css("height",$(window).height()+"px");
			$("#overlay-inside").css("height","93%");
		};
		// scroll to top of page
		//$.scrollTo( "#blackout", 500 );
		// position content
		$("#overlay-window").css("top",$(window).scrollTop()+"px");
		// resize content
		//$("#overlay-inside").css("height",$("#overlay-content").innerHeight()+"px");
		$("#overlay-content").css({height:($("#overlay-inside").innerHeight()-55)+"px", width:"804px", position:"absolute", top:"55px"});
		// load content
		$("#overlay-title").text(overlayTitle).addClass(iconType);
		$("#overlay-iframe").attr("src",showPage);
		// make close button work
		$("#overlay-close").click(function(){$("#blackout,#overlay-window").remove();}).css("cursor","pointer");
		// on window resize adjust some values
		$(window).resize(function(){
			$("#overlay-content").css({height:($("#overlay-inside").innerHeight()-55)+"px"});
		});
		// on window scroll adjust values
		$(window).scroll(function(){
			$("#overlay-window").css("top",$(window).scrollTop()+"px");
		});
	};
	
	//$.popupWindowOverlay("http://www.google.com","Apply to College","overlay-type-paper");
	
	// make any links with rel="overlay" to open in overlay window
	// expects links to contain three bits of data, a.) href b.) title c.) rel
	$("a[@rel^='overlay']").click(function(){
		relSplit = this.rel.split(" "); // the second portion of rel value could be the overlay type (icon type)
		$.popupWindowOverlay(this.href,this.title,relSplit[1]);
		return false;
	});
	
});

// ** Click to Show FAQs **
// **                    **
$(function(){ // (executes when the dom is ready)
	
	$(".faq .question").click(function(){
		if ($(this).parent().is(".faq-opened")) {
			$(this).parent().find(".answer").css("display","block").slideUp("normal").oneTime(400, function() {
				$.scrollTo( this, 500, {offset:{left: 0, top:-70 }} );
			});
			$(this).parent().addClass("faq-closed").removeClass("faq-opened");
		} else {
			$(".faq-opened .answer").css("display","block").slideUp("normal");
			$(".faq-opened").addClass("faq-closed").removeClass("faq-opened");
			$(this).parent().find(".answer").slideDown("fast").oneTime(400, function() {
				$.scrollTo( this, 500, {offset:{left: 0, top:-70 }} );
			});
			$(this).parent().addClass("faq-opened").removeClass("faq-closed");
		}
	});
	
	// if any faq's are on the page, close them and open the first
	$(".faq").addClass("faq-closed");
	
	
});

// ** Add search functionality **
// **                          **
$(function(){ // (executes when the dom is ready)
	
	if ($.browser.safari && Math.floor($.browser.version)>400) {
		// add search field for webkit/safari
		// replace existing search box
		$("#input-query").replaceWith('<input id="input-query" class="search-type-box" type="search" name="q" value="" placeholder="Search" results="5" autosave="com.collegefortexans.search"/>');
		// hide button but keep spacing
		$("#input-search").css({visibility:'hidden',left:'0'});
	} else {
		// For other browsers add active/inactive states
		$("#input-query").focus(function() {
			// clear value if the default value exists
			if ($(this).val() == this.defaultValue) { $(this).val(""); }
			$(this).addClass('active'); 
		}).blur(function() {
			// restore default value if value does not exist
			if ($(this).val() == "") { $(this).val(this.defaultValue); }
			$(this).removeClass('active');
		});
	};
	
});

// equalize function
$.equalizeColumns = function(container, options) {
	// equalize heights on sidebar and content area
	if ($("#sidebar-inside").outerHeight()>$("#content-area-inside").outerHeight()) {
		$("#content-area-inside").css("height",$("#sidebar-inside").outerHeight()+2+"px");
	} else {
		$("#sidebar-inside").css("height",$("#content-area-inside").outerHeight()-2+"px");
	};
};


// ** Misc **
// **      **
$(function(){ // (executes when the dom is ready)
	
	// make logo a link to go back to home page
	$("#logo").click(function(){ document.location = "/?HeaderClicked=1"}).css("cursor","pointer");
	
	// equalize heights on sidebar and content area
	$.equalizeColumns();
	
	// make any links with rel="external" to open in new windows
	$("a[@rel$='external']").click(function(){
		this.target = "_blank";
	});
	
	// fix overlay content window height
	$("body.overlay-window-content").each(function(){
		if ($(window).height()>$("#content-overlay-wrapper4").innerHeight()) {
			$(this).parent().css("height","100%");
		};
		$(window).resize(function(){
			if ($(window).height()<$(document).height()) {
				$("html").css("height","auto");
			} else {
				$("html").css("height","100%");
			};
		});
	});
	
	// add customselect where appropriate and on change go to value specified in option element
	$(".customselect").selectbox();
	$(".select-goes-to-url").bind('change', function(){
		if ($(this).val()!=null && $(this).val()!="null" && $(this).val()!="") {
			document.location = $(this).val();
		};
	});
	
});


/* stop IE6 flicker */
try { document.execCommand("BackgroundImageCache", false, true); } catch(err) {}

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 9/11/2008
 * @author Ariel Flesler
 * @version 1.4
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(h){var m=h.scrollTo=function(b,c,g){h(window).scrollTo(b,c,g)};m.defaults={axis:'y',duration:1};m.window=function(b){return h(window).scrollable()};h.fn.scrollable=function(){return this.map(function(){var b=this.parentWindow||this.defaultView,c=this.nodeName=='#document'?b.frameElement||b:this,g=c.contentDocument||(c.contentWindow||c).document,i=c.setInterval;return c.nodeName=='IFRAME'||i&&h.browser.safari?g.body:i?g.documentElement:this})};h.fn.scrollTo=function(r,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};a=h.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=h(k),d=r,l,e={},p=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(d)){d=n(d);break}d=h(d,this);case'object':if(d.is||d.style)l=(d=h(d)).offset()}h.each(a.axis.split(''),function(b,c){var g=c=='x'?'Left':'Top',i=g.toLowerCase(),f='scroll'+g,s=k[f],t=c=='x'?'Width':'Height',v=t.toLowerCase();if(l){e[f]=l[i]+(p?0:s-o.offset()[i]);if(a.margin){e[f]-=parseInt(d.css('margin'+g))||0;e[f]-=parseInt(d.css('border'+g+'Width'))||0}e[f]+=a.offset[i]||0;if(a.over[i])e[f]+=d[v]()*a.over[i]}else e[f]=d[i];if(/^\d+$/.test(e[f]))e[f]=e[f]<=0?0:Math.min(e[f],u(t));if(!b&&a.queue){if(s!=e[f])q(a.onAfterFirst);delete e[f]}});q(a.onAfter);function q(b){o.animate(e,j,a.easing,b&&function(){b.call(this,r,a)})};function u(b){var c='scroll'+b,g=k.ownerDocument;return p?Math.max(g.documentElement[c],g.body[c]):k[c]}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);
//borrowed from jQuery easing plugin
//http://gsgd.co.uk/sandbox/jquery.easing.php
$.easing.elasout = function(x, t, b, c, d) {
	var s=1.70158;var p=0;var a=c;
	if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
	if (a < Math.abs(c)) { a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
};
// jQuery Timers http://jquery.offput.ca/every/
jQuery.fn.extend({everyTime:function(_1,_2,fn,_4,_5){
return this.each(function(){
jQuery.timer.add(this,_1,_2,fn,_4,_5);
});
},oneTime:function(_6,_7,fn){
return this.each(function(){
jQuery.timer.add(this,_6,_7,fn,1);
});
},stopTime:function(_9,fn){
return this.each(function(){
jQuery.timer.remove(this,_9,fn);
});
}});
jQuery.extend({timer:{guid:1,global:{},regex:/^([0-9]+)\s*(.*s)?$/,powers:{"ms":1,"cs":10,"ds":100,"s":1000,"das":10000,"hs":100000,"ks":1000000},timeParse:function(_b){
if(_b==undefined||_b==null){
return null;
}
var _c=this.regex.exec(jQuery.trim(_b.toString()));
if(_c[2]){
var _d=parseInt(_c[1],10);
var _e=this.powers[_c[2]]||1;
return _d*_e;
}else{
return _b;
}
},add:function(_f,_10,_11,fn,_13,_14){
var _15=0;
if(jQuery.isFunction(_11)){
if(!_13){
_13=fn;
}
fn=_11;
_11=_10;
}
_10=jQuery.timer.timeParse(_10);
if(typeof _10!="number"||isNaN(_10)||_10<=0){
return;
}
if(_13&&_13.constructor!=Number){
_14=!!_13;
_13=0;
}
_13=_13||0;
_14=_14||false;
if(!_f.$timers){
_f.$timers={};
}
if(!_f.$timers[_11]){
_f.$timers[_11]={};
}
fn.$timerID=fn.$timerID||this.guid++;
var _16=function(){
if(_14&&this.inProgress){
return;
}
this.inProgress=true;
if((++_15>_13&&_13!==0)||fn.call(_f,_15)===false){
jQuery.timer.remove(_f,_11,fn);
}
this.inProgress=false;
};
_16.$timerID=fn.$timerID;
if(!_f.$timers[_11][fn.$timerID]){
_f.$timers[_11][fn.$timerID]=window.setInterval(_16,_10);
}
if(!this.global[_11]){
this.global[_11]=[];
}
this.global[_11].push(_f);
},remove:function(_17,_18,fn){
var _1a=_17.$timers,ret;
if(_1a){
if(!_18){
for(_18 in _1a){
this.remove(_17,_18,fn);
}
}else{
if(_1a[_18]){
if(fn){
if(fn.$timerID){
window.clearInterval(_1a[_18][fn.$timerID]);
delete _1a[_18][fn.$timerID];
}
}else{
for(var fn in _1a[_18]){
window.clearInterval(_1a[_18][fn]);
delete _1a[_18][fn];
}
}
for(ret in _1a[_18]){
break;
}
if(!ret){
ret=null;
delete _1a[_18];
}
}
}
for(ret in _1a){
break;
}
if(!ret){
_17.$timers=null;
}
}
}}});
if(jQuery.browser.msie){
jQuery(window).one("unload",function(){
var _1c=jQuery.timer.global;
for(var _1d in _1c){
var els=_1c[_1d],i=els.length;
while(--i){
jQuery.timer.remove(els[i],_1d);
}
}
});
};
/**
 * jQuery custom selectboxes
 * 
 * Copyright (c) 2008 Krzysztof Suszyński (suszynski.org)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * @version 0.6.1
 * @category visual
 * @package jquery
 * @subpakage ui.selectbox
 * @author Krzysztof Suszyński <k.suszynski@wit.edu.pl>
**/
jQuery.fn.selectbox=function(_1){
var _2={className:"custom-selectbox",animationSpeed:"normal",listboxMaxSize:1000,replaceInvisible:false};
var _3="custom-custom-selectboxes-replaced";
var _4=false;
var _5=function(_6){
var _7=_6.parents("."+_2.className+"");
_6.slideDown(_2.animationSpeed,function(){
_4=true;
});
_7.addClass("selecthover");
jQuery(document).bind("click",_8);
return _6;
};
var _9=function(_a){
var _b=_a.parents("."+_2.className+"");
_a.slideUp(_2.animationSpeed,function(){
_4=false;
jQuery(this).parents("."+_2.className+"").removeClass("selecthover");
});
jQuery(document).unbind("click",_8);
return _a;
};
var _8=function(e){
var _d=e.target;
var _e=jQuery("."+_2.className+"-list:visible").parent().find("*").andSelf();
if(jQuery.inArray(_d,_e)<0&&_4){
_9(jQuery("."+_3+"-list"));
}
return false;
};
_2=jQuery.extend(_2,_1||{});
return this.each(function(){
var _f=jQuery(this);
if(_f.filter(":visible").length==0&&!_2.replaceInvisible){
return;
}
var _10=jQuery("<div class=\""+_2.className+" "+_3+"\">"+"<div class=\""+_2.className+"-moreButton\" />"+"<div class=\""+_2.className+"-list "+_3+"-list\" />"+"<span class=\""+_2.className+"-currentItem\" />"+"</div>");
jQuery("option",_f).each(function(k,v){
var v=jQuery(v);
var _13=jQuery("<span class=\""+_2.className+"-item value-"+v.val()+" item-"+k+"\">"+v.text()+"</span>");
_13.click(function(){
var _14=jQuery(this);
var _15=_14.parents("."+_2.className);
var _16=_14[0].className.split(" ");
$(this).parent().find(".item-checked").removeClass("item-checked");
$(this).addClass("item-checked");
for(k1 in _16){
if(/^item-[0-9]+$/.test(_16[k1])){
_16=parseInt(_16[k1].replace("item-",""),10);
break;
}
}
var _17=_14[0].className.split(" ");
for(k1 in _17){
if(/^value-.+$/.test(_17[k1])){
_17=_17[k1].replace("value-","");
break;
}
}
_15.find("."+_2.className+"-currentItem").text(_14.text());
_15.find("select").val(_17).triggerHandler("change");
var _18=_15.find("."+_2.className+"-list");
if(_18.filter(":visible").length>0){
_9(_18);
}else{
_5(_18);
}
}).bind("mouseenter",function(){
jQuery(this).addClass("listelementhover");
}).bind("mouseleave",function(){
jQuery(this).removeClass("listelementhover");
});
jQuery("."+_2.className+"-list",_10).append(_13);
if(v.filter(":selected").length>0){
jQuery("."+_2.className+"-currentItem",_10).text(v.text());
}
});
_10.find("."+_2.className+"-moreButton").click(function(){
var _19=jQuery(this);
var _1a=jQuery("."+_2.className+"-list").not(_19.siblings("."+_2.className+"-list"));
_9(_1a);
var _1b=_19.siblings("."+_2.className+"-list");
if(_1b.filter(":visible").length>0){
_9(_1b);
}else{
_5(_1b);
}
}).bind("mouseenter",function(){
jQuery(this).addClass("morebuttonhover");
}).bind("mouseleave",function(){
jQuery(this).removeClass("morebuttonhover");
});
_f.hide().replaceWith(_10).appendTo(_10);
var _1c=_10.find("."+_2.className+"-list");
var _1d=_1c.find("."+_2.className+"-item").length;
if(_1d>_2.listboxMaxSize){
_1d=_2.listboxMaxSize;
}
if(_1d==0){
_1d=1;
}
var _1e=Math.round(_f.width());
if(jQuery.browser.safari){
_1e=_1e*1;
}
_10.css("width",_1e-16+"px");
_1c.css({width:Math.round(_1e)+4+"px"});
});
};
jQuery.fn.unselectbox=function(){
var _1f="custom-custom-selectboxes-replaced";
return this.each(function(){
var _20=jQuery(this).filter("."+_1f);
_20.replaceWith(_20.find("select").show());
});
};

