// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function showUS() {
  $('i18n').hide();
  $('uscan').show();
}

function showI18N() {
  $('uscan').hide();
  $('i18n').show();
}

/* This utility function resolves the string movieName to a Flash object reference based on browser type. */
function getMovieName(movieName) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName]
  }
  else {
    return document[movieName]
  }
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) {i = 0.00;}
	var minus = '';
	if(i < 0) {minus = '-';}
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) {s += '.00';}
	if(s.indexOf('.') == (s.length - 2)) {s += '0';}
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()

function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.toString().split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) {return '';}
	var minus = '';
	if(i < 0) {minus = '-';}
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) {a.unshift(n);}
	n = a.join(delimiter);
	if(!d || d.length < 1) {amount = n;}
	else {amount = n + '.' + d;}
	amount = minus + amount;
	return amount;
}

jQuery.noConflict();

jQuery('document').ready(function(){
  if(jQuery('#model_navigation').length != 0){

      jQuery('#html_000 h3').click(function(){
        jQuery('.link_category ul').hide();
        if(jQuery('#main_navigation').is(':visible')){
          hideboat_menu();
        }else{
          jQuery('#main_navigation').show();
        }
      });
      jQuery('#secondary_navigation h4').click(function(){
        if(jQuery(this).parent().find('ul').is(':visible')){
          jQuery(this).parent().find('ul').hide();
        }else{  
          hideboat_menu();
          jQuery('#secondary_navigation').find('li ul').hide();
          jQuery(this).parent().find('ul').show();
        }
      });

    //Boat menu stuff

      jQuery('#model_navigation h4').click(function(){
        if(jQuery(this).parent().find('ul').is(':visible')){
          jQuery(this).parent().find('ul').hide();
          jQuery(this).css('color','white')
        }else{
          jQuery('#main_navigation li ul').hide();
          jQuery(this).parent().parent().find('li h4').css('color','white');
          jQuery(this).css('color','#7DB8F5')
          jQuery(this).parent().find('ul').show();
        }
      });

      window.onload = function(){
        jQuery('#conditional_slideshow').cycle({
            fx: 'fade',
            speed:    1200,
            timeout:  5000,
            cleartypeNoBg: true
        });
        setInterval(function(){
           jQuery('.new_boat').toggle();
        },3000);
      }

      function hideboat_menu(){
        jQuery('#main_navigation li ul').hide();
        jQuery('#main_navigation h4').css('color','white');
        jQuery('#main_navigation').hide();
      }
      
  }
});
