// ----- Search -----

$().ready(function() {

  if ($('#query').val() == '') blurSearch();
  $('#query').bind('focus', focusSearch);
  $('#query').bind('blur', blurSearch);

});

function focusSearch() {
  if ($('#query').val() == $('#query').attr('alt')) {
    $('#query').val('');
    $('#query').removeClass('blur').addClass('focus');
  }
}

function blurSearch() {
  if ($('#query').val() == '') {
    $('#query').val($('#query').attr('alt'));
    $('#query').removeClass('focus').addClass('blur');
  }
}


// ----- Animations -----

$(window).bind("load", function() {

  $('#slide1').fadeIn(1000);
  
  $('#slide1b').delay(500).fadeIn(1000);

  $('#slide1').delay(3000).fadeOut(1000);
  $('#slide1b').delay(3000).fadeOut(1000);
  
  $('#slide2').delay(3000).fadeIn(1000);
  $('#slide2b').delay(3500).fadeIn(1000);

  $('#homebar').delay(3000).animate({
    opacity: 1,
    'filter': '',
    width: '1500px',
    height: '35px'
  }, 1500, function() {
    $('#homebar a').animate({
      opacity: 1,
      'filter': ''
    }, 500);
  });
  
  $('#bar').fadeIn(750);
  
  //$('#visual').detach().appendTo('body');

});



// ----- Pulldown menu -----

$().ready(function() {

  $('#nav>li').hover(function () {
    $('ul', this).stop(true,true).slideDown(100);
  }, function () {
    $('ul', this).slideUp(100);
  });

});


// ----- Right column & Subnav-----

$().ready(function() {

  if ($('#right').length) {

  	var theLoc = $('#right').position().top;
  	$('#right').wrapInner('<div id="fixed">');

  	$(window).scroll(function() {
  		if (theLoc >= $(window).scrollTop()) {
  			if ($('#fixed').hasClass('fixed')) {
  				$('#fixed').removeClass('fixed');
  				$('#subnav').removeClass('fixed');
  			}
  		} else {
  			if (!$('#fixed').hasClass('fixed')) {
  				$('#fixed').addClass('fixed');
  				$('#subnav').addClass('fixed');
  			}
  		}
  	});
	
	}
	
});



// ----- Focus -----

$().ready(function() {
  
  $('#focus ul').bxSlider({
    displaySlideQty: 3,
    moveSlideQty: 1,
    controls: true,
    infiniteLoop: true,
    auto: true,
    speed: 1500,
    pause: 4000
  });
  
});



// ----- News -----

$().ready(function() {

  $('#news h3 a').click(function () {
  
    $('#newsleft').hide();
    $('#newsright').hide();
    tab = $(this).attr('rel');
    $('#'+tab).show();
    return false;
    
  });

});



// ----- Awards -----

$().ready(function() {

  $('#seemoreawards').click(function () {

    $('#moreawards').toggle();
    $('#seemoreawards').hide();
    return false;

  });

});



// ----- Zoom -----

$().ready(function() {

  $("a.zoom").fancybox({
		'imageScale': true,
		'padding': 10,
		'zoomOpacity': true,
		'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		'zoomSpeedChange': 300,
		'overlayShow': true,
		'overlayColor': "#333333",
		'overlayOpacity': 0.5,
		'enableEscapeButton': true,
		'showCloseButton': true,
		'hideOnOverlayClick': true,
		'hideOnContentClick': false,
		'centerOnScroll': true,
		'titlePosition': 'inside',
	  'transitionIn'	:	'elastic',
	  'transitionOut'	:	'elastic'
	});

});



// ----- Product request -----

$().ready(function() {

  $('#requestNext').click(function() {

    $('#formpart1').hide();
    $('#formpart2').show();

  });

  $('#requestBack').click(function() {

    $('#formpart2').hide();
    $('#formpart1').show();

  });
  
  $('#request').submit(function() {
  		
	  if ($('#quantity').val() == "") {
	    $('#formpart2').hide();
    	$('#formpart1').show();
	    $('#quantity').focus();
	    alert("Please enter an ordering quantity.");
	    return false;
	  } else if ($('#quantity').val() < 10) {
	    $('#formpart2').hide();
    	$('#formpart1').show();
    	$('#quantity').focus();
    	alert("Ordering quantity out of limits. Please correct it.");
	    return false;
	  }
	
	  if (($('#app9').is(':checked')) && ($('#application_value').val() == "")) {
	  	$('#formpart2').hide();
    	$('#formpart1').show();
    	$('#application_value').focus();
	    alert("Please specify an application.");
	    return false;
	  }
		
	  if ($('#firstname').val() == "") {
	    alert("Please enter your first name.");
	    $('#firstname').focus();
	    return false;
	  }
	
	  if ($('#lastname').val() == "") {
	    alert("Please enter your last name.");
	    $('#lastname').focus();
	    return false;
	  }
	
	  if ($('#Company').val() == "") {
	    alert("Please enter your company name.");
	    $('#Company').focus();
	    return false;
	  }
	
	  if ($('#Title').val() == "") {
	    alert("Please enter your title.");
	    $('#Title').focus();
	    return false;
	  }
	
	  if ($('#Address').val() == "") {
	    alert("Please enter your address.");
	    $('#Address').focus();
	    return false;
	  }
	
	  if ($('#City').val() == "") {
	    alert("Please enter your city.");
	    $('#City').focus();
	    return false;
	  }
	
	   if ($('#Zip').val() == "") {
	    alert("Please enter your zip code.");
	    $('#Zip').focus();
	    return false;
	  }
	
	  if ($('#Country').val() == "") {
	    alert("Please enter your country.");
	    $('#Country').focus();
	    return false;
	  }
	
	  if ($('#Phone').val() == "") {
	    alert("Please enter your phone number.");
	    $('#Phone').focus();
	    return false;
	  }
	
	  if ($('#other').val() == "") {
	    alert("Please enter your e-mail address.");
	    $('#other').focus();
	    return false;
	  }
	    
  });

});



// ----- Tabs -----

$().ready(function() {

	$('#tabs ul a').click(function(event){
	  event.preventDefault();
		switch_tabs($(this));
	});

	switch_tabs($('.defaulttab'));

});

function switch_tabs(obj) {

	$('#tabs .tab-content').addClass('thide').removeClass('tshow');
	$('#tabs a').removeClass('selected');
	var id = obj.attr('rel');

	$('#'+id).addClass('tshow').removeClass('thide');
	obj.addClass('selected');

}



// ----- FAQ -----

$().ready(function() {

	$('#faq a').click(function(event){
	
	  event.preventDefault();
	  var id = $(this).attr('href');
	  
    $('#faq div:not('+id+')').slideUp();

		$(id).slideToggle();
		
	});

});


//------------ Map contact ------------

$().ready(function() {

  $('#contactmap area').click(function() {
    pays = $(this).attr('rel');
    $('#contactmapimg').attr('src','/images/maps/map_contact_'+pays+'_bleu.jpg').show();
    $('#right .contacts div').hide();
    $('#right #'+pays+'').show();
    return false;
  });

});

