$(init_page);

function init_page(){
  BrowserDetect.init();

  init_main_menu();   
  //$('#main_menu').superfish();
  
  footer_resizer();
  setTimeout(
    function(){
      footer_resizer();
      
      var _height;
      var _body_height;
      _body_height = $('body').height();
      if($('body').hasClass('home')){
        _height = $('#wrap').height()+ 178;
      }else{    
        _height = $('#wrap').height()+ 160;
      }
      if(_body_height>_height) _height = _body_height;
      $('#flash_box').height(_height);    
      
    }, 1000);

   

  
  $('#locations li a').hover(function(){
    $('#locations li a').removeClass('selected');
    $(this).addClass('selected');  
  });
  //init_sifr();
  replace_headers();

  if(typeof $('#thumbs_4col a').lightBox == 'function') {
    $(function() {
	    $('#thumbs_4col a').lightBox({fixedNavigation:true});
  	  $('a.connex_movie').lightBox({fixedNavigation:true});
    });  
  } 

  if(location.hash == '#connex_presentation'){
    $('a.connex_movie').trigger('click');
  }

  
  if(!has_flash()){
    // reveal the content
    js_reveal();
    // reveal the menu
    $('#main_menu_container').css('top','-101px');
    $('#main_menu>li').css({'display':'block','height':'auto'});
    $('#main_menu>li>a').css({'display':'block','height':'101px'});
    $('#main_menu li ul').css({'display':'','top':'101px'});    
    
  }else{
 
  }

}



function has_flash(){
  
  return FlashDetect.installed;
}

$(document).ready(function(){
  //replace_headers();
  //replace_main_menu_items(); 
  
});

function replace_headers(){

    $('h2').each(function(idx){
      if( $(this).hasClass('news_title')) return;
      
      var text = $(this).html().toUpperCase();
      var width =  $(this).width() ;
      if(width==0) width = 600;
      img_src = www_root + 'template/geodynamics/font.php?text=' + text + '&size=' + 20 + '&width=' + width ; 
      $(this).replaceWith('<h2><img src="' +  img_src  + '" alt="'+ text +'" class="h2" alt="'+ text +'" /></h2>');
    })
    
    $('h3').each(function(idx){
      var text = $(this).html().toUpperCase();
      var width =  $(this).width() ;
      if(width==0) width = 400;
      img_src = www_root + 'template/geodynamics/font_grad.php?text=' + text + '&size=' + 31  ; 
      $(this).replaceWith('<h3><img src="' +  img_src  + '" alt="'+ text +'" class="h2" alt="'+ text +'" style="margin-left: 2px;" /></h3>');
    })

    $('.contact_info').each(function(idx){
      var text = $(this).html().toUpperCase();
      var width =  $(this).width() ;
      if(width==0) width = 400;
      img_src = www_root + 'template/geodynamics/font_teamdir_item.php?text=' + text; 
      $(this).replaceWith('<span class="contact_info" ><img src="' +  img_src  + '" alt="'+ text +'" alt="'+ text +'" style="margin-left: 2px;" /></span>');
    })

    $('.big_text').each(function(idx){

      var text = $(this).html();
      var width =  $(this).width() ;
      if(width==0) width = 600;
      img_src = www_root + 'template/geodynamics/font_big_text.php?text=' + text + '&size=' + 30 + '&width=' + width ; 
      $(this).replaceWith('<p class="big_text"><img src="' +  img_src  + '" alt="'+ text +'" class="big_text" alt="'+ text +'" /></p>');
    })
}

function footer_resizer(){
  if($('body').hasClass('home')){
    $('#flash_box').css('background','none');  
    //resize_footer();
		$(window).resize(resize_flash_box);

   
  }else{
    $('#footer').height( $(window).height() - 588);
    $(window).resize(resize_footer);
    $('#flash_box').height($('#wrap').height() + 120); 
    resize_footer();
    
  }  
  
  
}

function resize_footer(){
    var h = $(window).height() - 588;
    if(h < 130) h = 130
    $('#footer').height( h );
    resize_flash_box();
}

function resize_flash_box(){
      var _height;
      var _body_height;
      _body_height = $('body').height();
      if($('body').hasClass('home')){
        _height = $('#wrap').height()+ 178;
      }else{    
        _height = $('#wrap').height()+ 160;
      }
      if(_body_height>_height) _height = _body_height;
      $('#flash_box').height(_height);       
}

function get_flash( swfID ){
   BrowserDetect.init();

//  alert(navigator.appName);
     if(navigator.appName.indexOf("Microsoft") != -1|| BrowserDetect.browser =='Safari' || BrowserDetect.browser == 'Chrome' ){
          

          return window[swfID];
          
     }else{
          return document[swfID + '_obj'];
     }
}


function js_reveal(param){
  $('#wrap').fadeIn();

}

        


function is_valid_email(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   return true;
}



/* Browser Detection Class */
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]
};

