var imagePos;

jQuery(document).ready( function()
{
	if ( parseUri(window.location).directoryPath.split("/")[1] == 'intranet' )
	{
		jQuery('.LanguageSwitchWrapper').hide();
		jQuery('.Header').prepend('<div class="MainSectionSubHeading"><a href="/intranet/"><img src="/themes/te/images/im_IntranetBadge.png" /></a></div>');
		jQuery('body').addClass('blue');
	}
	else if ( parseUri(window.location).directoryPath.split("/")[1] == 'community' )
	{
		jQuery('.LanguageSwitchWrapper').hide();
		jQuery('.Header').prepend('<div class="MainSectionSubHeading"><a href="/community/"><img src="/themes/te/images/im_CommunityBadge.png" /></a></div>');
		jQuery('body').addClass('red');
	}
	else if ( parseUri(window.location).directoryPath.split("/")[1] == 'recruitment' )
	{
		jQuery('.LanguageSwitchWrapper').hide();
		jQuery('.Header').prepend('<div class="MainSectionSubHeading"><a href="/recruitment/"><img src="/themes/te/images/im_RecruitmentBadge.png" /></a></div>');
		jQuery('body').addClass('green');
	}
	else if ( parseUri(window.location).directoryPath.split("/")[1] == 'internship' )
	{
		jQuery('.LanguageSwitchWrapper').hide();
		jQuery('.Header').prepend('<div class="MainSectionSubHeading"><a href="/internship/"><img src="/themes/te/images/im_InternshipBadge.png" /></a></div>');
	}
	else if ( parseUri(window.location).directoryPath.split("/")[1] == 'clientes' )
	{
		jQuery('body').addClass('clientes');
	}

	if ( parseUri(window.location).directoryPath.split("/")[1] == 'intranet' || parseUri(window.location).directoryPath.split("/")[1] == 'es' )
	{
		jQuery('#AllSitesBtn').attr('href', '/es/intranets').text('Otras Webs');
	}
	else
	{
		jQuery('#AllSitesBtn').attr('href', '/en/intranets').text('Other Sites');
	}
	
	// Add the header image slider
	if (jQuery('#slider').length > 0)
	{
		jQuery('#slider').nivoSlider({
			effect:'fade',
			slices: 10,
			captionOpacity: 1,
			pauseTime:5000
		});
	}

	// Wrap the isus coommercial video into a fancy box
	if (jQuery('#isus_video').length > 0)
	{	
		jQuery("#isus_video").fancybox({
			'padding'			: 10,
			'autoScale'			: false,
			'centerOnScroll'	: true,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'width'				: 751,
			'height'			: 423,
			'overlayColor'		: '#000',
			'overlayOpacity'	: '0.8'
		});
	}
	
	// Add class to all anchors to hide the automatic &nbsp;
	jQuery('a[name]').addClass('AnchorLinks');
} );

/* parseUri JS v0.1, by Steven Levithan (http://badassery.blogspot.com)
Splits any well-formed URI into the following parts (all are optional):
----------------------
- source (since the exec() method returns backreference 0 [i.e., the entire match] as key 0, we might as well use it)
- protocol (scheme)
- authority (includes both the domain and port)
    - domain (part of the authority; can be an IP address)
    - port (part of the authority)
- path (includes both the directory path and filename)
    - directoryPath (part of the path; supports directories with periods, and without a trailing backslash)
    - fileName (part of the path)
- query (does not include the leading question mark)
- anchor (fragment)
*/
function parseUri(sourceUri)
{
	var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];
	var uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri);
	var uri = {};

	for(var i = 0; i < 10; i++){
		uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
	}

	// Always end directoryPath with a trailing backslash if a path was present in the source URI
	// Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key
	if(uri.directoryPath.length > 0){
		uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
	}

	return uri;
}
