Index: /trunk/themes/default/js/switchbox.js
===================================================================
--- /trunk/themes/default/js/switchbox.js	(revision 23320)
+++ /trunk/themes/default/js/switchbox.js	(revision 23320)
@@ -0,0 +1,11 @@
+function switchBox(link, box) {
+  jQuery(link).click(function() {
+    var elt = jQuery(box);
+    elt.css("left", Math.min( jQuery(this).offset().left, jQuery(window).width() - elt.outerWidth(true) - 5))
+      .css("top", jQuery(this).offset().top + jQuery(this).outerHeight(true))
+      .toggle();
+  });
+  jQuery(box).on("mouseleave click", function() {
+    jQuery(this).hide();
+  });
+}
Index: /trunk/themes/default/template/index.tpl
===================================================================
--- /trunk/themes/default/template/index.tpl	(revision 23319)
+++ /trunk/themes/default/template/index.tpl	(revision 23320)
@@ -1,3 +1,5 @@
+{combine_script id='core.switchbox' load='footer' require='jquery' path='themes/default/js/switchbox.js'}
 {$MENUBAR}
+
 
 {if isset($errors) or isset($infos)}
@@ -25,15 +27,5 @@
 			{/foreach}
 		</div>
-		{footer_script require='jquery'}{literal}
-jQuery("#sortOrderLink").click(function() {
-	var elt = jQuery("#sortOrderBox");
-	elt.css("left", Math.min( jQuery(this).offset().left, jQuery(window).width() - elt.outerWidth(true) - 5))
-		.css("top", jQuery(this).offset().top + jQuery(this).outerHeight(true))
-		.toggle();
-});
-jQuery("#sortOrderBox").on("mouseleave", function() {
-	jQuery(this).hide();
-});
-		{/literal}{/footer_script}
+		{footer_script require='core.switchbox'}switchBox("#sortOrderLink", "#sortOrderBox");{/footer_script}
 		{/strip}</li>
 {/if}
@@ -52,15 +44,5 @@
 			{/foreach}
 		</div>
-		{footer_script require='jquery'}{literal}
-jQuery("#derivativeSwitchLink").click(function() {
-	var elt = jQuery("#derivativeSwitchBox");
-	elt.css("left", Math.min( jQuery(this).offset().left, jQuery(window).width() - elt.outerWidth(true) - 5))
-		.css("top", jQuery(this).offset().top + jQuery(this).outerHeight(true))
-		.toggle();
-});
-jQuery("#derivativeSwitchBox").on("mouseleave", function() {
-	jQuery(this).hide();
-});
-		{/literal}{/footer_script}
+		{footer_script require='core.switchbox'}switchBox("#derivativeSwitchLink", "#derivativeSwitchBox");{/footer_script}
 		{/strip}</li>
 {/if}
Index: /trunk/themes/default/template/picture.tpl
===================================================================
--- /trunk/themes/default/template/picture.tpl	(revision 23319)
+++ /trunk/themes/default/template/picture.tpl	(revision 23320)
@@ -1,10 +1,10 @@
-{* Example of resizeable
-{include file='include/autosize.inc.tpl'}
-*}
+{combine_script id='core.switchbox' load='footer' require='jquery' path='themes/default/js/switchbox.js'}
 {if isset($MENUBAR)}{$MENUBAR}{/if}
 <div id="content"{if isset($MENUBAR)} class="contentWithMenu"{/if}>
+
 {if isset($errors) or not empty($infos)}
 {include file='infos_errors.tpl'}
 {/if}
+
 {if !empty($PLUGIN_PICTURE_BEFORE)}{$PLUGIN_PICTURE_BEFORE}{/if}
 
@@ -18,7 +18,8 @@
 <div class="imageNumber">{$PHOTO}</div>
 {include file='picture_nav_buttons.tpl'|@get_extent:'picture_nav_buttons'}
+
 <div class="actionButtons">
 {if isset($current.unique_derivatives) && count($current.unique_derivatives)>1}
-{footer_script require='jquery'}{literal}
+{footer_script require='jquery,core.switchbox'}{literal}
 function changeImgSrc(url,typeSave,typeMap)
 {
@@ -34,13 +35,5 @@
 	document.cookie = 'picture_deriv='+typeSave+';path={/literal}{$COOKIE_PATH}{literal}';
 }
-jQuery("#derivativeSwitchLink").click(function() {
-	var elt = jQuery("#derivativeSwitchBox");
-	elt.css("left", Math.min( jQuery(this).offset().left, jQuery(window).width() - elt.outerWidth(true) - 5))
-		.css("top", jQuery(this).offset().top + jQuery(this).outerHeight(true))
-		.toggle();
-});
-jQuery("#derivativeSwitchBox").on("mouseleave click", function() {
-	jQuery(this).hide();
-});
+switchBox("#derivativeSwitchLink", "#derivativeSwitchBox");
 {/literal}{/footer_script}
 {strip}<a id="derivativeSwitchLink" title="{'Photo sizes'|@translate}" class="pwg-state-default pwg-button" rel="nofollow">
