/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

function update(url,div,typeR) { 
   $('#'+div).html('<img src="images/ajax-loader.gif"  />'); 
	  $.ajax({  
	    type: typeR,
	    url: url,           
	    cache : true,
	    timeout: 0,	   
	    success: function(data) {
	      $('#'+div).html(data);      
	      //window.setTimeout(update, 10000);
	    },
	    error: function (XMLHttpRequest, textStatus, errorThrown) {
	      $('#'+div).html('Timeout contacting server..');
	      window.setTimeout(update, 10000);
	    }
	})
}


function update_form(url,div,typeR,form) { 
   $('#'+div).html('<img src="images/ajax-loader.gif"  />');   
	 var str = $(form).serialize();
	  $.ajax({  
	    type: typeR,
	    url: url,
	    cache : true,
	    timeout: 0,
	    data:str,	   
	  	success: function(data) {
	      $('#'+div).html(data);      
	      //window.setTimeout(update, 10000);
	    },
	    error: function (XMLHttpRequest, textStatus, errorThrown) {
	      $('#'+div).html('Timeout contacting server..');
	      window.setTimeout(update, 10000);
	    }
	})
}



(function($){
 
	$.fn.toogleDiv = function(){
               this.each(function() {               
	                $(this).siblings('.extend').hide();
	                $(this).click(function(){
					$(this).siblings('.extend').slideToggle("slow");
				}); 
               
               });
        };
 
})(jQuery)


$(function () {

    $(".comment_button").click(function () {

        var element = $(this);

        var boxval = $("#content").val();

        var dataString = 'content=' + boxval;

        if (boxval == '') {
            alert("Please Enter Some Text");

        }
        else {
            $("#flash").show();
            $("#flash").fadeIn(400).html('Chargement');
            $.ajax({
                type: "POST",
                url: "update_ajax.php",
               
                data: dataString,
                cache: false,
                success: function (html) {

                    $("ol#update").prepend(html);
                    $("ol#update li:first").slideDown("slow");

                    document.getElementById('content').value = '';
                    $('#content').value = '';
                    $('#content').focus();
                    $("#flash").hide();

                }
            });
        }
        return false;
    });


    // delete undate
    $('.delete_update').live("click", function () {
        var ID = $(this).attr("id");

        if (confirm("Sure you want to delete this update? There is NO undo!")) {
            $(".bar" + ID).slideUp();
        }

    });

    //comment slide
    $('.comment').live("click", function () {

        var ID = $(this).attr("id");
        $(".fullbox" + ID).show();
        $("#c" + ID).slideToggle(300);


    });


    //commment Submint
    $('.comment_submit').live("click", function () {

        var ID = $(this).attr("id");

        var comment_content = $("#textarea" + ID).val();

        var dataString = 'comment_content=' + comment_content;

        if (comment_content == '') {
            alert("Please Enter Comment Text");

        }
        else {


            $.ajax({
                type: "POST",
                url: "comment_ajax.php",
                data: dataString,
                cache: false,
                success: function (html) {
                    $("#commentload" + ID).append(html);
                    document.getElementById("textarea" + ID).value = '';

                    $("#textarea" + ID).focus();

                }
            });


        }

        return false;
    });

    //comment delete
    $('.cdelete_update').live("click", function () {
        var ID = $(this).attr("id");

        if (confirm("Sure you want to delete this Comment? There is NO undo!")) {
            $("#comment" + ID).slideUp();
        }

    });





});
