$(document).ready( function() {

	$("#pLast, #taPagerPrev").mouseover( function() {
		$("#pLast").attr("src", "/images/layout/galleryb_arrow_left_live.gif");
		$("#taPagerPrev").addClass("taPagerPrevHover");
	});
	$("#pLast, #taPagerPrev").mouseout( function() {
		$("#pLast").attr("src", "/images/layout/galleryb_arrow_left.gif");
		$("#taPagerPrev").removeClass("taPagerPrevHover");
	});

	$("#pNext, .imageStage, #taNextImg").mouseover( function() {
		$("#pNext").attr("src", "/images/layout/galleryb_arrow_right_live.gif");
		$("#taNextImg").css("display", "block");
	});
	$("#pNext, .imageStage, #taNextImg").mouseout( function() {
		$("#pNext").attr("src", "/images/layout/galleryb_arrow_right.gif");
		$("#taNextImg").css("display", "none");
	});
	$("#taNextImg").click(function(){
		window.location.href=$("#pNext").parent().attr("href");
	});
	
	$("#taPagerPrev").click( function() {
		window.location.href=$("#pLast").parent().attr("href");
	});

	$("#detailsinfo").fadeIn("normal");

	$("ul.nav li").click( function() {
		showDetailsItem($(this).find("a").attr("rel"));
	});
	$("#detailsinfo a").click( function() {
		showDetailsItem($(this).attr("rel"));
	});
	$("#mediasection_comments_toplinks a").click( function() {
		showDetailsItem("comments");
		$("#mediasection_comments_toplinks a").hide("fast");
	});	

	$("#rateForm").submit( function() {
		$.post($(this).attr("action"), {
		    rating :$("input.ratingBox:checked").attr("value"),
		    type :"1"
		}, function(data) {
			$("#callbackRating").html(data);
		});
		return false;
	});
	$("#stfForm").submit( function() {
		$.post($(this).attr("action"), {
		    from :$("input#fromMail").attr("value"),
		    to :$("input#sendtoMail").attr("value"),
		    url :$("input#url").attr("value"),
		    type :"2"
		}, function(data) {
			$("#callbackSahre").html(data);
		});
		return false;
	});
	
	comment_highlight = false;
	
	setTimeout("fixheight()",2000);
	
});

function fixheight(){
	var newvaluehere=$("#pLast").offset();
	if(newvaluehere){
		$("#taPagerPrev").css("height", newvaluehere.top-199+"px");
	}
}

function showDetailsItem(item) {
	
	if ($("ul.nav li." + item).hasClass("active")) {
		return false;
	} else {
		$("ul.nav li").removeClass("active");
		$("#detailsinfo,#detailsrate,#detailscomments,#detailsshare").hide();
		$("#details" + item).show();
		$("ul.nav ." + item).addClass("active");
		//$("#container").slideDown("fast");
	}
}