function str_repeat(i, m) 
{
    for (var o = []; m > 0; o[--m] = i);
    return (o.join(''));
}

function sprintf() 
{
    var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
    while (f) 
	{
        if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
        else if (m = /^\x25{2}/.exec(f)) o.push('%');
        else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) 
		{
            if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw ("Too few arguments.");
            if (/[^s]/.test(m[7]) && (typeof (a) != 'number'))
                throw ("Expecting number but found " + typeof (a));
            switch (m[7]) {
                case 'b': a = a.toString(2); break;
                case 'c': a = String.fromCharCode(a); break;
                case 'd': a = parseInt(a); break;
                case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
                case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
                case 'o': a = a.toString(8); break;
                case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
                case 'u': a = Math.abs(a); break;
                case 'x': a = a.toString(16); break;
                case 'X': a = a.toString(16).toUpperCase(); break;
            }
            a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
            c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
            x = m[5] - String(a).length;
            p = m[5] ? str_repeat(c, x) : '';
            o.push(m[4] ? a + p : p + a);
        }
        else throw ("Huh ?!");
        f = f.substring(m[0].length);
    }
    
    return o.join('');
}

var ThumbTimerId = 0;
var ThumbActive = null;
var ThumbPosition = 1;
var ThumbOrigSrc = null;
var ThumbMaxPos = 0;
var ThumbPath = null;

$(document).ready(function()
{
	$("a img", $(document)).each(function() 
	{
		if($(this).attr("max") != null)
		{
			$(this).mouseover(function()
			{
				if(ThumbTimerId == 0)
				{
					ThumbActive = $(this);
					ThumbOrigSrc = $(this).attr("src");
					ThumbMaxPos = parseInt($(this).attr("max"));
					ThumbPath = ThumbOrigSrc.substring(0, ThumbOrigSrc.lastIndexOf("/") + 1);
					ThumbNewSrc(); 		
				}
			}); 
			
			$(this).mouseout(function()
			{
				clearInterval(ThumbTimerId);
				ThumbTimerId = 0;
				ThumbActive = null;
				ThumbOrigSrc = null;
				ThumbMaxPos = 0;
				ThumbPosition = 1;
					
				if(ThumbOrigSrc != null)
				{
					$(this).attr("src", ThumbOrigSrc);
				}
			});
		}
	});
});

function ThumbNewSrc()
{
	if(ThumbActive == null)
		return;

    $(ThumbActive).attr("src", ThumbPath + sprintf("%010d", ThumbPosition++) + ".jpg");

    if(ThumbPosition >= ThumbMaxPos)
    	ThumbPosition = 1;
   	
   	if(ThumbTimerId == 0)
   	{
   		ThumbTimerId = setInterval('ThumbNewSrc()', 1000); 
   	}
}

function GetFlashVer()
{
    try
    {
        var ua = navigator.userAgent.toLowerCase(); 
        var isIE = (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1); 
    
        var version = 0; 
        var version2 = 0;
        var lastVersion = 10; 
        var i;
        
        if (isIE) 
        { 
            // browser == IE 
            try 
            { 
                  for (i = 3; i <= lastVersion; i++) 
                  { 
                        if (eval('new ActiveXObject("ShockwaveFlash.ShockwaveFlash.' + i + '")')) 
                        { 
                            version = i; 
                        } 
                  } 
            } 
            catch(e) 
            {
                
            } 
        } 
        else 
        { 
            // browser != IE 
            for (i = 0; i < navigator.plugins.length; i++) 
            {     
                  if (navigator.plugins[i].name.indexOf('Flash') > -1) 
                  {                  
                      version = (parseInt(navigator.plugins[i].description.charAt(16)) > version) ? parseInt(navigator.plugins[i].description.charAt(16)) : version;   
                      version2 = (parseInt(navigator.plugins[i].description.charAt(17)) > version2) ? parseInt(navigator.plugins[i].description.charAt(17)) : version2;
                  } 
            } 
            
            if (version > 0 && version2 > -1)
            {
                version = parseInt(version.toString() + version2.toString());  
            }  
        }
        
        return version;
    }
    catch (e)
    {
        return 0;
    }
}

function HTML5Supported()
{
    try
    {
        var ret = !!document.createElement('video').canPlayType;
        
        if (ret)
        {
            var v = document.createElement('video');
            return true;
        }
        
        return false;
    }
    catch (e)
    {
        return false;
    }
}

function H264CodecSupported()
{
    try
    {
        if (HTML5Supported())
        {
            var v = document.createElement('video');
            var ret = v.canPlayType('video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"');
            return (ret != '');
        }
    }
    catch(e)
    {
        return false;
    }
}
