(function($) {
	$.fn.watermark = function(css, text) {
		return this.each(function() {
			var i = $(this), w;
			i.focus(function() {
				w && !(w=0) && i.removeClass(css).data('w',0).val('');
			})
			.blur(function() {
				!i.val() && (w=1) && i.addClass(css).data('w',1).val(text);
			})
			.closest('form').submit(function() {
				w && i.val('');
			});
			i.blur();
		});
	};
	$.fn.removeWatermark = function() {
		return this.each(function() {
			$(this).data('w') && $(this).val('');
		});
	};
})(jQuery);

jQuery('#header').ready(function() {
  MSDropDown.init('#language', 80, 50);
});
jQuery('#form_holder').ready(function() {
  //MSDropDown.init('#form_holder select[id$="country"]', 170, 50, 10);
  //MSDropDown.init('#form_holder select[id$="numvehicles"]', 170, 50, 100);
  //MSDropDown.init('#form_holder select[id$="numdepots"]', 170, 50, 10);

  $('#form_holder input[type!="checkbox"], #form_holder textarea').each(function() {
    $(this).watermark('watermark', $(this).prev('label').html());
    $(this).prev('label').css({'position':'absolute','left':'-9999px'});
  });
  
  $('#form_holder select').each(function() {
    $(this).prev('label').css({'position':'absolute','left':'-9999px'});
  });
});
jQuery('#homeTop').ready(function() {
  MSDropDown.init('#our_solutions', 285, 50, 10);
	MSDropDown.init('#interested_in', 285, 50, 100);
});


jQuery(document).ready(function () {
  $('.select_redirect').change(function(){
    value = $(this).attr('value');
    if(value == '' || value == '#'){
      return false;
    }
    window.location = value;
  });
  $('.clear_input').each(function() {
    $(this).watermark('watermark', $(this).prev('label').html());
    $(this).prev('label').css({'position':'absolute','left':'-9999px'});
  });
});

jQuery('#language_form').ready(function () {
  $('#language').change(function (){
    $('#language_form').submit();
  });
});


/**
* We use the initCallback callback
* to assign functionality to the controls
*/
function mycarousel_initCallback(carousel) {
  jQuery('.jcarousel-control a').bind('click', function() {
    carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr("rel")));
    carousel.startAuto(0);
    return false;
  });
  
  jQuery('.jcarousel-control a').hover( function(){ $(this).css({opacity: 0.5})}, function(){ $(this).css({opacity:1})} );

  // Pause autoscrolling if the user moves with the cursor over the clip.
  carousel.clip.hover(function() {
      carousel.stopAuto();
  }, function() {
      carousel.startAuto();
  });
};

function mycarousel_itemVisibleCallback(carousel, item, idx, state) {
  jQuery('#jcarousel_' + idx).css({ opacity: 1 });
  for (var i=1; i <= 4; i++) {
    jQuery('#jcarousel_' + i).attr("class", (i == idx ? "banner_nav_on" : "banner_nav_off"));
  }
}

jQuery('#header-carousel').ready(function() {
  jQuery(".jcarousel-content").jcarousel({
    scroll: 1,
    auto: 5,
    wrap: 'both',
    initCallback: mycarousel_initCallback,
    itemVisibleInCallback: { onBeforeAnimation: null, onAfterAnimation: mycarousel_itemVisibleCallback },
    // This tells jCarousel NOT to autobuild prev/next buttons
    buttonNextHTML: null,
    buttonPrevHTML: null
  });
});


