
$(document).ready(function(){
	$("#main_carousel_nav a:eq(1)").replaceWith("This Week");
	$("#password_holder").focus(function(){
		$("#password_holder").css("display","none");
		$("#password").css("display","").focus();
	    });
	$("#authuser").focus(function(){
		$(this).val("").css("color","#000");
	    }).blur(function(){
		    if (!$(this).val().length)
			$(this).val("Username").css("color","#777");
		}).css("color","#777");
});

ss.getPhotos = function(opt,page){
    if (typeof(ss.getPhotos.sort) == "undefined") ss.getPhotos.sort = '';
    if (typeof(ss.getPhotos.time) == "undefined") ss.getPhotos.time = '';
    if (typeof(opt.time) != "undefined") ss.getPhotos.time = opt.time;
    if (typeof(opt.sort) != "undefined"){
	$("#main_tabs a").removeClass("active");
	if (opt.sort != "")
	    $("#main_tabs a[href$='"+opt.sort+"']").addClass("active");
	else
	    $("#main_tabs a:last").addClass("active");
	ss.getPhotos.sort = opt.sort;
    }
    var num = 4;
    
    $("#main_carousel_images").html("<table class='c'><tr><td><img src='"+G.IMAGES+"/blue-long.gif' alt='Loading...' /></td></tr></table>");

    ss.ajax({
	    url: G.AJAX,
		data: 'cmd=get_photos',
		ref: { 'filters' : [ss.getPhotos.sort,ss.getPhotos.time], 'page' : page, 'num' : num, 'maxwidth' : 160, 'maxheight' : 118, 'class' : 'main_carousel_image_wrap' },
		success: ss.getPhotosCallback
		});
};

ss.getPhotosCallback = function(incoming){
    if (incoming.success){
	var fill = "";
	for (var i in incoming.photos){
	    var p = incoming.photos[i];
	    fill += "<div class='main_carousel_image'>"+p.html_thumb+"<div class='p2'><a href='"+p.url_photo+"'>"+ss.limit(p.title,19)+"</a></div><div>"+p.views+" view"+(p.views!=1?'s':'')+"</div><div class='p2'><a class='b' href='"+p.url_user+"'>"+p.username+"</a></div></div>";
	}
	$("#main_carousel_images").html(fill);

	var fill2 = "";
	fill2 += "<a class='main_carousel_view_all' href=\"javascript:document.location='/gallery"+(ss.getPhotos.sort?"/"+ss.getPhotos.sort+(ss.getPhotos.time?"-"+ss.getPhotos.time:""):"")+"'\">View All »</a>";
	if (ss.getPhotos.sort != "" && ss.getPhotos.sort != "editorspicks"){
	    fill2 += (ss.getPhotos.time == 'week' ? "This Week" : 
		      "<a href=\"javascript:ss.getPhotos({time:'week'},1)\">This Week</a>") + "&nbsp;|&nbsp;";
	    fill2 += (ss.getPhotos.time == 'month' ? "This Month" :
		      "<a href=\"javascript:ss.getPhotos({time:'month'},1)\">This Month</a>") + "&nbsp;|&nbsp;";
	    fill2 += (ss.getPhotos.time == '' ? "All Time" :
		      "<a href=\"javascript:ss.getPhotos({time:''},1)\">All Time</a>");
	}

	$("#main_carousel_nav").html(fill2);
    }
}