var $spriteHeight = 495;
var $Ypos = 0;

function DisplayNextSprite() {
    $Ypos = $Ypos + $spriteHeight;
    $("#slideshow_test").css("background-position", "0px "+$Ypos+"px") ;
    $("#slideshow_test").show(0);
    $("#slideshow_test").fadeTo(2000,1);
    $("#slideshow_test").fadeTo(400,0.0);
    $("#slideshow_test").hide(1, DisplayNextSprite);
}

$(document).ready(function() {       

$(".contents .encart").hover(function(){
  $(".encart2").removeClass("over");
	$(this).addClass("over")
},function(){
	$(this).removeClass("over");
});

if($('.slideshowVentes').length > 0){
 $('.slideshowVentes').cycle({ 
        fx: 'fade', 
       delay: -8000, 
      timeout: 6000
    }); 
}
if($('.slideshowLocationsParis').length > 0){
 $('.slideshowLocationsParis').cycle({ 
        fx: 'fade' , 
       delay: -4000 ,
      timeout: 6000
    }); 
}
if($('.slideshowLocations').length > 0){
 $('.slideshowLocations').cycle({ 
        fx: 'fade' ,
       delay: -2000, 
      timeout: 6000
    }); 
}
if($('#flash_slide_pan').length > 0){
 $('#flash_slide_pan').cycle({ 
        fx: 'fade', 
       delay: -8000, 
      timeout: 6000
    }); 
}

if($('#search').length > 0){

	$('#search select').change(function (){
    		$('#main-col').load($('#ajax_url').val(),{nbr_chambtre: $('#nbr_chambtre').val(),cp: $('#cp').val(),prix_min: $('#prix_min').val(),quartier: $('#quartier').val(),nbr_perso: $('#nbr_perso').val() });
	 });

}
/*
 $("select#pays").change(function(){
    $.getJSON("/usr/kost/pdv.php",{key: 'pays' ,value: $(this).val(), ajax: 'true'}, function(j){
      var options = '';
      $("select#ville").hide();
      for (var i = 0; i < j.length; i++) {
        options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
        $("select#ville").show();
      }
      $("select#ville").html(options);
    })
    $('#resultats').load("/usr/kost/pdv.php",{key: 'filter' ,value: $(this).val()},reinitialiseScrollPane);
  })
  
  $('#resultats').load("/usr/kost/pdv.php",{key: 'display'},reinitialiseScrollPane);*/



$(".encart2").addClass("over");


  if($("#slideshow_test")){
     DisplayNextSprite();
  }
  jQuery("span.decor").each(function() {
   var image = document.createElement("img");
   src =  "http://www.gaboweb.net/reflect/?text="+$(this).text()+"&fg_color=000000&bg_color=FFFFFF&antialiasing=32&font_name=Interstate-Regular.ttf&font_size=8.5&yoffset=0&xpadding=2&ypadding=1&reflex_margin=0&reflex_start=40&reflex_end=0&return=image";
   $(this).replaceWith('<img src="'+src+'" alt="'+$( this ).text()+'" title="'+$( this ).text()+'">'); 
  });


 jQuery("span.decoractive").each(function() {
   var image = document.createElement("img");
   src =  "http://www.gaboweb.net/reflect/?text="+$(this).text()+"&fg_color=A00806&bg_color=FFFFFF&antialiasing=32&font_name=Interstate-Regular.ttf&font_size=8.5&yoffset=0&xpadding=2&ypadding=1&reflex_margin=0&reflex_start=40&reflex_end=0&return=image";
   $(this).replaceWith('<img src="'+src+'" alt="'+$( this ).text()+'" title="'+$( this ).text()+'">'); 
  });
  jQuery("h2.titre").each(function() {
    //alert($(this).css("color"));
    var image = document.createElement("img");
    src ="http://www.gaboweb.net/reflect/?text="+ $( this ).text()+"&fg_color=A00806&bg_color=ffffff&font_name=BickhamScriptPro-Regular.otf&font_size=30&yoffset=-30&xpadding=0&ypadding=0&return=image&antialiasing=1&valign=true&debug=true";
    $(this).replaceWith('<img src="'+src+'" alt="'+$( this ).text()+'" title="'+$( this ).text()+'" class="decorate" align="center">'); 
  });

  jQuery("span.welldoneW").each(function() {
    //alert($(this).css("color"));
    var image = document.createElement("img");
    src ="http://www.gaboweb.net/reflect/?text="+ $( this ).text()+"&fg_color=A00806&bg_color=ffffff&font_name=BickhamScriptPro-Regular.otf&font_size=30&yoffset=-30&xpadding=5&ypadding=0&return=image&antialiasing=1&valign=true&debug=true";
    $(this).replaceWith('<img src="'+src+'" alt="'+$( this ).text()+'" title="'+$( this ).text()+'" class="decorate" align="center">'); 
  });
  
  jQuery("h2").each(function() {
    //alert($(this).css("color"));
    var image = document.createElement("img");
    src ="http://www.gaboweb.net/reflect/?text="+ $( this ).text()+"&fg_color=A00806&bg_color=ffffff&font_name=BickhamScriptPro-Regular.otf&font_size=35&yoffset=-35&xpadding=0&ypadding=0&return=image&antialiasing=1&valign=true&debug=true";
    $(this).replaceWith('<img src="'+src+'" alt="'+$( this ).text()+'" title="'+$( this ).text()+'" class="decorate">'); 
  });



jQuery("span.fl_deco").each(function() {
    var image = document.createElement("img");
    src =" http://www.gaboweb.net/reflect/?text="+ $( this ).text()+"&fg_color=A00806&bg_color=ffffff&font_name=BickhamScriptPro-Regular.otf&font_size=26&yoffset=-10&xpadding=0&ypadding=0&return=image&antialiasing=1";
    $(this).replaceWith('<img src="'+src+'" alt="'+$( this ).text()+'" title="'+$( this ).text()+' align="left"">'); 
  });

   
  $('a').focus(function() {
    this.blur();
  });


  $("div.item").fadeTo("fast",0.6);

  $("div.item").hover(function(){
     $(this).fadeTo("fast", 1.0);
     $(this).attr('style','border: 1px solid gray');

  },function(){
     $(this).fadeTo("fast", 0.6);
     $(this).attr('style','border: 1px solid lightgray');
  });

  $("div.item").click(function() { $("#item-detail").dialog('open');});


  $("#presse a.popup").click(function() {

    //$("#item-detail img").attr("src", "/usr/welldone/img/common/loading.gif");
    var name = $(this).attr("href");
    //$("#item-detail img").attr("src", name);
    //$("#item-detail").createElement("img").attr("src",name);

    /* marche mais pas terrible */
    //$("#placeholder").after( $(document.createElement("img")).attr("src",name) ); 

   var image = document.createElement("img");
   $("#item-detail img").replaceWith('<img src="'+name+'">'); 


    $("#item-detail").dialog('open');
    return false;
     //return false; 
  });

    


  $("#flagEN").fadeTo("fast", 0.6);
  $("#flagFR").fadeTo("fast", 0.6);

  $("#flagFR").hover(function(){
     $("#flagFR").fadeTo("fast", 1.0);
     $("#flagEN").fadeTo("fast", 0.6);
  },function(){
     $("#flagFR").fadeTo("fast", 0.6);
  });

  $("#flagEN").hover(function(){
     $("#flagEN").fadeTo("fast", 1.0);
     $("#flagFR").fadeTo("fast", 0.6);
  },function(){
     $("#flagEN").fadeTo("fast", 0.6);
  });

  $("img.appart_thumbnails_pic").hover(function(id){
//    $(this).fadeTo("fast", 1.0); 
//     $(this).attr('style','border: 1px solid #A10907');
     $("img.appart_main_pic").each(function(){
        $(this).fadeOut("fast"); 
    });
     $("img.appart_thumbnails_pic").each(function(){
        $(this).removeClass("active"); 
     	$(this).fadeTo("fast", 0.4);
    });
     $(this).addClass('active');
     $(this).fadeTo("fast", 1);

    var name = $(this).attr("alt");
   $("#"+name).fadeIn("fast"); 
    },function(){
//     $(this).fadeTo("fast", 0.4);
 //    $(this).attr('style','border: 1px solid #AEAEAE');
    });
  $("#appart_pic").fadeIn("fast");



  $("#skycrapper").css({top:"40px"});
  $(window).scroll(function(){
    var documentHeight = $(document).height();
    var scrollPosition = $(window).height() + $(window).scrollTop(); 
    var divHeight = $("#skycrapper").height(); 
    var final_position = (scrollPosition-(divHeight)-divHeight/2-90) ;
    if(final_position >40){  
      $("#skycrapper").css({top:final_position+"px"});
    }
     else{
      $("#skycrapper").css({top:"40px"});
    }
  }); 

  $("#slideshow_mod").dialog({ bgiframe: true, height: 580, width: 722, modal: true, autoOpen: false}); 
  $("#v360_mod").dialog({ bgiframe: true, height: 580, width: 722, modal: true, autoOpen: false}); 
  $("#dispo_mod").dialog({ bgiframe: true, height: 473, width: 663, modal: true, autoOpen: false}); 
  $("#map_mod").dialog({ bgiframe: true, height: 450, width: 630, modal: true, autoOpen: false,resizable: false}); 
  $("#plan_mod").dialog({ bgiframe: true, height: 573, width: 900, modal: true, autoOpen: false }); 


  $("#item-detail").dialog({ bgiframe: true, height: 580, width: 722, modal: true, autoOpen: false}); 

  
  $("#bt_plan").attr("href", "javascript:void(0)");


  $("#bt_slide").click(function() { $("#slideshow_mod").dialog('open');});

  $("#bt_slide2").click(function() { $("#slideshow_mod").dialog('open'); });
  $("#bt_slide3").click(function() { $("#v360_mod").dialog('open'); });
  $("#bt_slide_360").click(function() { $("#v360_mod").dialog('open'); });
  $("#bt_dispo").click(function() { $("#dispo_mod").dialog('open'); return false});
  $("#bt_map").click(function() { $("#map_mod").dialog('open'); });
  $("#bt_plan").click(function() { 
    $("#plan_mod").dialog('open');
  });



/*  $('#flash_slide_pan').flash(
          { src: '/usr/welldone/flash/focus_banner_rotator_v1.1.swf',
            width: 620,
            height: 413 },
          { version: 8 }
      );
*/

  $('.datepicker').datepicker();
//  $('#desc_scroll').jScrollPane({scrollbarWidth: 8});

  var originalSizes = new Array();

  $('#pane1').jScrollHorizontalPane({scrollbarHeight:16, scrollbarMargin:0,scrollbarHeight:16, showArrows:true, arrowSize:31});



  $("img.appart_thumbnails_pic").fadeTo("slow", 0.4); 

  $("img.active").fadeTo("fast",1);

  $("img.appart_main_pic").each(function(){
    $(this).hide();
  });


  $("img.appart_main_pic:first").show();

  $('#flash_appart_slide').flash(
        { src: '/usr/welldone/flash/monoslideshow.swf',
          width: 700,
          height: 525, 
          flashvars: { showLogo: 'false'}},
        { version: 8 }
    );


    $("a[href^='http://']").click(function(){
      if(($(this).attr("class"))=='internal'){
        return true;
      } 
      window.open(this.href);
      return false;
    }); 

});



/*oldies*/
function resetVal(id, val) { if($(id) && $(id).value == val) $(id).value = ''; }
function validateGetValueOf(o) {
    var value="";
    if(typeof(o)=="object") {
        switch(o.type) {
            case "select":
                var i=o.options.SelectedIndex;
            value=(i!=-1) ? o.options[i].value : "";
            break;
            case "chackbox":
                case "radio":
                case "input":
                case "textarea":
                case "file":
            default:
                return o.value;
        }
    }
    return value;
}

function hasAttribute(attribute) {
    var has=this.getAttribute(attribute);
    return (has==null) ? false : true;
}

function validate(hidealert) {
    var argv = validate.arguments;
    var argc = argv.length; 
    var str = "";
    var min_reqs=max_reqs=null;
    if(!document.getElementsByTagName) {
        alert("Sorry! Your browser does not support the W3C HTML DOM!");
        return false;
    }
    var forms = document.getElementsByTagName('form');
    for(var f=0; f<forms.length;f++) {
        var e=forms[f].elements;
        for(var i = 0; i < e.length; i++) {
            if(!e[i].hasAttribute) e[i].hasAttribute=hasAttribute;
            if(!e[i].hasAttribute('pattern')) continue;
            var pattern = new RegExp(e[i].getAttribute('pattern'));
            var value = validateGetValueOf(e[i]);
            
            if(document.getElementById("error_"+e[i].id)){
              var elem = document.getElementById("error_"+e[i].id);
              var old = (elem.parentNode).removeChild(elem);
            }

            if (pattern != 'null/index.html') {
                var offendingChar = value.match(pattern);
                if(offendingChar == null) {
                    str+= (e[i].hasAttribute('errorMsg')) ?
                        e[i].getAttribute('errorMsg') + "\n" :
                        "Parse error in form ! --"+e[i].name+"\n";
//                alert(forms[f].elements[i].id);
          
              /*     nouveauDiv = document.createElement("div");
                  nouveauDiv.innerHTML = e[i].getAttribute('errorMsg');
                  mon_div = document.getElementById('line_'+e[i].id);
                  document.body.insertBefore(nouveauDiv, mon_div);*/
                
                          
              var sp1 = document.createElement("div");
              sp1.setAttribute("class", "error_label");
              sp1.className = 'error_label';
              sp1.setAttribute("id", "error_"+e[i].id);
              
              sp1.innerHTML = '';
              var sp1_content = document.createTextNode(e[i].getAttribute('errorMsg'));
              sp1.appendChild(sp1_content);
              var sp2 = document.getElementById(e[i].id);
              var parentDiv = sp2.parentNode;
              parentDiv.insertBefore(sp1, sp2.nextSibling);



                    e[i].className='inputError';    
                    continue;
                }
                min_reqs= (e[i].hasAttribute('min')) ? e[i].getAttribute('min') : "";
                max_reqs= (e[i].hasAttribute('max')) ? e[i].getAttribute('max') : "";
                if(typeof(e[min_reqs])=="object")
                    min_reqs=validateGetValueOf(e[min_reqs]);
                if(typeof(e[max_reqs])=="object")
                    min_reqs=validateGetValueOf(e[max_reqs]);
                if(min_reqs!="") min_reqs=parseFloat(min_reqs);
                if(max_reqs!="") max_reqs=parseFloat(max_reqs);
                //str+="["+min_reqs+"]["+value+"]["+max_reqs+"]\n";
                if ((min_reqs!="" && value < min_reqs) || (max_reqs!="" && value > max_reqs)) {
                    str+= (e[i].hasAttribute('MinMaxerrorMsg')) ?
                        e[i].getAttribute('MinMaxerrorMsg') + "\n" :
                        "Parse error in form : "+e[i].name +": "+min_reqs+"<="+value+"<="+max_reqs+"\n";
                    e[i].className='inputError';
                } else{
                    if(e[i].getAttribute('type') != 'checkbox') e[i].className='inputValid';
                }
            }
        }
    }
    if (str != "" && str!=null) {
        if (hidealert == 1) {
            return false;
        } else {
            //alert(str);
//            document.getElementById('error-list').style.display
             
            return false;
        }
    } else {
        if(argc == 3 && argv[0].toLowerCase() == 'checkpass') {
            if(checkPass(argv[1], argv[2]) == false) {
                document.getElementById(argv[1]).className = 'inputError';
                document.getElementById(argv[2]).className = 'inputError';
                //alert((document.getElementById(argv[1]).hasAttribute('errorMsg')) ?  document.getElementById(argv[1]).getAttribute('errorMsg') : "Please enter the same passwords");
                alert("Please enter the same passwords");
                return false;
            }
        }
        return true;
    }
}
function clearForm(oForm) {
   
  var elements = oForm.elements;
   
  oForm.reset();

  for(i=0; i<elements.length; i++) {
     
  field_type = elements[i].type.toLowerCase();
 
  switch(field_type) {
 
    case "text":
    case "password":
    case "textarea":
          case "hidden":  
     
      elements[i].value = "";
      break;
       
    case "radio":
    case "checkbox":
        if (elements[i].checked) {
          elements[i].checked = false;
      }
      break;

    case "select-one":
    case "select-multi":
                elements[i].selectedIndex = -1;
      break;

    default:
      break;
  }
    }
}

