/*
Phil Renaud the mad scientist behind this.
phil@rhinointernet.com
http://rhinointernet.com
*/

$(document).ready(function(){
   rootsdown();
   rearrangelayout();
   navigation();

   if($('.majorgallery').length) {
      initializegallery();
//      newbackground();
   } else {
   } //fancybox
//      initializevideo();

   if($('body').hasClass('home')) {
      menucontrols();
   } //fancybox

   if($('.projectlist').length) {
      projectlist();
   } //fancybox
   

   contactpopup();

});
   $('object#flashbg').ready(function() {
      videocontrols();
   }); //ready
   


/*==( Page Layout Considerations )======================================================*/

function rearrangelayout() {

   if ($('#promotionbox').length) {
      $('#pageinfo').css({'width': '589px'});
   } //if no grassnav

   if (!$('#grass #minor').length) {
//      $('#grass #major').css({'width': '740px'});
   } //if no minor

   if (!$('#grass #minor').length && $('body').hasClass('home')) {
      $('#grass #major').css({'width': '760px'});
   } //if no minor, and home

   if (!$('#pageinfo').length && $('#grassnav').length) {
      $('#grassnav').css({'marginLeft': '382px', 'color': '#000', 'display': 'inline'});
   } //if no page info, but grassnav

   if (!$('#pageinfo').length && !$('#grassnav').length) {
      $('#promotionbox').css({'marginLeft': '555px', 'display': 'inline'});
   } //if no page info or grass nav

   if ($('#major').hasClass('tall') && !$('#minor').hasClass('tall')) {
      $('#sod').css({'width': '185px', 'left': '338px'});
      $('#promotionbox').css({'marginLeft': '0px'});
   } //if major's tall, minor ain't
   
   if (jQuery.browser.msie) {
     if(parseInt(jQuery.browser.version) < 7) {
     $('#major.gallery').css({'width': '569px', 'height': '336px', 'padding': '0px'});
     } //ifparseint
   } //ifie

}; //rearrangelayout


/*==( Placing the Roots (flash footer) at absolute bottom )=========================================*/

function rootsdown() {

   $('#worldcontainer').height($(window).height());
   
   $(window).resize(function(){
      $('#worldcontainer').height($(window).height());
   });

}; //rootsdown


/*==( Gallery Initialization and Interaction )======================================================*/

function initializegallery() {

$('.majorgallery').wrap('<div class="majorgallerycontainer"></div>');
$('.minorgallery').wrap('<div class="minorgallerycontainer"></div>');
$('.majorgallerycontainer').append('<a href="#" class="goleft">Go Left</a><a href="#" class="goright">Go Right</a>');

   $('div.majorgallerycontainer').append('<ul class="gallerynav"></ul>');
   $('ul.majorgallery').children('li').each(function(){
      $('ul.gallerynav').append('<li>&nbsp;</li>');
   }); //each li in majorgallery

   $('ul.gallerynav').children('li:first').addClass('active');

   $('.minorgallery').parent('#minor').css({'overflow': 'hidden'});
   $('.minorgallery li').css({'overflow': 'auto'});
   
   $('.minorgallery').css({'width': $('.minorgallery li').outerWidth() * $('.minorgallery').children().length});
//   $('.majorgallery').css({'width': $('.majorgallery li').outerWidth() * $('.majorgallery').children().length});
   $('.majorgallery').css({'width': '5000px'});
   galleryinteraction();
}; //initializegallery



function galleryinteraction() {
   $('ul.gallerynav').children('li').click(function(){
      whichdidiclick = $(this).index();
      $(this).addClass('active').siblings('.active').removeClass('active');
      $('ul.majorgallery').css({'left': -$('ul.majorgallery').children('li').eq(whichdidiclick).position().left});
      $('ul.minorgallery').css({'left': -$('ul.minorgallery').children('li').eq(whichdidiclick).position().left});
//alert($('ul.majorgallery').children('li').eq(whichdidiclick).offset().left);
//      $('ul.majorgallery').animate({'left': -$('ul.majorgallery').children('li').eq(whichdidiclick).offset().left}, {duration: 1000, easing: 'expoinout'});
      return false;
   }); //click
   
   $('.goright').click(function(){
      if ($('ul.gallerynav').children('li.active').is(':last-child')) {
         $('ul.gallerynav').children('li:first-child').click();
      } else {
         $('ul.gallerynav').children('li.active').next('li').click();
      }; // if last
      return false;
   }); //click goright

   $('.goleft').click(function(){
      if ($('ul.gallerynav').children('li.active').is(':first-child')) {
         $('ul.gallerynav').children('li:last-child').click();
      } else {
         $('ul.gallerynav').children('li.active').prev('li').click();
      }; // if first
      return false;
   }); //click goleft
   
}; //galleryinteraction




/*==( Menu Interaction )======================================================*/

function menucontrols() {
   $('a.menulink').toggle(function() {
      $('#navigation').slideUp(500);
      $(this).css({'backgroundImage': 'url(/images/menudown.png)'});
   }, function() {
      $('#navigation').slideDown(500);
      $(this).css({'backgroundImage': 'url(/images/menuup.png)'});
   }); //toggle
}; //menucontrols




/*==( Navigation Expanding and Contracting )======================================================*/

function navigation() {

   $('#navigation ul').css({'display': 'none'});
   $('#navigation').find('a').each(function() {
      if ($(this).attr('href') == window.location.pathname) {
         $(this).parent('li').children('ul').css({'display': 'block'})
         $(this).parent('li').parents('ul').css({'display': 'block'})
         $(this).parents('li').children('a').css({'color': '#fdce86'});
      }; // if
   }); //each link in navigation

   $('ul.projectlist').find('a').each(function() {
      if ($(this).attr('href') == window.location.pathname) {
         $(this).css({'color': '#600'});
      }; // if
   }); //each link in navigation

}; //navigation


/*==( Contact Popup )======================================================*/

function contactpopup() {
   $('.contactlink').click(function() {
      $('.popupcontainer').show();
      return false;
   }); //contactlink click
$('.closepopup').click(function() {
$('.popupcontainer').hide();
}); //closepopup click
}; //contactpopup


/*==( Video Backgrounds )======================================================*/

function initializevideo() {

      var urlpath = window.location.pathname;

      $('#flashbg').css({'position': 'absolute', 'width': '100%', 'height': $('#worldcontainer').height()});

		flashvars = {
   		file: "/video/citynorth_20100311.f4v",
   		autostart: 'true',
   		repeat: 'single',
   		stretching: 'fill',
   		controlbar: 'none',
   		smoothing: 'false'
		};

      if (urlpath.indexOf('aboutus')!= -1) {
         flashvars.file = '/video/uofa2_20100311.f4v';
         $('span.nowviewing').text('University of Arizona');
      } else if (urlpath.indexOf('landscapemanagement')!= -1 || urlpath.indexOf('landscapeenhancement')!= -1) {
         flashvars.file = '/video/laencantada_20100311.f4v';
         $('span.nowviewing').text('La Encantada');
      } else if (urlpath.indexOf('construction')!= -1) {
         flashvars.file = '/video/citynorth_20100311.f4v';
         $('span.nowviewing').text('CityNorth');
      } else if (urlpath.indexOf('sustainability')!= -1 || urlpath.indexOf('employeeculture')!= -1 || urlpath.indexOf('contactus')!= -1) {
         flashvars.file = '/video/uofa_20100311.f4v';
         $('span.nowviewing').text('University of Arizona');
      } //if

		flashwidth = $(window).width();
		flashheight = $(window).height();

		var attributes = {};
		attributes.id = "flashbg";
		attributes.name = "flashbg";
		
		var params = {};
		params.allowscriptaccess = "always";
		params.wmode = "transparent";

		swfobject.embedSWF("/video/player.swf", "flashcontainer", flashwidth, flashheight, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
   
}; //initializevideo

player = null;

function videocontrols() {
   setTimeout( function () {
   player = document.getElementById('flashbg');

   $('.soundoff').click(function() {
if (player!=null) {
      player.sendEvent("VOLUME", 0);
}; //if
   }); //click soundoff
   $('.soundon').click(function() {
if (player!=null) {
      player.sendEvent("VOLUME",100);
}; //if
   }); //click soundoff
   
   
   $('.playpause').toggle(function(){
if (player!=null) {
      player.sendEvent("PLAY","false");
      $(this).text('play');
}; //if
   }, function() {
if (player!=null) {
      player.sendEvent("PLAY","true");
      $(this).text('pause');   
}; //if
   });


   $('.viewvideoonly').toggle(function(){
      $('#grass').hide();
      $('#sod').hide();
      $('#trees').hide();
   }, function() {
      $('#grass').show();
      $('#sod').show();
      $('#trees').show();
   });
}, 1000);
}; //videocontrols






function newbackground() {
$('#flashbg').remove();
$('#flashcontainer').remove();
$('body').css({'backgroundColor': '#00703c'});
}; //












function projectlist(){
$('ul.projectlist').children('li').hover(function(){
$('.projecthover').remove();
$('body').append('<span class="projecthover">'+$(this).children('a').text()+'</span>');
$('.projecthover').css({'position': 'absolute', 'left': $(this).offset().left, 'top': $(this).offset().top-15, 'zIndex': '20'});
}, function() {
$('.projecthover').remove();
}); //hover
}; //projectlist
