jQuery.noConflict();

(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);

jQuery(document).ready(function($){

	$("#show_login").click(function(){
		$("#quick_login_overlay").fadeIn(100);
		$("#quick_login").fadeIn();
		$("#username").focus();
		return false;
	});
			
	$("#close_login").click(function(){
		$("#quick_login_overlay").fadeOut(100);
		$("#quick_login").fadeOut();
		return false;
	});
	
	$('#primary_nav li:not(.active) a')
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px -30px)"}, {duration:200});
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:200});
		});
	
	var backgroundpos = 0;
	var offset = 1;
	function scrollbackground() {
		offset = (offset < 1) ? offset + (backgroundpos - 1) : offset - 1;
   		$('#branding').css("background-position",  + offset + "px 0");
   		setTimeout(function() {
			scrollbackground();
			}, 100
		);
   	}
 	scrollbackground();
	
	$(".forum_name").hover(function() {
		$(this).next(".forum_desc_pos").children(".forum_desc_con").stop()
		.animate({left: "0", opacity:1}, "fast")
		.css("display","block")

	}, function() {
		$(this).next(".forum_desc_pos").children(".forum_desc_con").stop()
		.animate({left: "10", opacity: 0}, "fast", function(){
			$(this).hide();
		})
	});
	
	$(".rounded-avatar img").each(function() {
		$(this).wrap(function(){
			return '<span class="rounded-img" style="background:url(' + $(this).attr('src') + ') no-repeat center center;" />';
		});
		$(this).css("opacity","0");
	});
	
	$('#ctv_stbasic').click(function(){
		$(this).addClass("active");
		$('#ctv_stdetailed').removeClass("active");
		$("#customize_topic").addClass("ctv_basic");
		$.cookie('ctv','basic',{ expires: 365, path: '/'});
	});
	
	$('#ctv_stdetailed').click(function(){
		$(this).addClass("active");
		$('#ctv_stbasic').removeClass("active");
		$("#customize_topic").removeClass("ctv_basic");
		$.cookie('ctv',null,{ expires: -1, path: '/'});
	});
	
	if ( ($.cookie('ctv') != null))	{
		$("#customize_topic").addClass("ctv_basic");
		$("#ctv_stbasic").addClass("active");
	}
	else{
		$("#ctv_stdetailed").addClass("active");
	}

});
