Array.prototype.shuffle = function arrayShuffle(){
  var tmp, rand;
  for (var i =0; i < this.length; i++){
    rand = Math.floor(Math.random() * this.length);
    tmp = this[i];
    this[i] = this[rand];
    this[rand] =tmp;
  }
};

jQuery(document).ready(function(){
        var idx = parseInt(/rg_header_0(\d+)\.jpg/g.exec($('#header .images img').attr('src'))[1]);
        var headerImages = [];
        for (var i = 1; i <= 14; i++) {
            if (i == idx) {
                continue;
            }
            headerImages.push(i);
        }
        headerImages.shuffle();
        var headerImages2 = headerImages.slice(0); // Clone
        headerImages2.push(idx);

        function headerImage()
        {
            if (headerImages.length == 0) {
                headerImages = headerImages2.slice(0); // Clone
            }
            var $curr = $('#header .images img');
            var $next = $curr.clone();

            $next.hide().bind('load', function() {
                $curr.fadeOut(2000, function() {
                    $(this).remove();
                });
                $(this).fadeIn(2000);
				if (timeout)
				    clearTimeout(timeout);
                timeout = setTimeout(headerImage, 6000);
            })
            .attr('src', $next.attr('src').replace(/rg_header_0(\d+)\.jpg/g, 'rg_header_0' + headerImages.pop() + '.jpg'))
            .appendTo('#header .images');
        };

        var timeout = setTimeout(headerImage, 6000);

	jQuery(":text,textarea").focus(function(){
		jQuery(this).parent().addClass("currentFocus");
		jQuery(".currentFocus .desc").css({"color" : "#ff5a00"});
		jQuery(".currentFocus .message_input, .currentFocus #author, .currentFocus #email, .currentFocus #url").css({"border-color" : "#ff5a00", "color" : "#000"});
	});

	jQuery(":text,textarea").blur(function(){
		jQuery(this).parent().removeClass("currentFocus");
		jQuery(".message_input, .desc, #author, #email, #url").removeAttr("style");
	});
	
	/*jQuery("#sidebar ul li ul li").hover(function(){
		jQuery("#sidebar ul li ul li").css({"cursor" : "pointer"});
	});*/
	
	/*jQuery("#sidebar ul li ul li").click(function(){
		window.location=jQuery(this).find("a").attr("href");
		return false;
	});*/
	
	/*dropdown menu 20090805*/
	jQuery("div#main_navi ul.left li").hover(
		function(){jQuery("ul", this).css("display", "block");},
		function(){jQuery("ul", this).css("display", "none");}
	);
	
});
