function getMediaContact(countryNumber) {
	$.get( 'tem/mediacontacts.php', { country: countryNumber }, function(data) {
		$('.mediaLocations').html(data);
	});
}

var quoteTimer;
var newsTimer;
var quoteDelay = 3000;
var newsDelay = 1000;
var triggerUp = false;
var triggerDown = false;

/* Detect IE6 definitively */
if ( document.all && !window.opera ) {
	var isIE6 = true;
}
else { 
	var isIE6 = false;
}

$.browser.msie6 = isIE6; 
/* END Detect IE6 */

function rotateQuotes(){
	clearTimeout(quoteTimer);
	
	var current = $('#subtag span.current');
	var next = $(current).next().length ? $(current).next() : $('#subtag span:first');
	
	$(current).fadeOut('slow', function(){
		$(this).removeClass('current').addClass('next');
		$(next).fadeIn('slow').removeClass('next').addClass('current');
		
		quoteTimer = setTimeout("rotateQuotes()", quoteDelay);
	});
}

function rotateNews(){
	$('#newsScroller').trigger('scrollNext');
}

$(document).ready( function(){
	$("a[href$='.pdf'], a[href$='.doc'], a[href$='.xls'], a[href$='.mp3'], a[href^='http://'], a[href^='https://']").attr('target', '_blank');

	$('li').each( function(){
		$(this).html( '<span class="black">' + $(this).html() + '</span>' );
	});

	$('span.black ul li').each( function(){
		$(this).html( '<span class="black">' + $(this).html() + '</span>' );	
		
		if ( $(this).find('ul').length ) {
			$(this).find('ul li').each( function(){
				$(this).html( '<span class="black">' + $(this).html() + '</span>' );				
			});
		}
	});

	$('#email .emailButton').click( function(evt){
		evt.preventDefault();
		
		var emailValue = $('#email .emailField').val();
		
		if ( emailValue != '' ) {
			$.post('subscribe.php', { email: emailValue }, function(data){
				//$('#email .emailField').css('display', 'none').val(data);
				//$('#email .emailField').fadeIn('fast');
				window.location='index.php?p=ContactForm';
			});
		}
	});
	
	$('.searchField').click( function(){
		if ( $(this).val() == $(this).attr('rel') ) {
			$(this).val('');
			$(this).css('font-style','normal');
		}
		else if ( $(this).val() == '' ) {
			$(this).val( $(this).attr('rel') );
			$(this).css('font-style','italic');
		}
	}).blur( function(){
		if ( $(this).val() == $(this).attr('rel') ) {
			$(this).val('');
			$(this).css('font-style','normal');
		}
		else if ( $(this).val() == '' ) {
			$(this).val( $(this).attr('rel') );
			$(this).css('font-style','italic');
		}
	});
	
	$('.expandable').click( function(){
		$('.expandable').animate( { marginBottom: '3px' }, 200, function(){
			$('.subMenuExpand').slideUp('fast');
		});
		
		var drop = $(this).next('.subMenuExpand');
		
		if ( $(drop).css('display') == 'none' ) {		
			$(this).find('img').attr('src', 'pictures/subMenuMinus.jpg');
			$(this).animate( { marginBottom: '0px' }, 200, function(){
				$(drop).slideDown('fast');
			});
		}
		else {
			$(this).find('img').attr('src', 'pictures/subMenuPlus.jpg');				
		}
		
		return false;
	});
	
	$('.subMenuExpand a').hover( function(){
		$(this).css('backgroundColor', '#232020');
	}, function(){
		$(this).css('backgroundColor', '#a1a1a2');
	});
	
	$('.subScrollUp').mouseover( function(){
		if ( !triggerUp ) {
			triggerUp = true;		
			$(this).trigger('subscroll');
		}
	}).mouseout(function(){
		triggerUp = false;
	});

	$('.subScrollDown').mouseover( function(){
		if ( !triggerDown ) {
			triggerDown = true;
			$(this).trigger('subscroll');
		}
	}).mouseout(function(){
		triggerDown = false;
	});
	
	var hiding = 1;
	
	$('.subMenuScroller a').each( function(){
		if ( hiding < 7 ) {
			$(this).addClass('visible');
		}
		
		hiding = hiding + 1;
	});
	
	$('.subScrollUp').bind('subscroll', function(){
		var trueThis = $(this);
		var scrollBox = $(this).next('.subMenuScroll').find('.subMenuScroller');
		var first = $(scrollBox).find('a.visible:first').prev('a');
		var last = $(scrollBox).find('a.visible:last');		
		
		if ( first.length ) {
			$(scrollBox).animate( { marginTop: parseFloat( $(scrollBox).css('marginTop') ) + 33 + 'px' }, 400, function(){
				$(first).addClass('visible');
				$(last).removeClass('visible');
				
				if ( triggerUp ) {
					$(trueThis).trigger('subscroll');
				}
			});
		}
	});
	
	$('.subScrollDown').bind('subscroll', function(){
		var trueThis = $(this);	
		var scrollBox = $(this).prev('.subMenuScroll').find('.subMenuScroller');
		var first = $(scrollBox).find('a.visible:first');
		var last = $(scrollBox).find('a.visible:last').next('a');	

		if ( last.length ) {
			$(scrollBox).animate( { marginTop: parseFloat( $(scrollBox).css('marginTop') ) - 33 + 'px' }, 400, function(){
				$(last).addClass('visible');
				$(first).removeClass('visible');
				
				if ( triggerDown ) {
					$(trueThis).trigger('subscroll');
				}
			});
		}
	});
	
	$('#pulldown').mouseover( function(){
		$(this).find('.pullTop').css('background', 'url(images/pulldownBkgON.jpg) no-repeat').css('color', '#000');
		$(this).find('.pullDrop').css('display', 'block');
	}).mouseout( function(){
		$(this).find('.pullTop').css('background', 'url(images/pulldownBkg.jpg) no-repeat').css('color', '#C7002B');
		$(this).find('.pullDrop').css('display', 'none');
	}).find('a').mouseout( function(evt){
		evt.preventDefault();
	});
	
	$('#helpBubble').click( function(){
		if ( $('#helpBox').css('display') == 'none' ) {
			$(this).find('.helpPlus').attr('src', 'pictures/helpMinus.GIF');
			$('#helpBox').fadeIn('fast');
		}
		else {
			$(this).find('.helpPlus').attr('src', 'pictures/helpPlus.GIF');		
			$('#helpBox').fadeOut('fast');			
		}
	});
	
	$('#helpBox h2').hover( function(){
		$(this).css('cursor', 'pointer');
	}).click( function(e){
		if (!e) var e = window.event;
    	e.cancelBubble = true;
    	if (e.stopPropagation) e.stopPropagation();

		var question = $(this).next('div');
		
		$('#helpBox div.activeDiv').slideUp('fast').removeClass('activeDiv');
		$('#helpBox h2.activeQ').removeClass('activeQ');		
		
		if ( $(question).css('display') == 'none' ) {
			$(this).addClass('activeQ');
			$(question).addClass('activeDiv').slideDown('fast');
		}
	});
	
	/* News scroll on main page only */	
	if ( $('#newsScroller').length ) {
		$('#newsScroller').bind( 'scrollNext', function(){
			clearTimeout(newsTimer);
			
			$(this).animate( { top: ( parseFloat( $(this).css('top') ) - 20 ) + 'px' }, 500, function(){
				$(this).find('a:first').remove().appendTo( $(this) );
				$(this).css('top', '0px');
				
				newsTimer = setTimeout("rotateNews()", newsDelay);
			});
		});
		
		newsTimer = setTimeout("rotateNews()", newsDelay);
		
		$('#newsScroller').mouseover( function(){
			$(this).stop();
			clearTimeout(newsTimer);
		}).mouseout( function(){
			newsTimer = setTimeout("rotateNews()", newsDelay);		
		});
		
		$('#newsScroller a').mouseover( function(evt){
			evt.preventDefault();
		}).mouseout( function(evt){
			evt.preventDefault();
		});
	}
	
	/* Industries balls rotation */
	if ( $('#industryGraphic img.industryItem').length ) {
		$('#industryGraphic img.industryItem').mouseover( function(){
			$(this).attr( 'src', $(this).attr('src').replace('1.jpg', '2.jpg') );
			
			var thisId = $(this).attr('id');
			$('#industryText').html( industryContent[thisId] ); // this array is in the Industries tem file
		}).mouseout( function(){
			$(this).attr( 'src', $(this).attr('src').replace('2.jpg', '1.jpg') );
		});
	}
	
	quoteTimer = setTimeout("rotateQuotes()", quoteDelay);
});




		
