// Utilizing MooTools Library http://www.mootools.net

// Custom event handler to prevent conflict between libraries using window.addEvent 
var AC = {
    addEvent: function(el, type, fn) {
        if (el.attachEvent) {
            el['e' + type + fn] = fn;
            el[type + fn] = function() { el['e' + type + fn](window.event); }
            el.attachEvent('on' + type, el[type + fn]);
        } else {
            el.addEventListener(type, fn, false);
        }
    },
    removeEvent: function(el, type, fn) {
        if (el.detachEvent) {
            el.detachEvent('on' + type, el[type + fn]);
            el[type + fn] = null;
        } else {
            el.removeEventListener(type, fn, false);
        }
    }
};





AC.addEvent(window, 'load', setup);

function setup() {





    // if ($chk($('AC-PhotoList'))) { var PhotoThumb = new ACThumbnailer('AC-PhotoList', 'AC-PhotoThumbs', 'AC-PhotoImage', 'AC-NewsStory'); }

    Cufon.replace('#breadCt h3', { fontFamily: 'Gotham Medium' });
    Cufon.replace('#pageTitle h1', { fontFamily: 'Gotham Light'});
    Cufon.replace('h1', { fontFamily: 'Gotham Light' });
Cufon.replace('h2', { fontFamily: 'Gotham Light' });
Cufon.replace('h3', { fontFamily: 'Gotham Light' });
Cufon.replace('h4', { fontFamily: 'Gotham Light' });
Cufon.replace('h5', { fontFamily: 'Gotham Light' });
Cufon.replace('h6', { fontFamily: 'Gotham Light' });
    Cufon.replace('.AC-BlockHeader h4', { fontFamily: 'Gotham Light' });
    Cufon.replace('.AC-Events .AC-Date .AC-Month', { fontFamily: 'Gotham Black' });
    Cufon.replace('.AC-Events .AC-Date .AC-Day', { fontFamily: 'Gotham Black' });

    Cufon.replace('.AC-News.FeaturedStory .AC-BlockHeader H4', { fontFamily: 'Gotham Medium' });
    Cufon.replace('.AC-FinAidProcess .AC-BlockHeader h4', { fontFamily: 'Gotham Medium' });
    Cufon.replace('#AC-Tabs h6', { fontFamily: 'Gotham Medium' });
    Cufon.replace('#AC-Tabs h5', { fontFamily: 'Gotham Medium' });

    Cufon.replace('#AC-TabsPrograms h5', { fontFamily: 'Gotham Medium' });
    Cufon.replace('.AC-ApplyListingAdmissions .AC-BlockHeader h4', { fontFamily: 'Gotham Medium' });
    Cufon.replace('.AC-TitleApp  h4', { fontFamily: 'Gotham Medium' });
    Cufon.replace('.alumni #navPage UL LI A', { fontFamily: 'Gotham Medium' ,
                         hover: true
	    });	




    Cufon.replace('#sectTitle h2', { fontFamily: 'Gotham Light' });
    Cufon.replace('.AC-TodoHeader H4', { fontFamily: 'Gotham Light' });
    Cufon.replace('#AC-EventsListing H4', { fontFamily: 'Gotham Medium' });
    Cufon.replace('#AC-SpotArchive H4', { fontFamily: 'Gotham Medium' });
    Cufon.replace('#AC-NewsArchive H4', { fontFamily: 'Gotham Medium' });


    Cufon.replace('#AC-TabsAskUs h5', { fontFamily: 'Gotham Medium' });
    Cufon.replace('.AC-SearchResults h4', { fontFamily: 'Gotham Medium' });
    Cufon.replace('#applicationSelectHeader h4', { fontFamily: 'Gotham Medium' });


  if($chk($$('.home')[0]))
{


    function cuReplace() {
        Cufon('.homePage #AC-Tabs .AC-BlockHeader.SS h5');
        Cufon('.homePage #AC-Tabs .AC-BlockHeader.SS h6');
        Cufon('.homePage #AC-Tabs .AC-BlockHeader.FP h5');
        Cufon('.homePage #AC-Tabs .AC-BlockHeader.FP h6');
        Cufon('.homePage #AC-Tabs .AC-BlockHeader.SI H5');
        Cufon('.homePage #AC-Tabs .AC-BlockHeader.SI H6');

    }



   var flashvars = {};
                                  flashvars.mediaURL = $('vURLSS').get('html');
                                  flashvars.teaserURL = "";
                                  flashvars.allowSmoothing = "true";
                                  flashvars.autoPlay = "false";
                                  flashvars.buffer = "6";
                                  flashvars.showTimecode = "false";
                                  flashvars.loop = "false";
                                  flashvars.controlColor = "0xFFFFFF";
                                  flashvars.controlBackColor = "0x000000";
                                  flashvars.scaleIfFullScreen = "true";
                                  flashvars.showScalingButton = "true";
                                  flashvars.defaultVolume = "100";
                                  flashvars.crop = "true";

                                  var params = {};
                                  params.menu = "false";
                                  params.allowFullScreen = "true";
                                  params.allowScriptAccess = "always";
                                  params.wmode = "transparent"

                                  var attributes = {};
                                  attributes.id = "nonverblaster";
                                  attributes.name = "nonverblaster";
                                  attributes.bgcolor = "transparent"

                                  swfobject.embedSWF("/Media/Website%20Resources/flash/NonverBlaster.swf", "SSVideo", "538", "302", "9", "/Media/Website%20Resources/flash/expressinstall.swf", flashvars, params, attributes);

                                  registerForJavaScriptCommunication("nonverblaster");	

 	

$$('.homePage #AC-Tabs .AC-BlockHeader.SS').addClass('active');

   cuReplace();
   
        
        $$('.homePage #AC-Tabs .AC-BlockHeader.SS').addEvent('click', function(e) {
            sendToNonverBlaster('resetAll');
            $$('.homePage #AC-Tabs .AC-BlockHeader.SS').addClass('active');
            $$('.homePage #AC-Tabs .AC-BlockHeader.FP').removeClass('active');
            $$('.homePage #AC-Tabs .AC-BlockHeader.SI').removeClass('active');
            
            
            $('SSThumb').setStyle('z-index', '1');
            $('FPThumb').setStyle('z-index', '0');
            $('SIThumb').setStyle('z-index', '0');
            
            $('SSThumb').setStyle('display', 'block');
            $('FPThumb').setStyle('display', 'none');
            $('SIThumb').setStyle('display', 'none');
            
            
            
            
            
            
    
            cuReplace();
	        //playVideo(0);
            


            return false;
        });

        $$('.homePage #AC-Tabs .AC-BlockHeader.FP').addEvent('click', function(e) {
            sendToNonverBlaster('resetAll');
            $$('.homePage #AC-Tabs .AC-BlockHeader.FP').addClass('active');
            $$('.homePage #AC-Tabs .AC-BlockHeader.SS').removeClass('active');
            $$('.homePage #AC-Tabs .AC-BlockHeader.SI').removeClass('active');
            
            
             $('SSThumb').setStyle('z-index', '0');
            $('FPThumb').setStyle('z-index', '1');
            $('SIThumb').setStyle('z-index', '0');
            
            $('FPThumb').setStyle('display', 'block');
            $('SSThumb').setStyle('display', 'none');
            $('SIThumb').setStyle('display', 'none');
            
            
           
           

            		
            cuReplace();
            //playVideo(1);

			


            return false;
        });


        $$('.homePage #AC-Tabs .AC-BlockHeader.SI').addEvent('click', function(e) {
            sendToNonverBlaster('resetAll');
            $$('.homePage #AC-Tabs .AC-BlockHeader.SI').addClass('active');
            $$('.homePage #AC-Tabs .AC-BlockHeader.SS').removeClass('active');
            $$('.homePage #AC-Tabs .AC-BlockHeader.FP').removeClass('active');
            
             $('SSThumb').setStyle('z-index', '0');
            $('FPThumb').setStyle('z-index', '0');
            $('SIThumb').setStyle('z-index', '1');
            
            
            $('SIThumb').setStyle('display', 'block');
            $('FPThumb').setStyle('display', 'none');
            $('SSThumb').setStyle('display', 'none');
            
           
            


            cuReplace();
	        //playVideo(2);

            return false;
        });


        $('SSThumb').addEvent('click', function(e) {
            $('SSThumb').setStyle('display', 'none');
            playVideo(0);
             
        return false;
        });
        
        $('FPThumb').addEvent('click', function(e) {
            $('FPThumb').setStyle('display', 'none');
            playVideo(1);
             
        return false;
        });
        
        $('SIThumb').addEvent('click', function(e) {
            $('SIThumb').setStyle('display', 'none');
            playVideo(2);
             
        return false;
        });




// Just a small example how to switch through all the videos
      // First an Array with all the videos we want to play back
      //var videos = new Array($('vURLSS').get('html'), $('vURLFP').get('html'), $('vURLSI').get('html'));

      var videos = [
      $('vURLSS').get('html'),
      $('vURLFP').get('html'),
      $('vURLSI').get('html')
      ];


      // The id of the Video that should be played back first
      var videoID = 0;
      // Set the HTML-Buttons to the current state
      //adjustPlaylistButtons();

      function nextVideo() {
      videoID++;
      if (videoID == videos.length) {
      videoID = 0;
      }
      playVideo(videoID);
      }
      function playVideo($videoID) {
      videoID = $videoID;
      sendToNonverBlaster("switch:" + videos[videoID]);
      //adjustPlaylistButtons();
      }
      // Use this function if you want to automatically play the next video if the last was finished
      function computeEnd() {
      //nextVideo();

      }


}



    if ($chk($('AC-TabsAskUs'))) {
        $$('#footerAskUS_TextBoxNotes .value textarea').setStyle('height', '50px');
        $$('#footerAskUS_TextBoxNotes .label.required label').set('text', 'Question?');

    }

    if ($chk($$('.AC-AppType'))) {

        var applicationTypes = $$('div.AC-AppListing');
			
        if (applicationTypes.length > 1) {
			appTypeCt = new Element('div',{'class':'AC-AppTypeCt'});
			appTypeCt.addClass('clearfix');
			appTypeCt.inject(applicationTypes[0],'before');
			applicationTypes.each(function(item,index){
				item.clone().inject(appTypeCt);
				item.destroy();
			});		
        }
    }

    //alert($$('#askUsCtr .AC-Form #footerAskUS_TextBoxEmail').hasClass('field AC-Error')); 
    if ($$('#askUsCtr .AC-Form #footerAskUS_TextBoxEmail').hasClass('field AC-Error') == 'true') { scrollToAskUS() };
    if ($$('#askUsCtr .AC-Form #footerAskUS_TextBoxFirstName').hasClass('field AC-Error') == 'true') { scrollToAskUS() };
    if ($$('#askUsCtr .AC-Form #footerAskUS_TextBoxLastName').hasClass('field AC-Error') == 'true') { scrollToAskUS() };
    if ($$('#askUsCtr .AC-Form #footerAskUS_TextBoxNotes').hasClass('field AC-Error') == 'true') { scrollToAskUS() };
    if ($$('#askUsCtr .AC-Alert #ac-errorul li').get('html') > '') { scrollToAskUS() };


    function scrollToAskUS() {
        var bodySize = $$('BODY')[0].getScrollSize().y;
        $$('BODY')[0].scrollTo(0, bodySize);
    }
    

    





    if ($chk($('AC-SliderWithNav'))) {

        //var random = Math.floor(Math.random()* $$('.slide').length);  

        new SimpleSlideShowDemo({
            startIndex: 0,
            slides: $$('.slide'),
            currentIndexContainer: 'slide', //an element or it's id
            maxContainer: 'slideMax',
            nextLink: 'AC-Next',
            prevLink: 'AC-Prev',
            autoStart: true
        });
    }




    var accordion = new Accordion('div.toggleHead', 'div.toggleBody', { opacity: false, show: -1, alwaysHide: true });

    if ($chk($('AC-ProgramGrid'))) {
        var Sorttable = new SortingTable('AC-ProgramGrid', { zebra: false, dont_sort_class: 'nosort', forward_sort_class: 'forward_sort', reverse_sort_class: 'reverse_sort' });
        $$('#AC-ProgramGrid TBODY TR').addEvent('mouseover', function(e) { this.toggleClass('highlight'); });
        $$('#AC-ProgramGrid TBODY TR').addEvent('mouseout', function(e) { this.toggleClass('highlight'); });

        $('programDD').addEvent('change', function(e) {
            if ($chk($('nothingHere'))) { $('nothingHere').destroy(); }
            $$('#AC-ProgramGrid TBODY TR').each(function(row) {
                if ($('programDD').value == 'All') {
                    row.removeClass('hiddenRow');
                } else {

                    if (!row.hasClass($('programDD').value)) {
                        row.addClass('hiddenRow');
                    } else {
                        row.removeClass('hiddenRow');
                    }
                }
            });
            if ($$('#AC-ProgramGrid TBODY TR.hiddenRow').length == $$('#AC-ProgramGrid TBODY TR').length) {
                nothingHereTR = new Element('tr', { 'class': 'nothingHere', 'id': 'nothingHere' }).inject($$('#AC-ProgramGrid TBODY')[0]);
                nothingHereTD = new Element('td', { 'html': '<p>There are no areas of study that are in this academic division</p>', 'colspan': '3' }).inject(nothingHereTR);
            }
        });
    }
}


window.addEvent('domready', function(){    
    if($chk($$('.AC-InlineLogin')[0]))
    
    {
        $$('.AC-InlineLogin').adopt($('navTools'));
        
        $$('#navTools UL LI A').setStyle('text-align', 'left');
        $$('#navTools UL LI A').setStyle('padding-right', '0px');
         $$('#navTools UL LI').setStyle('width', '205px');
         $$('#navTools').setStyle('margin-left', '-34px');
         $$('#navTools').setStyle('width', '431px');
         $$('#navTools').setStyle('float', 'none');
          $$('#navTools').setStyle('margin-top', '-40px');
    
    }
    
    if(!$chk($$('.AC-AdmissionsNavigation .AC-BlockText ul li.welcomeMessage')[0])){
        if($chk($$('.AC-InlineLogin')[0])){
        $$('#navTools').setStyle('padding-left', '2em');
        }
    
    }
    
  });   

