﻿function tabSelected(event, ui)
{
    $(".tabset li").removeClass("after");
    $(".tabset li").removeClass("before");
    if(event.type == "tabscreate") {
        $(".tabset li.ui-state-active").next("li").addClass("after");
        $(".tabset li.ui-state-active").prev("li").addClass("before");
        $(".tabset").find("li:first").addClass("first");
        $(".tabset").find("li:last").addClass("last");
    } else {
        $(ui.tab).parent().next("li").addClass("after");
        $(ui.tab).parent().prev("li").addClass("before");
    }
}

// remap jQuery to $
(function ($) { })(window.jQuery);

/* //////////////////////////////////////////////
// Autosize select box
// usage: $(“select#selectBoxId”).autoWidthOnFocus();
////////////////////////////////////////////// */
(function ($) {
	$.fn.autoWidthOnFocus = function () {
		return this.each(function() {
			var box = $(this);
			var hasFocus = false;
			var initialWidth = box.outerWidth();
			box.css({ width: "auto" });
			var actualWidth = box.outerWidth();
			if (initialWidth > actualWidth) {
				initialWidth = actualWidth;
			}

			box.focus(function () {
				box.css({ width: "auto" });
				hasFocus = true;
			});
			box.blur(function () {
				box.css({ width: initialWidth });
				hasFocus = false;
			});
			box.mouseover(function () {
				box.css({ width: "auto" });
			});
			box.mouseout(function () {
				if (!hasFocus) {
					box.css({ width: initialWidth });
				}
			});
			box.change(function () { box.blur(); });
			box.blur();
		});
	};
})(jQuery);

$(".ie7 select, .ie8 select").autoWidthOnFocus();

/* trigger when page is ready */
$(document).ready(function () {
    $(".tabs, .blue-tabs").tabs({
        select: tabSelected,
        create: tabSelected
    });
    
    
/*******************************************************************************
=== COLOR BOX ============================================================
* The colorbox popup, uses the jquery.colorbox.js library
*******************************************************************************/     
$('a.colorbox').click(function() {
	$('a.colorbox').colorbox();
});    
$(".colorbox-modal").colorbox({ iframe: true, innerWidth:750, innerHeight:700});
$("#everify-modal").colorbox({ iframe: true, innerWidth:530, innerHeight:330});
$(".colorbox-video").colorbox({ iframe: true, innerWidth:460, innerHeight:380});
	  // history time line in about us
$(".timeline").colorbox({ innerWidth:920, innerHeight:660, scrolling:false, iframe:true});

$('a.video').click(function(){
	var href = $(this).attr('href');
	window.open(href, 'secure','width=440,height=350,scrollbars=no,location=no,dependent=yes,resizable=no,top=100,left=100');return false;
});

$(".close-btn").live("click", function(e) {
	$.colorbox.close();
});
	
/*******************************************************************************
=== INCREASE/DECREASE TEXT======================================================
	* INCREASE/DECREASE TEXT 
*******************************************************************************/
	
// Read the cookie. Depending on what it is, apply the inline style to the body tag, and the selected class to the link that indicates the size.
	var size = $.cookie('fontSize');
	if (size == 'small') {
	$('#main-content,footer').css('font-size','');
		$('#text-size a').removeClass('selected');
		$('#text-size #small').addClass('selected');
	};
	if (size == 'medium') {
	$('#main-content,footer').css('font-size','140%');
		$('#text-size a').removeClass('selected');
		$('#text-size #medium').addClass('selected');
	};
	if (size == 'large') {
	$('#main-content,footer').css('font-size','160%');
		$('#text-size a').removeClass('selected');
		$('#text-size #large').addClass('selected');
	};
	
// To increase and decrease the text-size, adding inline styles to the #main-content,footer tag.
	$('#text-size a').click(function(event) {
									 
// This nullifies the font-size value by default.
	$('#main-content,footer').css('font-size', '');
	$.cookie('fontSize', 'small', { expires: 365, path: '/'});
	
// This is the "smaller" font-size link.
    if (this.id == 'medium') {
      $('#main-content,footer').css('font-size', '140%');
	  $.cookie('fontSize', 'medium', { expires: 365, path: '/'});
    }
	
// This is the "larger" font-size link.
    else if (this.id == 'large') {
      $('#main-content,footer').css('font-size', '160%');
	  $.cookie('fontSize', 'large', { expires: 365, path: '/'});
    }
	
// Add the selected class to the link, if the user has selected it.
    $('#text-size a').removeClass('selected');
    $(this).addClass('selected');
	event.stopPropagation();
	});  

// Add pdf icon to pdf link
	$('a[href$=".pdf"]').attr("target","blank").after(' <img src="/careers/global/assets/images/pdf-ico.gif" class="pdf-icon" title="This is a PDF document" />');

   
/*******************************************************************************
=== PRINT THIS PAGE ============================================================
	* Initiates a regular browser print job when user clicks.
*******************************************************************************/
  $('#print-page a').click(function() {
	window.print(); return false;
  });

/*******************************************************************************
=== SHARE THIS PAGE AND EMAIL THIS PAGE ============================================================
	* Opens the Share This dialouge
*******************************************************************************/
  $('#share-this-link').click(function(){
		$('#tools div').removeClass("open");
		$('#share-this-box').toggleClass("open");
		
		
			var s=s_gi('amppublic,ampglobal'); 
			s.linkTrackVars='eVar21,events,prop17'; 
			s.linkTrackEvents='event17'; 
			s.eVar21='st_sharethis'; 
			s.events='event17'; 
			s.prop17 = s_om.pageName;
			s.tl(this,'o','st_sharethis');
			
			
		return false;
  });		

  $('#email-this-link').click(function(){
		$('#tools div').removeClass("open");
		$('#email-this-box').toggleClass("open");
		
		
		 var s=s_gi('amppublic,ampglobal'); 
		 s.linkTrackVars='eVar21,events,prop17'; 
		 s.linkTrackEvents='event17'; 
		 s.eVar21='amp_email_this_page_click'; 
		 s.events='event17'; 
  	 s.prop17 = s_om.pageName;
		 s.tl(this,'o','amp_email_this_page_click');
		
		return false;
  });		

  // Close the tools boxex if link with this class is clicked
  $('.tools-close').click(function(){
		$('#tools div').removeClass("open");
		return false;
  });	
  
  // Trigger bgiframe so these boxes show over forms and flash
	
	
	
	if($('#share-this-box').bgiframe != null) {
		$('#share-this-box').bgiframe();
	}
	
	if($('#email-this-box').bgiframe != null) {
		$('#email-this-box').bgiframe();
	}

	searchText();

});

function searchText() {
	var searchBox = $(".search-input");
	searchBox.val("Enter keyword");
	searchBox.focus(function() {
			if(searchBox.val() == "Enter keyword") {
				searchBox.val("");
			}
		});
	searchBox.blur(function() {
		if(searchBox.val() == "") {
			searchBox.val("Enter keyword");
			}
		});
}
    
/*******************************************************************************
=== Sharing ============================================================
* The colorbox popup, uses the jquery.colorbox.js library
*******************************************************************************/     
function openFacebook() {
	//trackClick("st_facebook"); 
	var url = getUrl();
	url = addQuery(url, "cid", "st_facebook");
	window.open("http://www.facebook.com/share.php?u="+url)
}

function openTwitter() {
	//trackClick("st_twitter"); 
 
	var url = getUrl();
	var title = document.title;

	//store in a cookie to pass so html characters dont get injected
	$.cookie('twittertitle', title, { expires: 1, path: '/'});

	url = addQuery(url, "cid", "st_twitter"); 
	 
	window.open("/global/sitelets/sharethis/twitter.asp?url="+url); 
}

function openLinkedIn() {
	
	//trackClick("st_linkedin"); 
 
	var url = getUrl();
	var title = document.title; 
	
	url = addQuery(url, "cid", "st_linkedin"); 
	 
	window.open("http://www.linkedin.com/shareArticle?mini=true&url="+url+"&title="+title); 
}

/***** Navigation by Dropdown *****/
function validateDropdown(url, value, errorMessage) {
    if(value == "") {
        alert(errorMessage);
    } else {
        window.location.href = url;
    }
	return false;
}
