﻿$(document).ready(function() {

//   var mainHeight = $('.ms-bodyareaframe').height();
//   alert ('mainHeight: ' + mainHeight);

 $('.ms-bodyareaframe').corner("bottom 20px");
 $('.TopNavBackGround').corner("tl 20px");
 $('.ms-topnav:first').corner("tl 20px");
 $('.searchBackground').corner("tr 20px");
 $('#app').corner("tl 20px");
 $('#Xguide').corner("tr 20px");

// keep logo at bottom
//$(window).scroll(function (){
//     $('#logo').stop().animate({bottom: 20}, 'slow'); }); 

//fancybox for Health and Wealth
	if ($('[id^=fancyBox]').length > 0 ) {
		$('#fancyBoxHome').fancybox({
			'width'				: 915,
			'height'			: 315,
			'autoDimensions'	: true,
        	'autoScale'     	: true,
        	'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe',
			'hideOnContentClick': true,
			'showCloseButton'	: true,
			'scrolling'			: 'no',
			'padding'			: 0,
			'margin'			: 0
		});
		
		$('#fancyBoxNewHire').fancybox({
			'width'				: 670,
			'height'			: 550,
			'autoDimensions'	: true,
        	'autoScale'     	: true,
        	'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe',
			'hideOnContentClick': true,
			'showCloseButton'	: true,
			'scrolling'			: 'no',
			'padding'			: 0,
			'margin'			: 0
		});

	
		$('#fancyBoxHealth').fancybox({
			'width'				: 485,
			'height'			: 388,
			'autoDimensions'	: true,
        	'autoScale'     	: true,
        	'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe',
			'hideOnContentClick': true,
			'showCloseButton'	: true,
			'scrolling'			: 'no',
			'padding'			: 0,
			'margin'			: 0
		});
	}


// section for slide show //
//if ($('#slideshowHolder').length > 0){
    // do something here

//  $('#slideshowHolder').jqFancyTransitions({ width: 460, height: 273, 
 //       links:true, navigation:true, position: 'top', direction: 'left' });
 //        links:true, navigation:true, position: 'curtain', direction: 'left', 
 //       strips:1,stripDelay:1 });
 //   $('#positionDyn').html('left');
//	$('#directionDyn').html('top');
//
//}        

//section for whatif/guides/etc //

    if($('#apps').length > 0) {
 
 //initializes state of section
      $('#whatifs').hide();
      $('#guides').hide(); 
      $('#apps').show();

      $('#app').addClass('TWGselected');
     };
  
  $('#whatif').click(function() {
    $('#whatifs').show();
    $('#guides').hide();
    $('#apps').hide();
    
    $('#app, #guide').removeClass('TWGselected').addClass('TWG');
    $('#whatif').addClass('TWGselected');
   });

  $('#guide').click(function() {
    $('#whatifs').hide();
    $('#guides').show();
    $('#apps').hide();

    $('#app, #whatif').removeClass('TWGselected').addClass('TWG');
    $('#guide').addClass('TWGselected');
    });

  $('#app').click(function() {
    $('#whatifs').hide();
    $('#guides').hide();
    $('#apps').show();
    
    $('#whatif, #guide').removeClass('TWGselected').addClass('TWG');
    $('#app').addClass('TWGselected');
    });


// section for autoexpanding/groupby
  $('.container').hide();
  
 $('.triggerHeader').click(function(){
   var QclassAll = $(this).parent().attr('class');
   var Qclassfirst = QclassAll.substring(0,QclassAll.indexOf(' '));
   var Aclass = Qclassfirst.replace('Q','A');
   var Dclass = Qclassfirst.replace('Q','D');

   $('.'+Aclass).toggle();
 
   var imgtest = $(this).children(':first-child').attr('src');
 
   if (imgtest.indexOf('close') > 0) {
     newimg = imgtest.replace('close','open');
     $('.'+Dclass).hide();
     $('.'+Aclass).find('img').attr('src',newimg);
    } 

   if (imgtest.indexOf('open') > 0) {
     newimg = imgtest.replace('open','close');
    }
     
 $(this).children(':first-child').attr('src', newimg);
 
 });
 
  $('.triggerDetail').click(function(){
   var QclassAll = $(this).parent().attr('class');
   var Qclassfirst = QclassAll.substring(0,2)+QclassAll.substring(QclassAll.indexOf(' ')+1,QclassAll.indexOf('container')-1);
   var Aclass = Qclassfirst.replace('A','D');

   $('.'+Aclass).toggle();
 
   var imgtest = $(this).children(':first-child').attr('src');
 
   if (imgtest.indexOf('close') > 0) {
     newimg = imgtest.replace('close','open');
    } 

   if (imgtest.indexOf('open') > 0) {
     newimg = imgtest.replace('open','close');
    }
     
 $(this).children(':first-child').attr('src', newimg);
 
 });

 
//all external reference links add target blank
 $('a[href^="http"]').not('.recentPages, .noPop, [id*="Welcome"]').attr("target","_blank");
 $('a[href$="pdf"]').attr("target","_blank");

//change last app box to border = 0
 if ($('#apps').find('.TWGDetail').length > 0) {
  $('#apps').find('.TWGDetail:last').css('border-bottom','0');
  $('#whatifs').find('.TWGDetail:last').css('border-bottom','0');
  $('#guides').find('.TWGDetail:last').css('border-bottom','0');
  }; 


// Legal Notice
    
	Offset = 100;   
	var legalContainer = $('#legal_notice')
	legalContainer.css({height: legalContainer.outerHeight() - 30});

	legalContainer.css({bottom: Offset});
	
	$('#legal_notice').slideUp().delay(1000).animate({right: 200}); // show the notice 200 is the position	
	$('.legal').click(function() {
		$('#legal_notice').slideDown(500);
     	$('.ms-bodyareaframe').addClass('transparent');
		});

	$('#legal_notice .close').click(function() {
		$('#legal_notice').slideUp(500);
		$('.ms-bodyareaframe').removeClass('transparent');
		});


// custom search input box
   $('#search_notice').slideUp().delay(100).animate({right: 400});
	
   $('#belongSearchString').blur(function(){

    var searchURL = "/Content/CustomSearch.aspx?k="
    var siteURL = $().SPServices.SPGetCurrentSite();  
    var tempSearch = $('#belongSearchString').val();

    var searchQuery = searchURL +encodeURIComponent(tempSearch)+"&u="+encodeURIComponent(siteURL);
	
	document.body.style.cursor = "wait";
	$('#search_notice').slideDown(100);
   	$('.ms-bodyareaframe').addClass('transparent');
	
   window.location.href=searchQuery;
   
   });   
   
  
// formatting search string text box when clicking into it 
   $('#belongSearchString').click(function(){
     $('#belongSearchString').val("");
     $('#belongSearchString').css('font-style','normal');
   });
  
// selected email send
  $('#selectEmail').change(function() {
    window.location = $('#selectEmail').val();  
  });


  // End of $(document).ready()      
 });
   
   
