//Init Form newfeed
$(document).ready(function() { 
var options = {target:'#newfeeds_result',resetForm:true,
	success:    function() { 
        //alert('Merci pour la soumission'); 
    	} };
        // bind 'myForm' and provide a simple callback function 
         $('#newfeeds').ajaxForm(options);
		
        }); 

 //Init scrollable
$(function() {


var root = $("#wizard").scrollable({size: 1, clickable: false});



// some variables that we need
var api = root.scrollable(), drawer = $("#drawer");

// validation logic is done inside the onBeforeSeek callback
api.onBeforeSeek(function(event, i) {

	// we are going 1 step backwards so no need for validation
	if (api.getIndex() < i) {

		// 1. get current page
		var page = root.find(".page").eq(api.getIndex()),

			 // 2. .. and all required fields inside the page
			 inputs = page.find(".required :input").removeClass("error"),

			 // 3. .. which are empty
			 empty = inputs.filter(function() {
				return $(this).val().replace(/\s*/g, '') == '';
			 });

		 // if there are empty fields, then
		if (empty.length) {

			// slide down the drawer
			drawer.slideDown(function()  {

				// colored flash effect
				drawer.css("backgroundColor", "#229");
				setTimeout(function() { drawer.css("backgroundColor", "#fff"); }, 1000);
			});

			// add a CSS class name "error" for empty & required fields
			empty.addClass("error");

			// cancel seeking of the scrollable by returning false
			return false;

		// everything is good
		} else {

			// hide the drawer
			drawer.slideUp();
		}

	}

	// update status bar
	$("#status li").removeClass("active").eq(i).addClass("active");

});



// if tab is pressed on the next button seek to next page
root.find("button.next").keydown(function(e) {
	if (e.keyCode == 9) {

		// seeks to next tab by executing our validation routine
		api.next();
		e.preventDefault();
	}
});

});


//Init YUI
var assetsDir = "assets/";
var buildDir = "yui/build/";
var yuiConfig = {base:"yui/build/", timeout: 10000};
//var yuiConfig = {combine: true, timeout: 10000};


//Init Slider
/*
$(document).ready(function(){	
			
			$("#slider2").easySlider({
				controlsBefore:	'<p id="controls2">',
				controlsAfter:	'</p>',		
				prevId: 'prevBtn2',
				nextId: 'nextBtn2',
				controlsShow:		false,
				auto: true, 
				pause: 8000,
				continuous: true	
			});			
		});	
*/

//init Uploadify
$(document).ready(function() {
	$("#uploadify").uploadify({
		'uploader'       : 'scripts/uploadify.swf',
		'script'         : 'scripts/uploadify.php',
		'cancelImg'      : 'cancel.png',
		'folder'         : 'uploads',
		'queueID'        : 'fileQueue',
		'auto'           : false,
		'buttonImg'	: 'button.jpg',
		'buttonText'     : 'Ajouter',
		'multi'          : true
	});


//$("#create-user").click(function () { alert ('load PHP vers Base-de-donnée'); });
//$("#create-user").click(function () { 
//$('#newfeeds').submit(function() { 
    // submit the form 
    //$(this).ajaxSubmit(); 
    // return false to prevent normal browser submit and page navigation 
   // return false; 
//});
// });


//init TABS
$(function() {
		$("#tabs").tabs();
	});
	$(function() {
		$("#tabs2").tabs();
	});


    
    $("#button_hide_tab").click(function () {

      $("#tabs2").slideToggle("slow");
    });



//init Tolltips and Overlay




$("#pub img[title]").tooltip('#tooltip');
$("a[rel]").overlay({ top: 100, expose: { color: '#000', loadSpeed: 200, opacity: 0.5 },api: true });

});

var xmlhttp

function showHint(str)
{
if (str.length==0)
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
var url="../php/vigi.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}


