$(function(){
  
  swfobject.embedSWF("modules/gripChallenge/medias/Showa.swf", "gcAnimation", "100%", "525", "9.0.0", "modules/gripChallenge/medias/playerProductInstall.swf", {}, { wmode: "transparent" }, { id: "Showa", name: "Showa" });  
  });

var GC = {
  opened: false
  };

function swfClose()
  {
	if(GC.opened == true)
	  {
	  $("#gcAnimation").animate({ height: "340px" }, "fast");
    $("#gcBottom").fadeIn("fast", function(){
      GC.opened = false;
      });
    }
  }

function go()
  {
  if(GC.opened == false)
    {
    $("#gcAnimation").animate({ height: "525px" }, "fast");
	  $("#gcBottom").fadeOut("fast", function(){
	    GC.opened = true;
	    });
    }
  }
  
function formulaire(datas)
  {
	/*var params="&language="+datas.country_id;
	params+='&'+$.param(datas);*/
	datas.glove=datas.requested.glove;
	datas.size=datas.requested.size;
	datas.requested='';
	datas.language=datas.country_id;
	$.ajax({
	  type: "POST",
      dataType: "json",
	  url: "modules/gripChallenge/scripts/send.php",
	  data: datas
	  });
  }

function swfLoaded()
  {
  setLang(gcLanguage);
  }

function setLang(lang, id)
  {
  var ids = [];
  ids[191] = "fr";
  ids[128] = "en";
  ids[59] = "es";
  ids[205] = "it";
  ids[5] = "de";
  ids[121] = "nl";
  var language_id = jQuery.inArray(lang, ids);
  
	$("#Showa").get(0).setLang(lang, language_id);
  }

jQuery.isArray = function(obj){
		return toString.call(obj) === "[object Array]";
	};

// extracted from jquery 1.4.2
// Serialize an array of form elements or a set of
// key/values into a query string
function toQueryString(a, traditional ) {
	var s = [];
	
	// Set traditional to true for jQuery <= 1.3.2 behavior.
	if ( traditional === undefined ) {
		traditional = jQuery.ajaxSettings.traditional;
	}
	
	// If an array was passed in, assume that it is an array of form elements.
	if ( jQuery.isArray(a) || a.jquery ) {
		// Serialize the form elements
		jQuery.each( a, function() {
			add( this.name, this.value );
		});
		
	} else {
		// If traditional, encode the "old" way (the way 1.3.2 or older
		// did it), otherwise encode params recursively.
		for ( var prefix in a ) {
			buildParams( prefix, a[prefix] );
		}
	}

	// Return the resulting serialization
	return s.join("&").replace(/%20/g, "+");

	function buildParams( prefix, obj ) {
		if ( jQuery.isArray(obj) ) {
			// Serialize array item.
			jQuery.each( obj, function( i, v ) {
				if ( traditional || /\[\]$/.test( prefix ) ) {
					// Treat each array item as a scalar.
					add( prefix, v );
				} else {
					// If array item is non-scalar (array or object), encode its
					// numeric index to resolve deserialization ambiguity issues.
					// Note that rack (as of 1.0.0) can't currently deserialize
					// nested arrays properly, and attempting to do so may cause
					// a server error. Possible fixes are to modify rack's
					// deserialization algorithm or to provide an option or flag
					// to force array serialization to be shallow.
					buildParams( prefix + "[" + ( typeof v === "object" || jQuery.isArray(v) ? i : "" ) + "]", v );
				}
			});
				
		} else if ( !traditional && obj != null && typeof obj === "object" ) {
			// Serialize object item.
			jQuery.each( obj, function( k, v ) {
				buildParams( prefix + "[" + k + "]", v );
			});
				
		} else {
			// Serialize scalar item.
			add( prefix, obj );
		}
	}

	function add( key, value ) {
		// If value is a function, invoke it and return its value
		value = jQuery.isFunction(value) ? value() : value;
		s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
	}
}
