var languages_visible = false;
var checkResize = 0;
var slider = '';

$(document).ready(function() {
	/* toggle language options display */
	$('#language-select a.select').click(function() {
			var $link = $(this);
			var $options = $(this).next('.options');
			$options.slideToggle('normal', function(){
					if($link.hasClass('showing')) {
						$link.removeClass('showing');
						languages_visible = false;
					}
					else {
						$link.addClass('showing');
						languages_visible = true;
					}
				});
			
		});
		
	// remove the language overlay when present and
	// visitor clicks on the screen
	$(document.body).click(function() {
		if(languages_visible === true) {
			$('#language-select .options').slideUp('fast', function() {
				$('#language-select a.select').removeClass('showing');
				languages_visible = false;
			});
		}
	});
	
	/* sub menu visual effects */
	$('#nav li li').hover(
		function() {
		/* on mouse in */
			/* if the hovered item has children then add an active class to the parent li */
			$(this).parent('ul').parent('li').addClass('forceActive');
		},
		function() {
		/* on mouse out */
			/* remove the parent class from the parent li */
			$('#nav li').removeClass('forceActive');
		}
	);
	
	/* add .hover class to top menu item - required for IE6 */
	$('#nav li').hover(
		function() {
			$(this).addClass('hover');
		},
		function () {
			$(this).removeClass('hover');
		}
	);
	
	if($('#banner-holder').length > 0) {
		var showpager = true;
		
		// if there is one or less images then hide the pager
		if($('#banner').children().length <= 1) {
			showpager = false;	
		}
		
		// main image banner
		slider = $('#banner').bxSlider({
				'mode': 'fade',
				'controls': false,
				'auto': true,
				'pause': 7000,
				'speed': 750,
				'pager': showpager,
				'pagerSelector': '#bx-pager',
				'pagerActiveClass': 'active'
			});
	}
	
	/* evoluted logo effect */
	$("#evoluted").hover(function() {
		var bg = $(this).find("img").attr("src");
		// set a background image(bg) on the <a> tag - set position to bottom
		$(this).css({'background' : 'url(' + bg + ') no-repeat center bottom'});
		// fade the image to 0 opacity
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide();
		});
	} , function() {
		// fade the image to full opacity 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});
	
	// function applies to all input items with class 'replace'
	// the default value for each input item with a class of
	// 'replace' will be removed onfocus and then reapplied
	// onblur if no input has been made
	$(':input.replace').each(function() {
		$(this)
			.data('label', $(this).val())
			.focus(function() {
				if ($(this).val() == $(this).data('label')) {
					$(this).removeClass('replace').val('');
				}
			})
			.blur(function() {
				if (!$(this).val()) {
					$(this).addClass('replace').val($(this).data('label'));
				}
			});
	});
	
	/* contact page map */
	if($('#global-map').length > 0) {
		$('.pointers div').hover(function() {
			var country = '.' + $(this).attr('class');
			var $active = $('#global-map .overviews').find(country);
			$.data(document.body, 'activeOverview', $active);
			// animate active overview
			$(this).animate({ opacity: 1 });
			$active.stop().animate({
				'left': '0'
			}, 300);
		},
		function() {
			$(this).animate({ opacity: 0.75 });
			// remove active overview
			var $active = $.data(document.body, 'activeOverview');
			$active.stop().animate({
				'left': '-255px'
			}, 300);
		});
	}
	
	/* contact page email addresses */
	if($('.emailuk').length > 0) {
		$('.emailuk').html('<a href="mailto:uk@stemcorspecialsteels.com">uk@stemcorspecialsteels.com</a>');
	}
	if($('.emailsingapore').length > 0) {
		$('.emailsingapore').html('<a href="mailto:singapore@stemcorspecialsteels.com">singapore@stemcorspecialsteels.com</a>');
	}
	if($('.emaildubai').length > 0) {
		$('.emaildubai').html('<a href="mailto:dubai@stemcorspecialsteels.com">dubai@stemcorspecialsteels.com</a>');
	}
	if($('.emailusa').length > 0) {
		$('.emailusa').html('<a href="mailto:us@stemcorspecialsteels.com">us@stemcorspecialsteels.com</a>');
	}
	if($('.emailbrazil').length > 0) {
		$('.emailbrazil').html('<a href="mailto:fernando.torres@stemcorspecialsteels.com">fernando.torres@stemcorspecialsteels.com</a>');
	}


});

