SyntaxHighlighter.defaults['light'] = true;

$(function(){
	$("section:eq(1)").css({"margin-right":"0px"});
	$("section:not(:eq(0),:eq(1))").filter(":nth-child(4n)").css({"margin-right":"0px"});
	
	$("#popup-close").click(function(){
		$("#popup").fadeOut(200);
		return false;
	}).hover(function(){
		$(this).fadeTo(100, 0.5);
	},function(){
		$(this).fadeTo(100, 1);
	});
	$("a.info, a.preview, #new a").click(function(){
		var mTop = parseInt($(window).height() - $("#popup").height()) / 2;
		var sTop = $(window).scrollTop();
		if(mTop < 40){ mTop = 40; }
		if(sTop > 0){ mTop = mTop + sTop; }
		$("#popup").css({"margin-top":  mTop+"px"}).fadeIn(400);
		$("#popup-images img").imgCenter().fullsize({iconOffset: 5});
		return false;
	});
});

frSuccess = function(){
	$("#search").focus(function(){
		$(this).val("Coming Soon");
		$(this).blur();
	});
	if($("#file-download").length > 0){
		var dl_id = $("#file-download").attr("rel");
		var dl_count_cntrl = $.controller.array("data/downloads",{id: dl_id},{success: function(data){
			$("#file-version").html(data.items[0].version);
			$("#file-count").html(data.items[0].downloads+" Downloads");
			$("#file-download dd a").click(function(){
				var new_count = parseInt(data.items[0].downloads) + 1;
				dl_count_cntrl.update({data_set_id: data.items[0].data_set_id, downloads: new_count, id: data.items[0].id}, {retrieveComplete: function(data){
					$("#file-count").html(data.items[0].downloads+" Downloads");
				}});
				window.open("http://drewwilson.com/upload/data/"+data.items[0].data_set_id+"/"+data.items[0].file);
				return false;	
			});
		}});		
	}
	if($("img.center").length > 0){
		$("img.center").imgCenter();
	}
	if(!/\/entry\//.test($.url.attr("source")) && !/\/archives\//.test($.url.attr("source"))){
		var cur_data = $(".entry-holder").data("data");
		var prevNext = $.controller.array("blog/blog_entries",{id: cur_data.id});
		$("#prev_next").format(function(elem, data){
			$(elem).find(".fr_prev_item").text(data.prev_title).attr("href","http://code.drewwilson.com/entry/"+data.prev_sef_title);
		});
		$("#prev_next").template(prevNext);
	}
	if($("#example_input").length > 0){
		var a_data = {items: [
			{value: "Mick Jagger"},
			{value: "Johnny Storm"},
			{value: "Richard Hatch"},
			{value: "Kelly Slater"},
			{value: "Michael Jordan"},
			{value: "Ronald Burgandy"},
			{value: "Jimmy"},
			{value: "Ratchet Robot"},
			{value: "Mike Steed"},
		]};
		$("#example_input").autoSuggest(a_data.items);
	}
	if($("div.fr_text a.tiptip").length > 0){
		$("div.fr_text a.tiptip").tipTip();
	}
	SyntaxHighlighter.all();
}