//On load page, init the timer which check if the there are anchor changes each 300 ms
$(document).ready(function(){
	setInterval("checkAnchor()", 300);
});

var currentAnchor = null;
//Function which chek if there are anchor changes, if there are, sends the ajax petition

function checkAnchor(){
	//Check if it has changes
	if(currentAnchor != document.location.hash){
		currentAnchor = document.location.hash;
		//if there is not anchor, the loads the default section
		if(!currentAnchor)
			var _curr_anchor = 'pia';
		else
		{
			//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2
			var splits = currentAnchor.substring(1).split('#');
			//Get the section
			var _curr_anchor = splits[0];
			delete splits[0];
		}
		
		// then dim the inactive ones
		$('#images').children().each(function(){
			var tmp = $(this).attr('id').split('_btn');
			if(tmp[0] != _curr_anchor)
			{
				//$("#"+tmp[0]+"_thumb").fadeTo("slow", 0.3);
				$("#"+tmp[0]+"_thumb").attr({
					src: "/home/images/"+tmp[0]+"_sm.png"
				});
			}
			
			if(tmp[0] == _curr_anchor)
			{
				//$("#"+tmp[0]+"_thumb").fadeTo("slow", 1);
				$("#"+tmp[0]+"_thumb").attr({
					src: "/home/images/"+tmp[0]+".png"
				});
			}
		});

                // to clear the queued animations
                //$(element).queue( [ ] ).stop();
                $(".flash_search").clearQueue();
		// make the corresponding button click automatically
		$("#"+_curr_anchor+"_btn").click();
	
		window._curr_anchor = _curr_anchor;
	}
}

$(function() {
	// this handles the hovering effect
	$(".latest_img").hover(function(){
		var tmp = $(this).attr('id').split('_thumb');
		
//		var img = $("#"+tmp[0]+"_thumb").attr("src");
//		alert(img);
		
		if(tmp[0] != window._curr_anchor)
		{
			//$("#"+tmp[0]+"_thumb").fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
			$("#"+tmp[0]+"_thumb").attr({
				src: "/home/images/"+tmp[0]+".png"
			});
		}
	},function(){
		var tmp = $(this).attr('id').split('_thumb');
		if(tmp[0] != window._curr_anchor)
		{
			//$("#"+tmp[0]+"_thumb").fadeTo("slow", 0.3); // This should set the opacity back to 30% on mouseout
			$("#"+tmp[0]+"_thumb").attr({
				src: "/home/images/"+tmp[0]+"_sm.png"
			});
		}
	});
});

