// function search
function searchForm(){
	$("input.input").focus(function(){
		if ($(this).val() == $(this).attr("title")){
			$(this).val("");
		}
	}).blur(function(){
		if ($(this).val() == 0){
			$(this).val($(this).attr("title"));
		}
	});
}

// function switchThis
function switchThis(div){
	nSwitcher = $(div + " .post").size();
	var switcher = 0;
	$(div + " .switch_over").hide();
	$(div).hover(function(){
		$(div + " .switch_over").fadeIn("normal");
	}, function(){
		$(div + " .switch_over").fadeOut("normal");
	});
	
	function switcha(i){
		$(div + " .switch_post").fadeOut("normal", function(){
			$(this).find("a.switch_img").attr("href",$(div + " .post:eq(" + i + ") h3 a").attr("href")).find("img").attr("src",$(div + " .post:eq(" + i + ") img").attr("src"));
			$(this).find("h3").html($(div + " .post:eq(" + i + ") h3").html());
			$(this).find("p").text($(div + " .post:eq(" + i + ") p:eq(1)").text());
			$(this).fadeIn();
		});
	}
	
	switcha(0);
	
	$(div + " .avanti").click(function(){
		if(switcher < nSwitcher-1){
			switcha(++switcher);			
		}	else {
			switcher = 0;
			switcha(switcher);
		}
		return false;
	});
	
	$(div + " .indietro").click(function(){
		if(switcher > 0){
			switcha(--switcher);
		} else {
			switcher = nSwitcher-1;
			switcha(switcher);
		}
		return false;
	});
}

// function share
function share(){
	$("a.share").each(function(){
		$(this).parent().parent().prev().find(".sociable").insertAfter($(this).parent().find("a.share"));
	}).click(function(){
		$(this).next().toggle("normal");
		return false;
	});
}

// function tag_cloud
function tag_cloud(){
	var cat = $("#tags a").size();
	$("#tags a").each(function(){
		var index = $("#tags a").index(this);
		var rgb = (255 - (index*2));
		$(this).attr("style","color:rgb(" + rgb + "," + rgb + "," + rgb + ")");
	});
}

// function ieSucks
function ieSucks(){/*
	if ($.browser.msie){
		if ($.browser.version == "6.0"){
		
	}
	*/
}

// function oldMore
function oldMore(){
	$("span[@id^='more']").each(function(){
		$(this).insertAfter($(this).parent()).prev().remove();
	});
}

// function hideHidden
function hideHidden(){
	$("input:hidden").css({visibility:"hidden",height:"0px",width:"0px",padding:"0px"});
}

// dom ready
$(document).ready(function(){
	searchForm();
	switchThis("#highlights");
	switchThis("#events");
	tag_cloud();
	share();
	ieSucks();
	oldMore();
	hideHidden();
});