(function($) {
  var Ss3iToolkit = {};
  
  Ss3iToolkit.SeparateListItems = function() {
    var items = arguments[0] || 'li';
    $(items).each( function(index, el) {
      if (index < $(items).size() - 1) {
        if (el.tagName == 'LI') {
          $(el).append('|');
        }
        if (el.tagName == 'A') {
          $(el).after('|');
        }
      }
    });
  };
  
  Ss3iToolkit.SelfLabeledInput = function() {
    var selector = arguments[0] || 'label';
    $(selector).each( function() {
      $(this).hide();
      var item = $('input[@id="'+$(this).attr('for')+'"]');
      var value = $(this).html();
      if (item.val() == '') {
        item.val(value);
      }
      item.val(value);
      item.blur(function() {
        if ($(this).val() == '') {
          $(this).val(value);
        }
      });
      item.focus(function() {
        if ($(this).val() == value) {
          $(this).val('');
        }
      });
    });
  };
  
  Ss3iToolkit.handleExternalLinks = function() {
    var selector = arguments[0] || 'a[rel="external"],a[rel="document"]';
    $(selector).each( function() {
      el = $(this);
      el.attr({ title: "Acc\u00e9der au site dans une nouvelle fen\u00EAtre" })
      .click( function() { 
        window.open(el.attr('href')); 
        return false; 
      });
    });
  }

  $(document).ready( function() {
		$("#ssfrais").fancybox({
				'titleShow'				: false,
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
		
    $("#homepage #content #navigation #main_links ul li a").pngfix();
    $("#avatar_devis_volume").pngfix();
  	$("#double #wrapper .internal #content #sub #nav #services ul li").pngfix();
  	$("#double #wrapper .internal #content #main #navigation_interne ul li").pngfix();
    //$('#homepage #wrapper').append('<div id="pencil"></div>');
    $('.inside').append('<div id="corner-bottom-right"></div>');
    $('#homepage').prepend('<div id="corner-top-left"></div>');
    //$('#single, #double').append('<div id="corner-bottom-right"></div>');
    $('#single, #double').prepend('<div id="corner-top-left"></div>');
    $('#header').attr('style', 'left:0;');
    $("#homepage #choice").change( function() {
      var dest = $('#choice').val();
      if (dest != "" && dest != "Vous souhaitez") {
        document.location.href = dest;
      }      
    }); 
    Ss3iToolkit.SeparateListItems('#footer li a');
    Ss3iToolkit.SeparateListItems('#breadcrumb li');
    $("a[rel='external'],a[rel='document']")
    .attr({ title: "s'ouvre dans une nouvelle fen\u00EAtre" })
    .click(function() { window.open($(this).attr('href')); return false; });
    $("a[rel='external_link']")
    .click(function() { window.open($(this).attr('href')); return false; });	
  });
})(jQuery);
