
// HB's Main Object
Kone = {
	Box: {
		Content: {},
		Lightbox: {},
		Menu: {}
	},
	Ctl: {
		Transition: {},
		General: {},
		Histo:{}
	},
	Paths: {
		PATH_JST: 'public/js/front/',						// Javascript
		PATH_PLG: '/plugins/front/',						// JQuery plugins
		PATH_CSS: '../../css/front',						// Css
		PATH_IMG: '../../images/front/',						// Images
		PATH_HTC: '/plugins/front/iepngfix/blank.gif',   	// HTC's blank image fix
		BASEURL:  '',						// BaseUrl Site
		BASEWEB : '/'
	},
	Language: null
}

// Skip a line for each file to avoid missing cariage return error


Tools = {
	
		initialize: function () {
			
					
		},
		fieldInfo: function(){

			$(".authRecall").focus(function() {
				if($(this).attr("value") == $(this).attr("alt")) {
					$(this).attr("value", "");
				}
			});

			$(".authRecall").blur(function() {
				if($(this).attr("value") == "") {
					$(this).attr("value", $(this).attr("alt"));
				}	
			});
			


		}

}

Kone.Box.Content.Menu = {
	
		initialize: function () {

			// Homepage Carousel
			$("#genCarousel").jCarouselLite({
				btnNext: "#genCarouselNext",
				btnPrev: "#genCarouselPrev",
				visible: 5,
				scroll: 5,
				speed: 800,
				vertical: false,
				circular: true
			});
			
			$("#genCarousel").css('visibility','visible');
			
			$(".genCarouselImage").mouseover(function(){
				$(this).siblings('.genCarouselLink').fadeIn();
			});

			$(".genCarouselImage").mouseout(function(){
				$(this).siblings('.genCarouselLink').fadeOut();
			});


			// MENU
			$('.genMenuItem').mouseover(function(){
				
				$(this).css({'color':'#000'});
				
				$('.subMenu').hide();
				var	color = $(this).attr('rel');
				colorID = 'genTransp'+color;				
				$(this).addClass(colorID);
			
			
			
			/*	
				var	submenu = $(this).children("a").attr('rel');
				$(".subMenu[rel='"+submenu+"']").addClass(colorID);
				$(".subMenu[rel='"+submenu+"']").show();
			*/	
			});
				
			$('.genMenuItem').mouseout(function(){
					
				var	color = $(this).attr('rel');
				colorID = 'genTransp'+color;				
				$(this).removeClass(colorID);
				
			});				
				

			$(".subMenu").mouseleave(function(){
				$(this).hide();
			});
			
			$('#genMenuContainer').mouseleave(function(){
				$(".subMenu").hide();
				$('.subShow').show();
			});

			


		}

}


Kone.Box.Content.Rss = {
	
		initialize: function () {

			$('.deployBody').click(function(){
			
				rssNmbre = $(this).attr('rel');
				$("#rssBody"+rssNmbre).slideToggle();
				$(this).toggleClass('textOrange');
				return false;
			});


	 	   var optionsEST = {
				timeNotation: '24h',
		        utc: true,
		        utc_offset: +2
		      }
		      $('#jclock1').jclock(optionsEST);

		      var optionsCST = {
		        utc: true,
		        utc_offset: -4
		      }
		      $('#jclock2').jclock(optionsCST);


			var optionsCST = {
		        utc: true,
		        utc_offset: -4
		      }
		      $('#jclock3').jclock(optionsCST);

		}

}


Kone.Box.Content.Content = {
	
		initialize: function () {

			$("a[rel='content_diaporama']").colorbox({
					transition:"elastic",
					opacity: 0.85
					
			});
	
			
			$(".articleCarousel").jCarouselLite({
					btnNext: ".next",
					btnPrev: ".prev",
					visible: 4,
					scroll: 2,
					auto: 2000,
					speed: 1000,
					vertical: false,
					circular: true,
					beforeStart: function(a) {    
						$("a[rel='diapo']").colorbox({
							transition:"elastic",
							opacity: 0.85
						});
				    }
			});
				
			/*
			$("#sideLatestVideo").jCarouselLite({
						btnNext: ".nextVid",
						btnPrev: ".prevVid",
						visible: 1,
						scroll: 1,
						auto: 2000,
						speed: 1000,
						vertical: false,
						circular: true
			});
			*/
			/*
			$('#commentPost').unbind('click').click(function(){
				$('#comment_post').submit();
			});
			*/
			
			articleSubmission = false;
			
			$("#articleNew").click(function(){
				if(!articleSubmission){
					Kone.Box.Content.Content.articleSubmit();
					articleSubmission = true;	
				}
				
				
			});
			
		
			$("#elContentNewArticle").keyup(function(){
				
				var elContent = CKEDITOR.instances.elContent.getData();
				$(".wmd-preview").html(elContent);
				
			});
			
			
		},
		articleSubmit: function(){
			
			idCategory = $('#idCategory').attr('value');
			elName = $('#elName').attr('value');
		//	elContent = $('#elContent').attr('value');
			idElement = $('#idElement').attr('value');
			elKeyword = $('#elKeyword').attr('value');
			actionPost = $('#newArticle').attr('action');
			var elContent = CKEDITOR.instances.elContent.getData();
			
			
			strUrl = Kone.Paths.BASEWEB + "article/ajaxpost";
			$.post( strUrl , { elName : elName, idCategory: idCategory, elContent: elContent, elKeyword:elKeyword, actionPost:actionPost, idElement:idElement } , function(data){
				

				
				if(data.result){
					
					$(".newArticleError").slideUp();
					
					window.location.href = data.url;
					
				}else{
					if(!data.elName){
						$('.elNameError').slideDown();
					}else{
						$('.elNameError').slideUp();
					}

					if(!data.idCategory){
						$('.idCategoryError').slideDown();
					}else{
						$('.idCategoryError').slideUp();
					}

					if(!data.elKeyword){
						$('.elKeywordError').slideDown();
					}else{
						$('.elKeywordError').slideUp();
					}

					if(!data.elContent){
						$('.elContentError').slideDown();
					}else{
						$('.elContentError').slideUp();
					}					
					articleSubmission = false;
					
				}
				
			},'json');
				
		
			
		}

}


Kone.Box.Content.Lightbox = {
	
		initialize: function () {

					
			$(".lightboxClose").live('click',function(){
				
				Kone.Box.Content.Lightbox.close();
				return false;
			
			});
			
			$(".lightboxCall").click(function(){

					action =  $(this).attr('href');
					title = $(this).attr('title');
					strUrl = Kone.Paths.BASEWEB + action;
					Kone.Box.Content.Lightbox.launch();
					Kone.Box.Content.Lightbox.loading();
					$('#lightboxContent').load( strUrl , {update:true}, function(){
						$('.lighboxTitle').html(title);
					});
				return false;
			});
			
			

			
					
		}, 
		denied: function(){

			
		
		},
		launch: function(){
			$('.buttonLoadingLeft').fadeOut();
			$('.buttonLoadingRight').fadeOut();
			$('#lightboxOverlay').fadeIn('slow', function(){
				$("#lightbox").fadeIn('slow');
			});
		},
		close: function(){
			
				$('#lightbox').fadeOut('slow',function(){
					$("#lightboxOverlay").fadeOut();
					$("#lightboxContent").html('');
				});
			
		},
		loading: function(){
			
			$("#lightboxContent").html('');
			$("#lightboxContent").html('<div class="lightboxLoading"></div>');
			
			
		}

}


Kone.Box.Content.Profile = {
	
		initialize: function () {
			
				
			   
				$("#profileAccountLink").click(function(){
					$("#genLoginMore").slideToggle();
				//	alert('yes');
				});
				
				$('.registerNow').click(function(){
					
						Kone.Box.Content.Lightbox.loading();
						Kone.Box.Content.Lightbox.launch();

						strUrl = Kone.Paths.BASEWEB + "profile/register";
						$('#lightboxContent').load( strUrl , {update:true}, function(){
								// efface les champs au click, puis remet la valeur par défaut
								Tools.fieldInfo();
								
						});

						return false;
				
				});
							
				$(".loginNow").click(function(){
				
					Kone.Box.Content.Lightbox.loading();
					Kone.Box.Content.Lightbox.launch();
					Kone.Box.Content.Profile.login_behaviour();
					
				
					return false;
				});
					
		},
		login_behaviour:function(message, action, value){
			
				strUrl = Kone.Paths.BASEWEB + "profile/login";
				$('#lightboxContent').load( strUrl , {update:true}, function(){
						// efface les champs au click, puis remet la valeur par défaut
						Tools.fieldInfo();
						action = action;
						value =value;
						Kone.Box.Content.Profile.login( action, value);
						
						$('.authForgetLink').click(function(){
							$("#authForget").slideToggle('slow');
							return false;
						});
						
						$('#authLogin').keyup(function(e) {
  							if(e.keyCode == 13) {
								$("#authOk").trigger('click');
						      }
						});
						
						$('#authPassword').keyup(function(e) {
  							if(e.keyCode == 13) {
								$("#authOk").trigger('click');
						      }
						});
						
						$('.lighboxTitle').html(message);
							
				});
			
			
		},
		login: function( action, value){
			
			action = action;
			value = value;
			$(".authLoginBtn").click(function(){
					
					$(this).html('<div class="buttonLoadingRight"></div>');
					
					login = $('#authLogin').attr('value');
					passwd = md5($('#authPassword').attr('value'));
					if( $("#authPersistant").is(':checked') ){
						booPersistant = true;
					}else{
						booPersistant = false;
					}
					
					strUrl = Kone.Paths.BASEWEB + "profile/ajaxlogin";
					$.post( strUrl , { login:login, passwd:passwd, booPersistant: booPersistant, action:action, actionValue:value }, function(data){
							
						if(data.result){
							$(".authLoginBtn").html('');
							$("#authResult").html(data.message);
							$("#authResult").removeClass();
							$("#authResult").addClass('valid');
								$("#authResult").fadeIn(function(){
									
									$(this).oneTime('1s', function(){
											window.location.reload();
									});
									
								});
						}else{
							$(".authLoginBtn").html('');
							$("#authResult").html(data.message);
							$("#authResult").removeClass();
							$("#authResult").addClass('error');
							$("#authResult").slideDown(function(){
								$(this).oneTime('2s', function(){
									$(this).slideUp();
								});
							});
							
						}
					}, "json");
				
			});
			
			
			
		},
		register:function(){
				
				
				$("#regLogin").blur(function(){
				
					login = $('#regLogin').attr('value');

					strUrl = Kone.Paths.BASEWEB + "profile/ajaxchecklogin";
					$.post( strUrl , { login:login }, function(data){

							if(data.result){
								$('#resLogin').fadeIn();
								$('#validLogin').attr('value','true');
							}else{
								$('#resLogin').fadeOut();
								$('#validLogin').attr('value','false');
							}

						}, "json");


				});
				
				$("#registerOk").click(function(){
					
						$(this).html('<div class="buttonLoadingLeft"></div>');
						login = $('#regLogin').attr('value');
						email = $('#regEmail').attr('value');
						password = $('#regPassword').attr('value');
						confirm = $('#regConfirm').attr('value');
						zipcode = $('#regZipcode').attr('value');
						invalidLogin = $('#invalidLogin').attr('value');
						
						idFacebook = $('#idFacebook').attr('value');
						photo = $('#photo').attr('value');
		
						if(confirm !=  password){
							$('#resPassword').fadeIn();
							validConfirm = false;
						}else{
							$('#resPassword').fadeOut();
							validConfirm = true;
						}					
						
						if( login != '' && email != '' && password != '' && confirm != '' ){
							
							$('#resRequired').fadeOut();
							noEmpty = true;
						
						}else{
							$('#resRequired').fadeIn();
							noEmpty = false;
						}
						
//						alert(invalidLogin + ' - '+ noEmpty+ ' - '+ validConfirm);
						
						if( noEmpty == true  && invalidLogin == "false" && validConfirm == true ){
						//	alert('yes');
								password = md5(password);
								strUrl = Kone.Paths.BASEWEB + "profile/ajaxregister";
								$.post( strUrl , { login:login, password:password, email:email, zipcode:zipcode, photo:photo, uid: idFacebook }, function(data){
									
									if (data.result) {
										$("#registerOk").html('');
										$(".register").fadeOut(function(){
	
											$(".registerSuccess").fadeIn(function(){
											
												$(this).oneTime('1s', function(){
													window.location.reload();
												});
											
											});
	
										});
										
									}
									
									
								}, "json");
							
						}else{
							$("#registerOk").html('');
						}
						
						
				
				});
			
		},
		getPassword: function(){
			
			
			
				$(".authPasswordBtn").click(function(){

						login = $('#authForgetPass').attr('value');
					

						strUrl = Kone.Paths.BASEWEB + "profile/passwordemailajax";
						$.post( strUrl , { login:login }, function(data){
							if(data.result){
								$("#authPassResult").html(data.message);
								$("#authPassResult").removeClass();
								$("#authPassResult").addClass('valid');
									
							}else{
								$("#authPassResult").html(data.message);
								$("#authPassResult").removeClass();
								$("#authPassResult").addClass('error');
								
						

							}
						}, "json");

				});
			
			
			
			
		},
		changePassword: function(){
			
			
				
				$(".newPasswordOk").click(function(){
						
						
						email = $('#newEmail').attr('value');
						password = $('#newPassword').attr('value');
						confirm = $('#newConfirm').attr('value');
						passwordRetrieve = $('#passwordRetrieve').attr('value');
						
						if(confirm !=  password){
							$('#resPassword').fadeIn();
							validConfirm = false;
						}else{
							$('#resPassword').fadeOut();
							validConfirm = true;
						}					
						
						if( email != '' && password != '' && confirm != '' ){
							
							$('#resRequired').fadeOut();
							noEmpty = true;
						
						}else{
							$('#resRequired').fadeIn();
							noEmpty = false;
						}

						
						if( noEmpty && validConfirm ){
							
								password = md5(password);
								strUrl = Kone.Paths.BASEWEB + "profile/change";
								$.post( strUrl , { password : password , email : email , passwordRetrieve : passwordRetrieve }, function(data){
									
									
									if (data.result) {
										$(".newPasswordSuccess").slideDown(function(){
											$(this).oneTime("1s", function(){
											 //	window.location = data.url;
												$(this).slideUp();
												$('.loginNow').trigger('click');
											});
										});
										
									}else{
									
										if(data.message){
												$(".errormailChange").slideDown(function(){
													$(this).oneTime("3s", function(){
													
														$(this).slideUp();
													});
												});								
										}else{
												$(".errorChange").slideDown(function(){
													$(this).oneTime("3s", function(){
														$(this).slideUp();
													});
												});
										}
									
										
									}
								
									
									
								}, "json");
							
						}
						
			
				});
			
			
		},
		edit_behaviour: function(){
			
			$("#displayChangePass").click(function(){
				$("#changePass").slideToggle();
				return false;
			});
			
			$('#addFile').change(function(){
				
				$('#updatePhoto').fadeIn();
				
	    	 });			

			$('#updatePhoto').click(function(){
			
				$(this).hide();
				$('#photoContainer img').fadeOut(function(){
					$("#photoContainer").html('<img src="/images/front/gui/bkg/small_loader.gif"></div> ');
					
					
						strUrl =  Kone.Paths.BASEWEB + 'profile/updateimage';

						var options = { 
						dataType: 'json',
				        url:        strUrl,  // target element(s) to be updated with server response 
				    //    beforeSubmit:  showRequest,
				
				//		pre-submit callback
				        success:  function(data){
					
								if(data.result){
										$("#photoContainer").html('<img src="'+data.image+'" /> ');
										$('#photoContainer img').fadeIn();
										$('#addFile').attr('value','');
										
									}else{
										$("#photoContainer").html('<img src="'+data.image+'" /> ');
										$('#photoContainer img').fadeIn();
									}
								}  
							
						};

						$("#profileForm").ajaxSubmit(options);				

					
				});
				return false;


			});

			function showRequest(formData, jqForm, options) { 
			    // formData is an array; here we use $.param to convert it to a string to display it 
			    // but the form plugin does this for you automatically when it submits the data 
			    var queryString = $.param(formData); 

			    // jqForm is a jQuery object encapsulating the form element.  To access the 
			    // DOM element for the form do this: 
			    // var formElement = jqForm[0]; 

			    alert('About to submit: \n\n' + queryString); 

			    // here we could return false to prevent the form from being submitted; 
			    // returning anything other than false will allow the form submit to continue 
			    return true; 
			} 
			function processJson(data) { 
			    // 'data' is the json object returned from the server 
			    alert(data.message); 
			}
			// post-submit callback 
			function showResponse(responseText, statusText, xhr, $form)  { 
			    // for normal html responses, the first argument to the success callback 
			    // is the XMLHttpRequest object's responseText property 

			    // if the ajaxForm method was passed an Options Object with the dataType 
			    // property set to 'xml' then the first argument to the success callback 
			    // is the XMLHttpRequest object's responseXML property 

			    // if the ajaxForm method was passed an Options Object with the dataType 
			    // property set to 'json' then the first argument to the success callback 
			    // is the json data object returned by the server 

			    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
			        '\n\nThe output div should have already been updated with the responseText.'); 
			}



			$('#registerOk').click(function(){
					$(this).html('<div class="buttonLoadingLeft"></div>');
					email = $('#regEmail').attr('value');
					password = $('#regPassword').attr('value');
					confirm = $('#regConfirm').attr('value');
					zipcode = $('#regZipcode').attr('value');
					
					idFacebook = $('#idFacebook').attr('value');
					photo = $('#photo').attr('value');
	
					if(password != ''){
					
						if(confirm !=  password){
							$('#resPassword').fadeIn();
							validConfirm = false;
								$('#registerOk').html('');
						}else{
							
							$('#resPassword').fadeOut();
							validConfirm = true;
						}
							
					}else{
						password = 'none';
						validConfirm = true;
					}				
					
					if( email != '' && password != '' ){
						
						$('#resRequired').fadeOut();
						noEmpty = true;
					}else{
						$('#resRequired').fadeIn();
						noEmpty = false;
					
					}
					
//						alert(invalidLogin + ' - '+ noEmpty+ ' - '+ validConfirm);
					
					if( noEmpty == true  && validConfirm == true ){
					//	alert('yes');
							password = md5(password);
							strUrl = Kone.Paths.BASEWEB + "profile/updateprofile";
							$.post( strUrl , { password:password, email:email, zipcode:zipcode }, function(data){
								
								if (data.result) {
									
									$("#updateSucces").slideDown(function(){
										$('#registerOk').html('');
										$(this).oneTime('2s', function(){
											$("#updateSucces").slideUp();
										});
										
									});
									
								}
								
								
							}, "json");
						
					}else{
							$("#registerOk").html('');
					}
				
				
				
				
			});

			
		},
		facebook: function(){
			
			  FB.init({ apiKey: 'f5751a79c8f73d464c9a87b9c8f0d34b' });

		      // fetch the status on load
		     // FB.loginStatus(handleSessionResponse);

		      $('#tBarFbkConnect').bind('click', function() {
				FB.api({ method: 'Auth.revokeAuthorization' }, function(response) {
		       //   clearDisplay();
		        });
		        FB.login(handleSessionResponse);
				return false;
		      });

			/*
		      $('#logout').bind('click', function() {
		        FB.logout(handleSessionResponse);
		      });

		      $('#disconnect').bind('click', function() {
		        FB.api({ method: 'Auth.revokeAuthorization' }, function(response) {
		          clearDisplay();
		        });
		      });

		      // no user, clear display
		      function clearDisplay() {
		        $('#user-info').hide('fast');
		      }
			*/

		    // handle a session response from any of the auth related calls
		      function handleSessionResponse(response) {
		        // if we dont have a session, just hide the user info
		        if (!response.session) {

		          return;
		        }

		        // if we have a session, query for the user's profile picture and name
		        FB.api(
		          {

						method: 'fql.query',
						query: 'SELECT uid,username, hometown_location,proxied_email , current_location,profile_url ,status, pic_small_with_logo, first_name, last_name, pic, sex, pic_square_with_logo FROM user WHERE uid=' + FB.getSession().uid
					//method: 'fql.query',
		           // query: 'SELECT name, pic FROM profile WHERE id=' + FB.getSession().uid
		          },
		          function(response) {

				//	alert(user.pic);
		        //   $('#user-info').html('<img src="' + user.pic + '">' + user.name).show('fast');
					
				 	var user = response[0];
				//	alert(user.username);
			
					
					strUrl = 'profile/ajaxfblogin';
					$.post( strUrl , { uid: md5(user.uid), hometown_location : user.hometown_location, username:user.username,profile_url:user.profile_url, status:user.status, pic_small_with_logo:user.pic_small_with_logo, first_name:user.first_name, last_name:user.last_name, pic_square_with_logo: user.pic_square_with_logo,  current_location:user.current_location }, function(data){
						if(data.result){
	
									window.location.reload();

						}else{

									Kone.Box.Content.Lightbox.loading();
									Kone.Box.Content.Lightbox.launch();

									strUrl = Kone.Paths.BASEWEB + "profile/register";
									$('#lightboxContent').load( strUrl , {update:true, uid: data.idFacebook, photo: data.photo}, function(){
											// efface les champs au click, puis remet la valeur par défaut
											Tools.fieldInfo();
									});			
									
								}
							}, "json");

		          });
		      }





		    // if we have a session, query for the user's pr ofile picture and name

			function print_r(theObj){
				  if(theObj.constructor == Array ||
				     theObj.constructor == Object){
				    document.write("<ul>")
				    for(var p in theObj){
				      if(theObj[p].constructor == Array||
				         theObj[p].constructor == Object){
				document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
				        document.write("<ul>")
				        print_r(theObj[p]);
				        document.write("</ul>")
				      } else {
				document.write("<li>["+p+"] => "+theObj[p]+"</li>");
				      }
				    }
				    document.write("</ul>")
				  }
				}
			
			
			
		}

}


Kone.Box.Content.Star = {
	
	initialize: function () {
	
		var becomeFanAction = false;
		var removeFanAction = false;
	
		$(".becomeFan").click(function(){
			
			if(!becomeFanAction){
			becomeFanAction = true;
			removeFanAction = false;
			idStar = $('#idStar').attr('value');
		
			$(this).prepend('<div class="buttonLoadingLeft"></div>');
						
			strUrl = Kone.Paths.BASEWEB + "star/becomefanajax";
			$.post( strUrl , { idStar : idStar, fan: true } , function(data){
					
					if(data.result){
						
						nbFan = data.nbFan;
								
						$("#fanNumber").empty();
						$("#fanNumber").append(nbFan);
						$("#nbFans").empty();
						$("#nbFans").append(nbFan);
						
						$("#starBeFan").removeClass("hide");
						$("#starBeFan").addClass('show');
						$("#starBeFan").show()
						$("#starBeFan").empty();
						$("#starBeFan").append(data.info).oneTime('2s', function(){
								$(this).fadeOut();
						});
						
						
						$(".becomeFan").fadeOut(function(){
							$(".removeFan").removeClass("hide");
							$(".removeFan").addClass('show');
							$(".removeFan").show();
							$('.buttonLoadingLeft').fadeOut();		
						});
						
					}else{
						
							Kone.Box.Content.Lightbox.loading();
							Kone.Box.Content.Lightbox.launch();
							action = "becomeFan";
							value = idStar;
							Kone.Box.Content.Profile.login_behaviour(data.message, action, value);
						
					}		
					
			}, 'json');
			}
			return false;
		});
		

		$(".removeFan").click(function(){
			
			if(!removeFanAction){
			removeFanAction = true;
			becomeFanAction = false;
			
			
			$(this).prepend('<div class="buttonLoadingLeft"></div>');
			
			idStar = $('#idStar').attr('value');

						
			strUrl = Kone.Paths.BASEWEB + "star/becomefanajax";
			$.post( strUrl , { idStar : idStar, fan : false } , function(data){
					
					if(data.result){
						
						nbFan= data.nbFan;
						$("#fanNumber").empty();
						$("#fanNumber").append(nbFan);
						      
						$("#starBeFan").removeClass("hide");
						$("#starBeFan").addClass('show');
						$("#starBeFan").show();      
						$("#starBeFan").empty();
						$("#starBeFan").append(data.info).oneTime('2s', function(){
								$(this).fadeOut();
							});
						                    
						$(".removeFan").fadeOut(function(){

							$(".becomeFan").removeClass("hide");
							$(".becomeFan").addClass('show');
							$(".becomeFan").show();
							$('.buttonLoadingLeft').fadeOut();
							
						
							
						});
						
					}
					else{
						
							Kone.Box.Content.Lightbox.loading();
							Kone.Box.Content.Lightbox.launch();
							Kone.Box.Content.Profile.login_behaviour(data.message);
						
					}		
					
					
			}, 'json');
			}	
			return false;
		});
		
		
	
	}
}
Kone.Box.Content.Search = {
	
	initialize: function () {
	
		$(".search").click(function(){
			
			search = $('#searchWord').attr('value');
			if(search=="")
			{
				alert("Vous devez écrire quelque chose");
			}
			else
			{
				$("form").submit();
			}
		
				
			return false;
		});
	}
}
Kone.Box.Content.Comment = {
	
	initialize: function () {

	
		$("#edition").click(function(){
			alert('ca marche');
		});


		$("#commentPost").click(function(){
		               
			comment = $('#comTextarea').attr('value');
			idArticle = $('#idArticle').attr('value');
			nbComment = $('#nbComment').attr('value');
			if(comment==""){
				alert("Vous devez écrire quelque chose");
			}else if(comment !=""){
				strUrl = Kone.Paths.BASEWEB + "comment/postcommentajax";
				$.post( strUrl , { comment : comment, idArticle : idArticle} , function(data){
					
					if(data){
						if(nbComment=="0"){
							$("#commentContainer").empty();
							//$('#nbComment').attr('value','1');
						}
						
						newNbComment=parseInt(nbComment)+1;
						$("#printNbComment").empty();
						$("#printNbComment").append(newNbComment);
						$('#nbComment').attr('value',newNbComment);
						$('#comTextarea').attr('value','');
						$("#commentContainer").append(data);						
					}else{
						
					}
			});
		

		}
		});
		
		
		$('.commentEdit').live('click', function(){
			
			idComment = $(this).attr('rel');
			commentElement = '#comBodyContent'+idComment;
				
			strUrl = Kone.Paths.BASEWEB + "comment/edit";
			
			$(commentElement).slideUp();
	
			$(commentElement).load( strUrl , { idComment : idComment} , function(){
			
				$(commentElement).slideDown();
				$("#commentPostEdit").live('click', function(){
						
				
					$(this).html('<div class="buttonLoadingRight"></div>');
					comBody = $("#bodyCommentPostEdit").attr('value');
					
					strUrl = Kone.Paths.BASEWEB + "comment/ajaxedit";
					$.post( strUrl , { idComment : idComment, comBody: comBody},  function(data){
					
						if(data.result){
							
							$(commentElement).slideUp(function(){
								
								$(this).html(data.comBody).slideDown();
								
							});
							
						}else{
							
						}
					}, 'json');
					return false;
				});
			});
			
				
			return false;
		});
		
	
	}
}
Kone.Box.Content.Article = {
	
	initialize: function () {

		$("#articleBlock").click(function(){
			
					Kone.Box.Content.Lightbox.loading();
					strUrl = Kone.Paths.BASEWEB + "article/block";
					$('#lightboxContent').load( strUrl , {update:true}, function(data){
							// efface les champs au click, puis remet la valeur par défaut
						//	Tools.fieldInfo();
							
							if(data.result == false){
								
								
								
							}else{
								
								Kone.Box.Content.Lightbox.launch();
							}
							
					}, 'json');

					return false;
			
			
		});
		
	
	}
}