// JavaScript Document
/*
function callback() {
  id=($("#colonneseul").length>0)?"#colonneseul":"#posts_main";
  $(id).html($(id).attr("oldHtml"));
  var target_offset = $("#news_mail").offset();  
  var target_top = target_offset.top;
  $('html, body').animate({scrollTop:target_top}, 500); 
};
*/
$(document).ready(function(){
  try { // IE Flick Fix
    document.execCommand("BackgroundImageCache", false, true)
  } catch(e) { /**/ }
	$(".thumbs a").click(function(){		
		var largePath = $(this).attr("href");
		var largeAlt = $(this).attr("title");		
		$("#largeImg").attr({ src: largePath, alt: largeAlt });			
		return false;
	});
	$("#news_mail").focus(function(){
	   $(this).val('');
	   $(this).unbind("focus");
  });
  $("#news_submit").click(function(){
    var mail = $("#news_mail").attr("value");
    $.ajax({
      method: "get",
      url: "news.php",
      data: "mail="+mail,
      success: function(html){
        $('<div>'+html+'</div>').modal();
      }
    });
    return false;  
  });

  $(".fac").focus(function(){
    $(this).val('');
    $(this).attr("focused",true);
    $(this).next().show();
    $(this).unbind("focus");
  });
  $(".dev").focus(function(){
    $(this).val('');
    $(this).attr("focused",true);
    $(this).next().show();
    $(this).unbind("focus");
  });
  $(".opt").focus(function(){
    $(this).val('');
    $(this).attr("focused",true);
    $(this).next().show();
    $(this).unbind("focus");
  });
  $(".isset").attr("focused",true);
  $(".isset").unbind("focus");
  
  if($("#delivery").is(':checked')) {
    $(".delivery").show("normal");
  }
  $("#delivery").click(function(){
	   if($(this).is(':checked')) {
      $(".delivery").show("normal");
     } else { 
      $(".delivery").hide("normal");
     }
  });
  $("#order").submit(function(){
    var valid=true;

    $(".fac").each(function(){
      if($(this).val().length<1 || !$(this).attr("focused")) { valid=false; }
    });
    var cgv=$("#cgv");
    if(cgv.length>0) {
      if(!$("#cgv").is(':checked')) valid=false;
      if($("#delivery").is(':checked')) {
        $(".dev").each(function(){
          if($(this).val().length<1 || !$(this).attr("focused")) { valid=false; }
        });
      } else if(valid==true) {
        $(".dev").each(function(){
          $(this).val('');
        });
      }
    }

    if(valid==false) $("#dialog").modal({maxHeight:80});
    else {
      $(".opt").each(function(){
        if(!$(this).attr("focused")) $(this).val('');
      });
    }
    return valid;
  });
});
