/**
*
* Jquery help from Laurent Batailley, www.batailley.net
*
**/
function submitform()
{
  document.comform.submit();
}
//----------------------------------------------------------------------------------------------------
 var G = (function(){
//-----------------	
//Private
	function _zeroNotNull(height_return){
			if (height_return == null) {return 0;}
			else {return height_return;}
		};

//-----------------	
//Public	
    var o = {};	
//	o.Vals = 
	o.btn = {state:"after",lacouche:1};
	o.init = function(fromtpl_vals){
		this.Vals = fromtpl_vals;
		//Values Setup;	
		this.Vals.new_h = 0;	
		this.imageLoad("#img_ddbtn_after",  this.Vals.img_name);
		this.computeValues();		
		this.setUpEvents();
		this.human = false;
	};
/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*/
	o.dump = function (arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects
	 for(var item in arr) {
	  var value = arr[item];
	 
	  if(typeof(value) == 'object') { //If it is an array,
	   dumped_text += level_padding + "'" + item + "' ...\n";
	   dumped_text += dump(value,level+1);
	  } else {
	   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
	  }
	 }
	} else { //Stings/Chars/Numbers etc.
	 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
	} 
	/*
	 * */

	o.computeValues = function(){
		this.Vals.vp_h = $(window).height();
		this.Vals.vp_w = $(window).width();
		this.Vals.maxdispo = this.Vals.vp_h - this.Vals.img_hminus;;
		this.Vals.maxWdispo = this.Vals.vp_w-30;				
		this.Vals.ratio = parseInt(this.Vals.img_w)/parseInt(this.Vals.img_h);
		this.Vals.marginer = (this.Vals.maxdispo - parseInt(this.Vals.img_h))/ 2;	
		if (this.Vals.img_h < (this.Vals.maxdispo)) {
			$("#mainimage").css("width", parseInt(this.Vals.img_w) + "px");
			$("#mainimage").css("height", parseInt(this.Vals.img_h) + "px");
			$("#imgpart").css("margin-top", this.Vals.marginer);
			$("#navlinks").css("margin-top", this.Vals.marginer);
			$("#imgpart").css("margin-bottom", this.Vals.marginer);
			$("#menu").css("margin-top", "0px");
		}
		else {
			//get the ratio
			this.Vals.ratio = parseInt(this.Vals.img_w) / parseInt(this.Vals.img_h);
			this.Vals.new_h = this.Vals.maxdispo - 10;
			this.Vals.new_w = Math.round(this.Vals.new_h * this.Vals.ratio);			
			$("#mainimage").css("width", parseInt(this.Vals.new_w + "px"));
			$("#mainimage").css("height", parseInt(this.Vals.new_h + "px"));
			$("#imgpart").css("margin-bottom", "5px");
			$("#imgpart").css("margin-top", "5px");
			$("#navlinks").css("margin-top", "5px");
			$("#menu").css("margin-top", 0);
		};

		$("#mainimage").removeClass("loading");
		$("#allcontainer").removeClass("hidetitle");

		$("#navlinks").css("height", $("#top").height());		
	};

	o.imageLoad= function(container,source)      {
			
			var img = new Image();
			$(img).load(function(){
				$("#mainimage").addClass("loading");
				$(this).hide();
				
				$(container).append(this);
				$(this).fadeIn();	
			})
			.error(function(){})
			.attr('src',""+source);
	};
	o.switcher = function (cssid){
		this.btn.lacouche++;
		switch(cssid.split("_")[1]) {
			case "before":
				this.btn.lasource = "" + this.Vals.img_namefirst +"-0.jpg";
				o.messenger.showIn("Loading original version");
				break;
			case "after":
				this.btn.lasource = "" + this.Vals.img_namefirst +"-98.jpg";
				o.messenger.showIn("Loading final version");							
				break;
			default:
				this.btn.lasource = "" + this.Vals.img_namefirst +"-"+ cssid.split("_")[1]  +".jpg";
				o.messenger.showIn("Loading step "+ cssid.split("_")[1] + " Image");	
			break;
		}
		if ($('#img_' + cssid).length === 0) {//load de l'autre image
			$("#mainimage").append("<div id='img_" + cssid + "'><\/div>");
			$("#img_" + cssid).hide();
						$("#img_" + cssid).css("position", "absolute");
						$("#img_" + cssid).css("top", 0);
						$("#img_" + cssid).css("left", 0);
						$("#img_" + cssid).css("z-index", this.btn.lacouche);
						$("#img_" + cssid).fadeIn();
			if (cssid.split("_")[1] == "before")
			{

				$("#img_ddbtn_after").fadeOut();
			}
			//load
			var img = new Image();
			$(img).load(function(){
				$(this).hide();
				$("#img_" + cssid).append(this);
				$(this).fadeIn();
			}).error(function(){
			}).attr('src', this.btn.lasource);
			$("#img_" + cssid).fadeIn();
			
		}
		else {
			$("#img_" + cssid).hide();
			$("#img_" + cssid).css("position", "absolute");
			$("#img_" + cssid).css("top", 0);
			$("#img_" + cssid).css("left", 0);
			$("#img_" + cssid).css("z-index", this.btn.lacouche);
			$("#img_" + cssid).fadeIn();	
			if (cssid.split("_")[1] == "before")
			{
				$("#img_ddbtn_after").fadeOut();
			}
			if (cssid.split("_")[1] == "after")
			{
				$("#img_ddbtn_before").fadeOut();
			}
		}
		o.messenger.showOff();
		//
		$(".current_dd").removeClass("current_dd");
		$("#" + cssid).addClass("current_dd");	

	};

	o.formWorks = function (){
		
		$('#form_firstline INPUT')
			.focus(function(){$(this).addClass("inpfocus");})			
			.blur(function(){$(this).removeClass("inpfocus");});
		
		;			
		$('#form_txtarea TEXTAREA')
			.focus(function(){$("#form_txtarea").addClass("txtfocus");})
			.blur(function(){$("#form_txtarea").removeClass("txtfocus");})			
		;		
		/*$("INPUT.submit").hover(function(){
			$(this).css("background-color", "#E4C131");
		}, function(){
			$(this).css("background-color", "#A3A3A3");
		});
		$("#allform").hover(
			function(){
				if (!o.human){
					$("#form_sub").append("<input id='you_are' type='hidden' name='you_are' value='ahuman' />");
					$("INPUT.submit").click(function(){o.submitCom()});
					o.human = true;
				}
			},
			function(){}
		);*/
	}
	/*o.submitCom = function(){
		//loader dessus
		if ( $("#message").val() == "" ){return;}
		$("#allform").addClass("loading").height($("#allform FORM").height());
		$("#allform FORM").fadeOut();

		//post contenu form
		 $.post("/index.php?x=save_comment", { 
			name: $("#name").val(),
			email: $("#mail").val(),
			url:$("#url").val(),
			message:$("#message").val(),
			parent_name:$("#parent_name").val(),
			parent_id:$("#parent_id").val(),
			you_are: $("#you_are").val()
			},
			//callback
		   function(data){
		     //recup html
			 $("#commentbloc UL").append(data);
			 $("#commentbloc UL LI:last").hide();
			 	if ($("(#commentbloc UL LI:last):has(span)"))
				{
					 $("#commentbloc UL LI:last").fadeIn();
					 if($("LI.nocom").length > 0){$("LI.nocom").fadeOut();}					 
					 $("#allform").removeClass("loading");
					 $("#message").val(""),
					 $("#allform FORM").fadeIn();
 					 //popup
 
				}
				else {					 				 
					 $("#allform").removeClass("loading");
					 $("#allform FORM").fadeIn();
 					 //popup
					
				}
		   }
		 );		
	}  */


	//	
	o.messenger = {
		showIn : function(text){$("#themessage").html(text).fadeIn(250);},
		showOff : function(){$("#themessage").fadeOut(100);},
		flash   : function(text){$("#themessage").html(text).fadeIn("slow").fadeOut(1500);}
	};
	o.setUpEvents = function (){
		//----------------------------------------------------------------------					
		//IMAGE EVENTS
		//----------------------------------------------------------------------
		$("#linkmap a#area_prev").hoverIntent(
			function(){				
				$(this).attr("title", "");
				o.messenger.showIn("Go to the previous post");},
			function(){o.messenger.showOff();}
			);
		$("#linkmap a#area_next").hoverIntent(
			function(){				
				$(this).attr("title", "");
				o.messenger.showIn("Go to the next post");},
			function(){o.messenger.showOff();}
			);			
		$("#linkmap a").click(
			function(){
				$("#mainimage IMG").fadeOut();
				$("#mainimage").addClass("loading");
			}
		);		
		//----------------------------------------------------------------------					
		//PP EVENTS
		//----------------------------------------------------------------------					
		$("DIV.ddclic").click(function(){o.switcher($(this).attr("id"));});


		//----------------------------------------------------------------------
		//Messenger popups on menu items
		$("#menu_stumble_link").hoverIntent(
			function(){$(this).attr("title", "");o.messenger.showIn("Thumb up this image on Stumble Upon");},
			function(){o.messenger.showOff();}
		);

		$("#menu_hiresdownload_link").hoverIntent(
			function(){$(this).attr("title", "");o.messenger.showIn("Download a high res image of this picture");},
			function(){o.messenger.showOff();}
		);
	
		$("#menu_digg_link").hoverIntent(
			function(){$(this).attr("title", "");o.messenger.showIn("Digg this picture over at Digg, digg it?");},
			function(){o.messenger.showOff();}
		);			
		//----------------------------------------------------------------------					
		//FORM EVENTS
		//----------------------------------------------------------------------
		o.formWorks();
		//----------------------------------------------------------------------					
		//WINDOW EVENTS
		//----------------------------------------------------------------------
		 $(window).bind("resize", function(){  
     		o.computeValues();
 		});
	}
//--------------
  return o;
  })();
//----------------------------------------------------------------------------------------------------
	