/* 
Author: 
Brian Barthold

Client: 
Civitas Schools

*/
jQuery(document).ready(function(){	
								

	/* USED FOR FAQ PAGE AND CAMPUS INSTRUCTORS */
	if ($('.accordion').length) {		
			
			if ($('.northtown-academy').length) {
				var borderColor = '#FF7F00';
			} else if ($('.wrightwood').length) {
				var borderColor = '#FFBF00';				
			} else if ($('.ralph-ellison').length) {
				var borderColor = '#FF6418';				
			} else {
				var borderColor = '#01A4AF';	
			}
			
			
			$('.col1').addClass('faq');
			$('.col1 h2').each(function(i) {
				$(this).prepend('<span>+&nbsp;</span>');
				//wrap all elements between h2 tags in a div				  
				$(this).nextUntil('h2').wrapAll('<div></div>');
				$(this).css('border','1px solid '+borderColor);
			});				
			//apply accordion
			$('.col1 h2').click(function() {//alert($(this).child('span').text());
				$(this).css('padding-top','2px');
				
				$(this).css('background-color','#F7F7F7');
				/*$(this).next().css('background-color','#fff');*/
				$(this).css('border-top','1px solid '+borderColor);
				$(this).css('border-right','1px solid '+borderColor);			
				$(this).css('border-left','1px solid '+borderColor);	
				$(this).css('border-bottom','0');	
				$(this).next().toggle();
				if($(this).next().css('display') == 'none' ) {
					$(this).children('span').html('<span>+&nbsp;</span>');
					$(this).css('background-color','#F7F7F7');
					$(this).css('border-bottom','1px solid '+borderColor);	
				} else {
					$(this).children('span').html('<span>&ndash;&nbsp;</span>');
				}
				return false;
			}).next().hide();//.next().hide().$(this).children('span').html('<span>-&nbsp;</span>');										
	}	
	
    /* OPEN LINKS IN NEW WINDOW */
    var safeList = ['civitasschools.org'];
	
	/**
	  * you can hide the warning from external links if they are deemeed safe. none of the domains below will show a warning
	  */
	var noWarning = [''];  
	
	$.extend($.expr[':'], {	
		external: function(a, i, m) {	
			if (!a.href) { return false; }
			if (a.hostname && a.hostname !== window.location.hostname) {
				var fixedHostname = a.hostname.replace(/^\s+|\s+$/g, '').replace('www.', '').toLowerCase();	
					if (jQuery.inArray(fixedHostname, safeList) >= 0) {
					return false;
				}
				else return true;
			}
			else return false;
		}
	});	
	
	$('a:external').attr("target", "_blank");//.after(' <img src="/assets/css/img/external.png" alt="external link" height="10" width="10" />')						  	
		
	$(".northtown-academy .summary").next("ul").addClass("bottom");
	$(".ralph-ellison .summary").next("ul").addClass("bottom");
	$(".wrightwood .summary").next("ul").addClass("bottom");	
	
	
});		



// INCLUDE USED FOR GOOGLE MAPS ON CAMPUS PAGES AND MAIN CONTACT PAGE

var Include = function () {
  var Include = function (src) {
    var reg = null;
    for (var i = 0; reg = Include.registry[i]; i++) {
      if (reg.toLowerCase() == src.toLowerCase()) {
        return false;
      }
    }
    
    var head   = document.getElementsByTagName('head')[0];
    var script = document.createElement("script");
      
    script.src  = src.match(/^\//) ? src : Include.base + src;
    script.type = "text/javascript";
    script.language = "javascript";
      
    head.appendChild(script);
    return script;
  };
  
  Include.registry = [];
  Include.Once = function (src) {
    var script = Include(src);
    Include.registry[Include.registry.length] = src;
    return script;
  };
  
  var base     = document.getElementsByTagName("base")[0];
  Include.base = base ? base.href : "";
  
  return Include;
}();





