/*
sortIntegers()
---
Uses the "bubble sort" algorithm to sort an array of
integers. PHP's sorting functions are fine, so this
function is merely to demonstrate how it could be done.
*/
function sortIntegers($x)
{
$count = count($x)-1;
for ($i=0; $i<$count; $i++)
{
if ($x[$i]<$x[$i+1]) continue;
list($x[$i],$x[$i+1]) = array($x[$i+1],$x[$i]);
$x = sortIntegers($x);
}
return $x;
}
// Example
$integers = array(6,3,2,8,9,4,0,1,7,5);
$sorted = sortIntegers($integers);
echo '<pre>', implode(',',$sorted), '</pre>';
function rgb2hex($r, $g, $b, $uppercase=false, $shorten=false)
{
// The output
$out = "";
// If shorten should be attempted, determine if it is even possible
if ($shorten && ($r + $g + $b) % 17 !== 0) $shorten = false;
// Red, green and blue as color
foreach (array($r, $g, $b) as $c)
{
// The HEX equivalent
$hex = base_convert($c, 10, 16);
// If it should be shortened, and if it is possible, then
// only grab the first HEX character
if ($shorten) $out .= $hex[0];
// Otherwise add the full HEX value (if the decimal color
// is below 16 then we have to prepend a 0 to it)
else $out .= ($c < 16) ? ("0".$hex) : $hex;
}
// Package and away we go!
return $uppercase ? strtoupper($out) : $out;
}
echo "#", rgb2hex(250, 123, 0, true), // Gives: #FA7B00
"<br>#", rgb2hex(170, 0, 255), // Gives: #aa00ff
"<br>#", rgb2hex(170, 0, 255, false, true); // Gives: #a0f
$(function(){
var menu = $("#nav");
menu.find("ul.sf-menu")
.superfish({
delay: 0,
speed: 'fast',
autoArrows: false,
dropShadows: false,
onHide: function(){
if (this.parent().is('.sfPersist')) {
this.show().css('visibility','visible').parent().addClass('sfHover');
}
}
})
.find('li > ul > li').click(function(){
// hide previously persistent children (LOL that just sounds wrong)
menu.find('.sfPersist')
.removeClass('sfPersist sfHover')
.find('> ul').hide().css('visibility','hidden');
// add children that should be persistent
if ($(this).is('.sfSelected')) {
// if previously selected, keep hidden
menu.find('li.sfSelected').removeClass('sfSelected');
} else {
// Hide other selected classes
menu.find('li.sfSelected').removeClass('sfSelected');
// if newly selected, then show
$(this)
.addClass('sfSelected') // remember which one is selected
.parent()
.show().css('visibility','visible')
.parent().addClass('sfHover sfPersist');
}
});
});